4 #include <swarmio/data/Variant.pb.h> 5 #include <swarmio/data/discovery/Schema.pb.h> 51 : _readOnly(readOnly), _path(path)
54 _value.set_bool_value(value);
64 : _readOnly(readOnly), _path(path)
67 _value.set_string_value(value);
77 : _readOnly(readOnly), _path(path)
80 _value.set_string_value(value);
90 : _readOnly(readOnly), _path(path)
92 _type = data::discovery::Type::INT;
93 _value.set_int_value(value);
103 : _readOnly(readOnly), _path(path)
105 _type = data::discovery::Type::DOUBLE;
106 _value.set_double_value(value);
114 virtual data::Variant
Get(
const std::string& path)
override 122 throw Exception(
"In memory parameter queried for unknown resource path.");
131 virtual void Set(
const std::string& path,
const data::Variant& value)
override 137 throw Exception(
"Parameter is read-only.");
141 switch (value.value_case())
143 case data::Variant::ValueCase::kBoolValue:
150 throw Exception(
"Invalid type for parameter.");
154 case data::Variant::ValueCase::kDoubleValue:
155 if (_type == data::discovery::Type::DOUBLE)
161 throw Exception(
"Invalid type for parameter.");
165 case data::Variant::ValueCase::kIntValue:
166 if (_type == data::discovery::Type::INT)
172 throw Exception(
"Invalid type for parameter.");
176 case data::Variant::ValueCase::kStringValue:
183 throw Exception(
"Invalid type for parameter.");
188 throw Exception(
"Unknown type for parameter.");
195 throw Exception(
"In memory parameter queried for unknown resource path.");
208 data::discovery::Field field;
209 field.set_type(_type);
214 throw Exception(
"In memory parameter queried for unknown resource path.");
223 virtual bool CanWrite(
const std::string& path)
const noexcept
override 240 virtual bool CanRead(
const std::string& path)
const noexcept
override virtual void Set(const std::string &path, const data::Variant &value) override
Set the current value of the target.
Abstract base class for registered keys.
bool _readOnly
Is read-only?
std::string _path
Resource path.
virtual bool CanWrite(const std::string &path) const noexceptoverride
Determines whether the value can be written.
virtual bool CanRead(const std::string &path) const noexceptoverride
Determines whether the value can be read.
data::discovery::Type _type
Type.
Exception class thrown by all library classes.
InMemoryParameter(const std::string &path, bool value, bool readOnly=false)
Create a new boolean in-memory parameter.
A strongly typed in-memory parameter target that can be made read-only.
data::Variant _value
Value.
const std::string & GetPath() const
Get the resource path of the parameter.
InMemoryParameter(const std::string &path, const std::string &value, bool readOnly=false)
Create a new string in-memory parameter.
virtual data::Variant Get(const std::string &path) override
Get the current value of the target.
virtual data::discovery::Field GetFieldDescriptor(const std::string &path) const override
Get the data type of the target.
InMemoryParameter(const std::string &path, int value, bool readOnly=false)
Create a new integer in-memory parameter.
InMemoryParameter(const std::string &path, double value, bool readOnly=false)
Create a new integer in-memory parameter.
InMemoryParameter(const std::string &path, const char *value, bool readOnly=false)
Create a new string in-memory parameter.