1
/************************************************************************
2
DSPatch - Cross-Platform, Object-Oriented, Flow-Based Programming Library
3
Copyright (c) 2012-2015 Marcus Tomlinson
5
This file is part of DSPatch.
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.
16
Alternatively, this file may be used in accordance with the terms and
17
conditions contained in a signed written agreement between you and
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
************************************************************************/
28
//-------------------------------------------------------------------------------------------------
33
#include <dspatch/DspRunType.h>
34
#include <dspatch/DspThread.h>
36
//=================================================================================================
37
/// Value container used to carry data between components
40
DspComponents process and transfer data between each other in the form of "signals" via
41
interconnecting wires. The DspSignal class holds a single value that can be dynamically typed at
42
runtime. Furthermore, a DspSignal has the ability to change it's data type at any point during
43
program execution. This is designed such that a signal bus can hold any number of different typed
44
variables, as well as to allow for a variable to dynamically change it's type when needed -this can
45
be useful for inputs that accept a number of different data types (E.g. Varying sample size in an
46
audio buffer: array of byte / int / float).
49
class DLLEXPORT DspSignal
52
DspSignal(std::string signalName = "");
56
template <class ValueType>
57
bool SetValue(ValueType const& newValue);
59
template <class ValueType>
60
bool GetValue(ValueType& returnValue) const;
62
template <class ValueType>
63
ValueType const* GetValue() const;
65
bool SetSignal(DspSignal const* newSignal);
69
std::type_info const& GetSignalType() const;
71
std::string GetSignalName() const;
74
DspRunType _signalValue;
75
std::string _signalName;
79
//=================================================================================================
81
template <class ValueType>
82
bool DspSignal::SetValue(ValueType const& newValue)
84
_signalValue = newValue;
85
_valueAvailable = true;
89
//-------------------------------------------------------------------------------------------------
91
template <class ValueType>
92
bool DspSignal::GetValue(ValueType& returnValue) const
96
ValueType const* returnValuePtr = DspRunType::RunTypeCast<ValueType>(&_signalValue);
97
if (returnValuePtr != NULL)
99
returnValue = *returnValuePtr;
104
return false; // incorrect type matching
109
return false; // no value available
113
//-------------------------------------------------------------------------------------------------
115
template <class ValueType>
116
ValueType const* DspSignal::GetValue() const
120
return DspRunType::RunTypeCast<ValueType>(&_signalValue);
124
return NULL; // no value available
128
//=================================================================================================
130
#endif // DSPSIGNAL_H