Fixed block param template.

This commit is contained in:
James Goppert 2014-03-16 15:54:35 -04:00
parent 239a0cc155
commit 2c32cdf16b
2 changed files with 36 additions and 28 deletions

View File

@ -76,4 +76,29 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref
printf("error finding param: %s\n", fullname); printf("error finding param: %s\n", fullname);
}; };
template <class T>
BlockParam<T>::BlockParam(Block *block, const char *name,
bool parent_prefix) :
BlockParamBase(block, name, parent_prefix),
_val() {
update();
}
template <class T>
T BlockParam<T>::get() { return _val; }
template <class T>
void BlockParam<T>::set(T val) { _val = val; }
template <class T>
void BlockParam<T>::update() {
if (_handle != PARAM_INVALID) param_get(_handle, &_val);
}
template <class T>
BlockParam<T>::~BlockParam() {};
template class __EXPORT BlockParam<float>;
template class __EXPORT BlockParam<int>;
} // namespace control } // namespace control

View File

@ -70,38 +70,21 @@ protected:
* Parameters that are tied to blocks for updating and nameing. * Parameters that are tied to blocks for updating and nameing.
*/ */
class __EXPORT BlockParamFloat : public BlockParamBase template <class T>
class BlockParam : public BlockParamBase
{ {
public: public:
BlockParamFloat(Block *block, const char *name, bool parent_prefix=true) : BlockParam(Block *block, const char *name,
BlockParamBase(block, name, parent_prefix), bool parent_prefix=true);
_val() { T get();
update(); void set(T val);
} void update();
float get() { return _val; } virtual ~BlockParam();
void set(float val) { _val = val; }
void update() {
if (_handle != PARAM_INVALID) param_get(_handle, &_val);
}
protected: protected:
float _val; T _val;
}; };
class __EXPORT BlockParamInt : public BlockParamBase typedef BlockParam<float> BlockParamFloat;
{ typedef BlockParam<int> BlockParamInt;
public:
BlockParamInt(Block *block, const char *name, bool parent_prefix=true) :
BlockParamBase(block, name, parent_prefix),
_val() {
update();
}
int get() { return _val; }
void set(int val) { _val = val; }
void update() {
if (_handle != PARAM_INVALID) param_get(_handle, &_val);
}
protected:
int _val;
};
} // namespace control } // namespace control