RTC Toolkit 4.0.2
Loading...
Searching...
No Matches
parameter.hpp
Go to the documentation of this file.
1
13#ifndef RTCTK_DATATASK_PARAMETER_HPP
14#define RTCTK_DATATASK_PARAMETER_HPP
15
16#include <stdexcept>
17#include <string>
18
20
21namespace rtctk::dataTask {
22
27public:
28 ParameterNotSet(const std::string& par_name)
29 : rtctk::componentFramework::RtctkException("Parameter '" + par_name + "' not set!") {
30 }
31};
32
37public:
38 ParameterNotWriteable(const std::string& par_name)
39 : rtctk::componentFramework::RtctkException("Parameter '" + par_name + "' not writeable!") {
40 }
41};
42
50// TODO can we do some value range checking with traits as well here?
51template <class T>
52class [[deprecated]] Parameter {
53public:
54 Parameter(std::string const& name)
55 : m_name(name), m_value(), m_is_set(false), m_is_locked(false) {
56 }
57
58 Parameter(std::string const& name, T const& value)
59 : m_name(name), m_value(value), m_is_set(true), m_is_locked(false) {
60 }
61
66 void Set(T const& value) {
67 if (m_is_locked) {
68 CII_THROW(ParameterNotWriteable, m_name);
69 }
70 m_value = value;
71 m_is_set = true;
72 }
73
77 void Lock() {
78 m_is_locked = true;
79 }
80
84 void Unlock() {
85 m_is_locked = false;
86 }
87
92 T& Get() {
93 if (not m_is_set) {
94 CII_THROW(ParameterNotSet, m_name);
95 }
96 return m_value;
97 }
98
103 bool IsSet() {
104 return m_is_set;
105 }
106
110 void CheckSet() {
111 if (not m_is_set) {
112 CII_THROW(ParameterNotSet, m_name);
113 }
114 }
115
116private:
117 const std::string m_name; //< name of paramter
118 T m_value; //< value
119 bool m_is_set; //< bool is the value set
120 bool m_is_locked; //< bool is the value locked.
121};
122
123} // namespace rtctk::dataTask
124
125#endif // RTCTK_DATATASK_PARAMETER_HPP
The RtctkException class is the base class for all Rtctk exceptions.
Definition: exceptions.hpp:237
Definition: parameter.hpp:26
ParameterNotSet(const std::string &par_name)
Definition: parameter.hpp:28
Definition: parameter.hpp:36
ParameterNotWriteable(const std::string &par_name)
Definition: parameter.hpp:38
Class for basic handling of parameters in read thread.
Definition: parameter.hpp:52
void Set(T const &value)
Set interface for setting values.
Definition: parameter.hpp:66
bool IsSet()
checks if the value in paramter has been set
Definition: parameter.hpp:103
Parameter(std::string const &name, T const &value)
Definition: parameter.hpp:58
T & Get()
get the value set in paramter
Definition: parameter.hpp:92
Parameter(std::string const &name)
Definition: parameter.hpp:54
void CheckSet()
Check if set if not set throw error.
Definition: parameter.hpp:110
void Lock()
lock parameter so cannot be changed while locked
Definition: parameter.hpp:77
void Unlock()
unlock interface
Definition: parameter.hpp:84
Provides macros and utilities for exception handling.
Definition: computationBase.hpp:33
Definition: commandReplier.cpp:22
std::string m_name
Definition: populateConfig.cpp:166