/usr/include/CLAM/InControl.hxx is in libclam-dev 1.4.0-5build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | /*
* Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
* UNIVERSITAT POMPEU FABRA
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _InControl_
#define _InControl_
#include <string>
#include <list>
#include <typeinfo>
#include <sstream>
#include "TypeInfo.hxx"
#include "InControlBase.hxx"
#include "OutControlBase.hxx"
namespace CLAM {
class Processing;
class OutControlBase;
template<class ControlDataType>
class OutControl;
/**
* An InControl receives values of the template type in an asyncronous pace.
* A processing method can be set as callback to respond to incoming events.
* You can also consult GetLastValue to get the last received value.
*/
template<class ControlDataType>
class InControl : public InControlBase
{
class Callback;
private:
Callback * _callback;
protected:
ControlDataType mLastValue;
public:
/// Constructor to use when no callback is used
InControl(const std::string &name = "unnamed in control", Processing * proc = 0)
: InControlBase(name,proc)
, _callback(new NullCallback)
{
}
/// Constructor to use a callback by const reference
template <typename ProcessingType, typename ParameterType>
InControl(const std::string &name, ProcessingType * proc, void (ProcessingType::*callback)(const ParameterType&))
: InControlBase(name,proc)
, _callback(new MethodCallback<ProcessingType,ParameterType>(proc, callback))
{
}
/// Constructor to use a callback by const reference plus a port id to distinguish different caller controls in a single serving callback
template <typename ProcessingType, typename ParameterType>
InControl(unsigned id, const std::string &name, ProcessingType * proc, void (ProcessingType::*callback)(unsigned, const ParameterType&))
: InControlBase(name,proc)
, _callback(new MethodCallbackWithId<ProcessingType,ParameterType>(proc, callback, id))
{
}
/// Constructor to use a callback by copy
template <typename ProcessingType, typename ParameterType>
InControl(const std::string &name, ProcessingType * proc, void (ProcessingType::*callback)(ParameterType))
: InControlBase(name,proc)
, _callback(new MethodCallbackByCopy<ProcessingType,ParameterType>(proc, callback))
{
}
/// Constructor to use a callback by copy plus a port id to distinguish different caller controls in a single serving callback
template <typename ProcessingType, typename ParameterType>
InControl(unsigned id, const std::string &name, ProcessingType * proc, void (ProcessingType::*callback)(unsigned, ParameterType))
: InControlBase(name,proc)
, _callback(new MethodCallbackByCopyWithId<ProcessingType,ParameterType>(proc, callback, id))
{
}
virtual ~InControl()
{
delete _callback;
}
/// The control receives a value when this method gets called.
/// Associated callback if any, gets triggered on result.
/// Connected OutControl may trigger it but it also may be
/// called directly, for example to set the initial value.
virtual void DoControl(const ControlDataType& val)
{
mLastValue = val;
_hasBeenRead=false;
_callback->DoControl(val);
};
/// Returns the last received value
virtual const ControlDataType& GetLastValue() const
{
_hasBeenRead=true;
return mLastValue;
};
/// Convenience method to get the string representation of the last value.
/// This just works if the token is storable as XML leaf, if not a "Not printable"
/// string is given.
const std::string GetLastValueAsString() // TODO: Use plugins as soon we start to use non streamable types
{
return GetLastValueAsString((TokenIsStorableAsLeaf*)0);
}
// For the typed linking check
virtual const std::type_info& GetTypeId() const { return typeid(ControlDataType); };
private:
std::string GetLastValueAsString(StaticFalse* /*isStreamable*/) const
{
return "Not printable";
}
/** @return A string with the extracted XML content */
std::string GetLastValueAsString(StaticTrue* /*isStreamable*/) const
{
std::ostringstream valueStream;
valueStream << GetLastValue();
return valueStream.str();
}
private:
// Callback wrappers
/// Base control callback wrapper. It defines the interface for callback wrappers.
typedef typename TypeInfo<ControlDataType>::StorableAsLeaf TokenIsStorableAsLeaf;
class Callback
{
public:
virtual ~Callback() {}
virtual void DoControl(const ControlDataType & val) =0;
};
/// Null control callback wrapper. Just do nothing.
class NullCallback : public Callback
{
public:
virtual void DoControl(const ControlDataType & val) {}
};
/// Processing method callback wrapper.
/// Calls a processing method that receives the value as const reference.
template <typename ProcessingType, typename ValueParameterType>
class MethodCallback : public Callback
{
protected:
ProcessingType * _processing;
void (ProcessingType::*_method)(const ValueParameterType& );
public:
MethodCallback(ProcessingType * processing, void (ProcessingType::*method)(const ValueParameterType &) )
: _processing(processing)
, _method(method)
{
}
virtual void DoControl(const ControlDataType & value)
{
(_processing->*_method)(value);
}
};
/// Processing method callback wrapper with control id.
/// Calls a processing method that receives the value as const reference.
/// The id enables reusing the same callback for different controls,
/// but still knowing the originating control.
template <typename ProcessingType, typename ValueParameterType>
class MethodCallbackWithId : public Callback
{
ProcessingType * _processing;
void (ProcessingType::*_method)(unsigned, const ValueParameterType &);
unsigned _id;
public:
MethodCallbackWithId(ProcessingType * processing, void (ProcessingType::*method)(unsigned,const ValueParameterType &), unsigned id )
: _processing(processing)
, _method(method)
, _id(id)
{
}
virtual void DoControl(const ControlDataType & value)
{
(_processing->*_method)(_id, value);
}
};
/// Processing method callback wrapper by copy.
/// Calls a processing method that receives the control value by copy.
/// To use with basic (cheap copy) objects (ints, bools, floats...)
template <typename ProcessingType, typename ValueParameterType>
class MethodCallbackByCopy : public Callback
{
protected:
ProcessingType * _processing;
void (ProcessingType::*_method)(ValueParameterType);
public:
MethodCallbackByCopy(ProcessingType * processing, void (ProcessingType::*method)(ValueParameterType) )
: _processing(processing)
, _method(method)
{
}
virtual void DoControl(const ControlDataType & value)
{
(_processing->*_method)(value);
}
};
/// Processing method callback wrapper by copy with control id.
/// Calls a processing method that receives the control value by copy.
/// To use with basic (cheap copy) objects (ints, bools, floats...)
/// The id enables reusing the same callback for different controls,
/// but still knowing the originating control.
template <typename ProcessingType, typename ValueParameterType>
class MethodCallbackByCopyWithId : public Callback
{
ProcessingType * _processing;
void (ProcessingType::*_method)(unsigned, ValueParameterType);
unsigned _id;
public:
MethodCallbackByCopyWithId(ProcessingType * processing, void (ProcessingType::*method)(unsigned,ValueParameterType), unsigned id )
: _processing(processing)
, _method(method)
, _id(id)
{
}
virtual void DoControl(const ControlDataType & value)
{
(_processing->*_method)(_id, value);
}
};
};
/// Alias provided by convenience to ease the transitions to typed controls
typedef InControl<float> FloatInControl;
} // End namespace CLAM
#endif //_InControl_
|