DSPatch  v.2.42
C++ Cross-Platform, Object-Oriented, Flow-Based Programming Library
 All Classes Pages
DspSignalBus.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 DSPSIGNALBUS_H
26 #define DSPSIGNALBUS_H
27 
28 //-------------------------------------------------------------------------------------------------
29 
30 #include "DspSignal.h"
31 
32 //=================================================================================================
34 
44 class DLLEXPORT DspSignalBus
45 {
46 public:
47  virtual ~DspSignalBus();
48 
49  bool AddSignal( std::string signalName = "" );
50 
51  bool SetSignal( unsigned short signalIndex, const DspSignal* newSignal );
52  bool SetSignal( std::string signalName, const DspSignal* newSignal );
53 
54  DspSignal* GetSignal( unsigned short signalIndex );
55  DspSignal* GetSignal( std::string signalName );
56 
57  bool FindSignal( std::string signalName, unsigned short& returnIndex ) const;
58  bool FindSignal( unsigned short signalIndex, unsigned short& returnIndex ) const;
59 
60  unsigned short GetSignalCount() const;
61 
62  void RemoveAllSignals();
63 
64  template< class ValueType >
65  bool SetValue( unsigned short signalIndex, const ValueType& newValue );
66 
67  template< class ValueType >
68  bool SetValue( std::string signalName, const ValueType& newValue );
69 
70  template< class ValueType >
71  bool GetValue( unsigned short signalIndex, ValueType& returnValue ) const;
72 
73  template< class ValueType >
74  bool GetValue( std::string signalName, ValueType& returnValue ) const;
75 
76  void ClearValue( unsigned short signalIndex );
77  void ClearValue( std::string signalName );
78 
79  void ClearAllValues();
80 
81 private:
82  std::vector< DspSignal > _signals;
83 };
84 
85 //=================================================================================================
86 
87 template< class ValueType >
88 bool DspSignalBus::SetValue( unsigned short signalIndex, const ValueType& newValue )
89 {
90  if( signalIndex < _signals.size() )
91  {
92  return _signals[signalIndex].SetValue( newValue );
93  }
94  else
95  {
96  return false;
97  }
98 }
99 
100 //-------------------------------------------------------------------------------------------------
101 
102 template< class ValueType >
103 bool DspSignalBus::SetValue( std::string signalName, const ValueType& newValue )
104 {
105  unsigned short signalIndex;
106 
107  if( FindSignal( signalName, signalIndex ) )
108  {
109  return _signals[signalIndex].SetValue( newValue );
110  }
111  else
112  {
113  return false;
114  }
115 }
116 
117 //-------------------------------------------------------------------------------------------------
118 
119 template< class ValueType >
120 bool DspSignalBus::GetValue( unsigned short signalIndex, ValueType& returnValue ) const
121 {
122  if( signalIndex < _signals.size() )
123  {
124  return _signals[signalIndex].GetValue( returnValue );
125  }
126  else
127  {
128  return false;
129  }
130 }
131 
132 //-------------------------------------------------------------------------------------------------
133 
134 template< class ValueType >
135 bool DspSignalBus::GetValue( std::string signalName, ValueType& returnValue ) const
136 {
137  unsigned short signalIndex;
138 
139  if( FindSignal( signalName, signalIndex ) )
140  {
141  return _signals[signalIndex].GetValue( returnValue );
142  }
143  else
144  {
145  return false;
146  }
147 }
148 
149 //=================================================================================================
150 
151 #endif // DSPSIGNALBUS_H