diff options
author | James Goppert <james.goppert@gmail.com> | 2014-03-16 15:54:35 -0400 |
---|---|---|
committer | James Goppert <james.goppert@gmail.com> | 2014-03-20 12:12:42 -0400 |
commit | 2c32cdf16bb02a9ae4d47b60cb32553fefb33738 (patch) | |
tree | 6407151cef5f6b91697a46532d0d044b4303b1fe /src/modules | |
parent | 239a0cc1550ac872bbef1822ad11674edef3df2c (diff) | |
download | px4-firmware-2c32cdf16bb02a9ae4d47b60cb32553fefb33738.tar.gz px4-firmware-2c32cdf16bb02a9ae4d47b60cb32553fefb33738.tar.bz2 px4-firmware-2c32cdf16bb02a9ae4d47b60cb32553fefb33738.zip |
Fixed block param template.
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/controllib/block/BlockParam.cpp | 25 | ||||
-rw-r--r-- | src/modules/controllib/block/BlockParam.hpp | 39 |
2 files changed, 36 insertions, 28 deletions
diff --git a/src/modules/controllib/block/BlockParam.cpp b/src/modules/controllib/block/BlockParam.cpp index fd12e365d..8f98da74f 100644 --- a/src/modules/controllib/block/BlockParam.cpp +++ b/src/modules/controllib/block/BlockParam.cpp @@ -76,4 +76,29 @@ BlockParamBase::BlockParamBase(Block *parent, const char *name, bool parent_pref 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 diff --git a/src/modules/controllib/block/BlockParam.hpp b/src/modules/controllib/block/BlockParam.hpp index 36bc8c24b..735b2b292 100644 --- a/src/modules/controllib/block/BlockParam.hpp +++ b/src/modules/controllib/block/BlockParam.hpp @@ -70,38 +70,21 @@ protected: * Parameters that are tied to blocks for updating and nameing. */ -class __EXPORT BlockParamFloat : public BlockParamBase +template <class T> +class BlockParam : public BlockParamBase { public: - BlockParamFloat(Block *block, const char *name, bool parent_prefix=true) : - BlockParamBase(block, name, parent_prefix), - _val() { - update(); - } - float get() { return _val; } - void set(float val) { _val = val; } - void update() { - if (_handle != PARAM_INVALID) param_get(_handle, &_val); - } + BlockParam(Block *block, const char *name, + bool parent_prefix=true); + T get(); + void set(T val); + void update(); + virtual ~BlockParam(); protected: - float _val; + T _val; }; -class __EXPORT BlockParamInt : public BlockParamBase -{ -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; -}; +typedef BlockParam<float> BlockParamFloat; +typedef BlockParam<int> BlockParamInt; } // namespace control |