DSPatch  v.2.42
C++ Cross-Platform, Object-Oriented, Flow-Based Programming Library
 All Classes Pages
DspSignal.h
1 /************************************************************************
2 DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3 Copyright (c) 2012-2013 Marcus Tomlinson
4 
5 This file is part of DSPatch.
6 
7 GNU Lesser General Public License Usage
8 This file may be used under the terms of the GNU Lesser General Public
9 License version 3.0 as published by the Free Software Foundation and
10 appearing in the file LGPLv3.txt included in the packaging of this
11 file. Please review the following information to ensure the GNU Lesser
12 General Public License version 3.0 requirements will be met:
13 http://www.gnu.org/copyleft/lgpl.html.
14 
15 Other Usage
16 Alternatively, this file may be used in accordance with the terms and
17 conditions contained in a signed written agreement between you and
18 Marcus Tomlinson.
19 
20 DSPatch is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 ************************************************************************/
24 
25 #ifndef DSPSIGNAL_H
26 #define DSPSIGNAL_H
27 
28 //-------------------------------------------------------------------------------------------------
29 
30 #include <string>
31 #include <vector>
32 
33 #include "DspRunType.h"
34 #include "DspThread.h"
35 
36 //=================================================================================================
38 
49 class DLLEXPORT DspSignal
50 {
51 public:
52  DspSignal( std::string signalName = "" );
53 
54  virtual ~DspSignal();
55 
56  template< class ValueType >
57  bool SetValue( const ValueType& newValue );
58 
59  template< class ValueType >
60  bool GetValue( ValueType& returnValue ) const;
61 
62  bool SetSignal( const DspSignal* newSignal );
63 
64  void ClearValue();
65 
66  const std::type_info& GetSignalType() const;
67 
68  std::string GetSignalName() const;
69 
70 private:
71  DspRunType _signalValue;
72  std::string _signalName;
73  bool _valueAvailable;
74 };
75 
76 //=================================================================================================
77 
78 template< class ValueType >
79 bool DspSignal::SetValue( const ValueType& newValue )
80 {
81  _signalValue = newValue;
82  _valueAvailable = true;
83  return true;
84 }
85 
86 //-------------------------------------------------------------------------------------------------
87 
88 template< class ValueType >
89 bool DspSignal::GetValue( ValueType& returnValue ) const
90 {
91  if( _valueAvailable )
92  {
93  const ValueType* returnValuePtr = DspRunType::RunTypeCast< ValueType >( &_signalValue );
94  if( returnValuePtr != NULL )
95  {
96  returnValue = *returnValuePtr;
97  return true;
98  }
99  else
100  {
101  return false; // incorrect type matching
102  }
103  }
104  else
105  {
106  return false; // no value available
107  }
108 }
109 
110 //=================================================================================================
111 
112 #endif // DSPSIGNAL_H