CVB++ 15.0
boolean_node.hpp
1#pragma once
2
3#include <cctype>
4
5#include "../global.hpp"
6
7#include "integer_base_node.hpp"
8#include "value_node.hpp"
9
11#include "_detail/ihas_value_config.hpp"
12#include "_detail/iconfigurable_register_node.hpp"
13#include "_detail/iconfigurable_command_node.hpp"
15
16namespace Cvb
17{
18 CVB_BEGIN_INLINE_NS
19
20 namespace GevServer
21 {
23
24 class BooleanNode
25 : public ValueNode
27 , public Private::IHasValueConfig<IntegerBaseNodePtr>
29 {
30 public:
31 explicit BooleanNode(HandleGuard<Node> &&guard)
32 : ValueNode(std::move(guard))
33 {
34 }
35
46 static BooleanNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
47 {
48 String okName = EnsureNodeNameOnly(name);
49 return std::make_shared<BooleanNode>(HandleGuard<Node>(
50 CExports::CreateGSBooleanNodeTyped(okName.data(), static_cast<CExports::TGSNamespace>(nameSpace))));
51 }
52
66 static BooleanNodePtr Create(const String &name)
67 {
68 return Create(ParseName(name), ParseNamespace(name));
69 }
70
76 {
78 auto hasValueConfig = dynamic_cast<Private::IHasValueConfig<IntegerBaseNodePtr> *>(node);
79 return (dynamic_cast<Private::IConfigurableRegisterNode *>(node) || !hasValueConfig->ValueConfigAsNode())
80 ? true
81 : false;
82 });
83 if (value == nullptr)
85 else
86 return value->AccessMode();
87 }
88
94 {
96 auto hasValueConfig = dynamic_cast<Private::IHasValueConfig<IntegerBaseNodePtr> *>(node);
97 return (dynamic_cast<Private::IConfigurableRegisterNode *>(node) || !hasValueConfig->ValueConfigAsNode())
98 ? true
99 : false;
100 });
101 if (value == nullptr)
103 else
104 return value->CacheMode();
105 }
106
111 template <class Rep, class Period>
113 {
115 auto isRegisterNode = dynamic_cast<Private::IConfigurableRegisterNode *>(node);
116 auto isCommandNode = dynamic_cast<Private::IConfigurableCommandNode *>(node);
117 return (isRegisterNode || isCommandNode) ? true : false;
118 });
119 if (value == nullptr)
121 else
122 return value->template PollingTime<Rep, Period>();
123 }
124
130 {
131 return GetInfoAsInt(NodeInfo::OffValue);
132 }
133
142 void SetOffValue(const std::int64_t &value)
143 {
144 SetInfoAsInt(NodeInfo::OffValue, value);
145 }
146
152 {
153 return GetInfoAsInt(NodeInfo::OnValue);
154 }
155
164 void SetOnValue(const std::int64_t &value)
165 {
166 SetInfoAsInt(NodeInfo::OnValue, value);
167 }
168
170
174 bool Value() const
175 {
176 return (NativeCall<CExports::cvbbool_t>(
177 [&](CExports::cvbbool_t &value) { return CVB_CALL_CAPI(GSNGetAsBoolean(Handle(), value)); }))
178 ? true
179 : false;
180 }
181
183
187 void SetValue(bool value)
188 {
189 NativeCall([&]() { return CVB_CALL_CAPI(GSNSetAsBoolean(Handle(), static_cast<CExports::cvbbool_t>(value))); });
190 }
191
200 template <class T>
201 T ValueConfig() const
202 {
203 throw std::runtime_error(
204 "requested value config type must be derived from IntegerBaseNode or be "
205 "of type int64_t");
206 }
207
208 IntegerBaseNodePtr ValueConfigAsNode() const override;
209
222 template <class T>
223 void SetValueConfig(const T & /*value*/)
224 {
225 throw std::runtime_error(
226 "requested command config type must be derived from "
227 "IntegerBaseNode or be of integral type");
228 }
229
234 void FromString(const String &value) override
235 {
236 if (value.empty())
237 throw std::runtime_error("String must not be empty");
238
239 std::string str(Internal::CastToAscii(value));
240 std::transform(str.begin(), str.end(), str.begin(),
241 [](char ch) { return static_cast<char>(std::tolower(ch)); });
242 std::istringstream is(str);
243 bool b = false;
244 is >> std::boolalpha >> b;
245 SetValue(b);
246 }
247
254 String ToString() const override
255 {
256 return Value() ? CVB_LIT("true") : CVB_LIT("false");
257 }
258 };
259
260 template <>
261 inline std::int64_t BooleanNode::ValueConfig<std::int64_t>() const
262 {
263 return GetInfoAsInt(NodeInfo::Value);
264 }
265
266 template <>
267 inline void BooleanNode::SetValueConfig<std::int64_t>(const std::int64_t &value)
268 {
269 SetInfoAsInt(NodeInfo::Value, value);
270 }
271 } // namespace GevServer
272 CVB_END_INLINE_NS
273} // namespace Cvb
T boolalpha(T... args)
void SetOffValue(const std::int64_t &value)
Sets the value to be written if GenApi::IBooleanNode.Value is set to false.
Definition boolean_node.hpp:142
void SetValue(bool value)
Sets the value of this boolean node.
Definition boolean_node.hpp:187
std::int64_t OffValue() const
Gets the value to be written if GenApi::IBooleanNode.Value is set to false.
Definition boolean_node.hpp:129
bool Value() const
Gets the value of this boolean node.
Definition boolean_node.hpp:174
void SetValueConfig(const T &)
Sets the value configuration of this boolean node.
Definition boolean_node.hpp:223
static BooleanNodePtr Create(const String &name)
Creates a new BooleanNode with the given name .
Definition boolean_node.hpp:66
void FromString(const String &value) override
Sets this node's value from the string value .
Definition boolean_node.hpp:234
void SetOnValue(const std::int64_t &value)
Sets the value to be written if GenApi::IBooleanNode.Value is set to true.
Definition boolean_node.hpp:164
std::int64_t OnValue() const
Gets the value to be written if GenApi::IBooleanNode.Value is set to true.
Definition boolean_node.hpp:151
GenApi::CacheMode CacheMode() const override
Gets the cache mode by querying all ValueConfigs for it.
Definition boolean_node.hpp:93
T ValueConfig() const
Gets the value configuration of this boolean node.
Definition boolean_node.hpp:201
GenApi::AccessMode AccessMode() const override
Gets the access mode by querying all ValueConfigs for it.
Definition boolean_node.hpp:75
static BooleanNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new BooleanNode with the given name and nameSpace .
Definition boolean_node.hpp:46
String ToString() const override
Gets the string representation of this node.
Definition boolean_node.hpp:254
std::chrono::duration< Rep, Period > PollingTime() const
Gets the polling time by querying all ValueConfigs for it.
Definition boolean_node.hpp:112
Basic GevServer node for device feature access.
Definition decl_node.hpp:34
static GevServer::Namespace ParseNamespace(const String &name)
Gets the Namespace from the given name .
Definition decl_node.hpp:591
static String EnsureNodeNameOnly(const String &name)
Throws if the given name has a namespace prefix.
Definition decl_node.hpp:564
static String ParseName(const String &name)
Gets the name part of the given node name .
Definition decl_node.hpp:611
ValueNodePtr GetTerminalRegisterNode(const NodeT *node, std::function< bool(Node *)> f) const
Try to get terminal register node.
Definition detail_node.hpp:708
void * Handle() const noexcept
Classic API node handle.
Definition decl_node.hpp:102
T make_shared(T... args)
T move(T... args)
CacheMode
Defines how the value is cached.
Definition genapi.hpp:218
@ NoCache
No caching used.
Definition genapi.hpp:220
AccessMode
Access possibility of the node.
Definition genapi.hpp:183
@ ReadWrite
Node can be read and written to.
Definition genapi.hpp:213
Describes a GenICam Pixel Format Naming Convention (PFNC) compatible image memory buffer with possibl...
Definition decl_int_swiss_knife_node.hpp:11
Namespace
The possible name spaces a node can be in.
Definition gevserver.hpp:147
std::shared_ptr< IntegerBaseNode > IntegerBaseNodePtr
Convenience shared pointer for IntegerBaseNode.
Definition gevserver.hpp:64
std::shared_ptr< BooleanNode > BooleanNodePtr
Convenience shared pointer for BooleanNode.
Definition gevserver.hpp:56
@ OnValue
Definition gevserver.hpp:211
@ Value
Accesses the value configuration.
Definition gevserver.hpp:210
@ OffValue
Boolean specific: accesses the integer value for false.
Definition gevserver.hpp:213
@ String
Node is a string node (no reg).
Definition gevserver.hpp:168
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
T transform(T... args)