CVB++ 15.0
enumeration_node.hpp
1#pragma once
2
3#include "../global.hpp"
4
5#include "integer_base_node.hpp"
6#include "value_node.hpp"
7
9#include "_detail/ihas_value_config.hpp"
10#include "_detail/iconfigurable_register_node.hpp"
11#include "_detail/iconfigurable_command_node.hpp"
13
14namespace Cvb
15{
16 CVB_BEGIN_INLINE_NS
17 namespace GevServer
18 {
20
22 class EnumerationNode
23 : public SelectorNode
25 , public Private::IHasValueConfig<IntegerBaseNodePtr>
27 {
28 public:
29 explicit EnumerationNode(HandleGuard<Node> &&guard)
30 : SelectorNode(std::move(guard))
31 {
32 }
33
44 static EnumerationNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
45 {
46 String okName = EnsureNodeNameOnly(name);
47 return std::make_shared<EnumerationNode>(HandleGuard<Node>(
48 CExports::CreateGSEnumerationNodeTyped(okName.data(), static_cast<CExports::TGSNamespace>(nameSpace))));
49 }
50
65 static EnumerationNodePtr Create(const String &name)
66 {
67 return Create(ParseName(name), ParseNamespace(name));
68 }
69
75 {
77 this, [](Node *node) { return dynamic_cast<Private::IConfigurableRegisterNode *>(node) ? true : false; });
78 if (value == nullptr)
80 else
81 return value->AccessMode();
82 }
83
90 {
92 this, [](Node *node) { return dynamic_cast<Private::IConfigurableRegisterNode *>(node) ? true : false; });
93 if (value == nullptr)
95 else
96 return value->CacheMode();
97 }
98
104 template <class Rep, class Period>
106 {
108 auto isRegisterNode = dynamic_cast<Private::IConfigurableRegisterNode *>(node);
109 auto isCommandNode = dynamic_cast<Private::IConfigurableCommandNode *>(node);
110 return (isRegisterNode || isCommandNode) ? true : false;
111 });
112 if (value == nullptr)
114 else
115 return value->template PollingTime<Rep, Period>();
116 }
117
128
129 IntegerBaseNodePtr ValueConfigAsNode() const override;
130
140 template <class T>
141 T ValueConfig() const
142 {
143 throw std::runtime_error(
144 "requested value config type must be derived from GSIntergerBaseNode "
145 "or be of type int64_t");
146 }
147
161
162 template <class T>
163 void SetValueConfig(const T & /*value*/)
164 {
165 throw std::runtime_error(
166 "requested value config type must be derived from "
167 "IntegerBaseNode or be of type std::int64_t");
168 }
169
171
175 String Value() const
176 {
177 return ToString();
178 }
179
181
186 {
187 return GetInfoAsInt(NodeInfo::Value);
188 }
189
191
195 void SetValue(const String &value)
196 {
197 FromString(value);
198 }
199
204 void FromString(const String &value) override
205 {
206 NativeCall([&]() { return CExports::GSNSetAsStringTyped(Handle(), value.data()); });
207 }
208
213 String ToString() const override
214 {
215 auto bufferSize = NativeCall<size_t>(
216 [&](size_t &size) { return CExports::GSNGetAsStringTyped(Handle(), reinterpret_cast<Char *>(0), size); });
217 bufferSize += sizeof(Char);
218 std::vector<Char> buffer(bufferSize);
219 NativeCall([&]() { return CExports::GSNGetAsStringTyped(Handle(), buffer.data(), bufferSize); });
220 return buffer.data();
221 }
222 };
223
224 template <>
225 inline std::int64_t EnumerationNode::ValueConfig<std::int64_t>() const
226 {
227 return GetInfoAsInt(NodeInfo::Value);
228 }
229
230 template <>
231 inline void EnumerationNode::SetValueConfig<std::int64_t>(const std::int64_t &value)
232 {
233 SetInfoAsInt(NodeInfo::Value, value);
234 }
235 } // namespace GevServer
236 CVB_END_INLINE_NS
237} // namespace Cvb
void SetValue(const String &value)
Sets the symbolic value of this enumeration.
Definition enumeration_node.hpp:195
String Value() const
Gets the symbolic value of this enumeration.
Definition enumeration_node.hpp:175
void SetValueConfig(const T &)
Sets the value configuration of this enumeration node.
Definition enumeration_node.hpp:163
void FromString(const String &value) override
Same as assigning value to Value.
Definition enumeration_node.hpp:204
std::vector< EnumEntryNodePtr > Entries() const
Gets all enum entries of this enumeration.
Definition enumeration_node.hpp:124
GenApi::CacheMode CacheMode() const override
Gets the cache mode by querying all ValueConfigs for it.
Definition enumeration_node.hpp:89
T ValueConfig() const
Gets the value configuration of this enumeration node.
Definition enumeration_node.hpp:141
GenApi::AccessMode AccessMode() const override
Gets the access mode by querying all ValueConfigs for it.
Definition enumeration_node.hpp:74
static EnumerationNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new EnumerationNode with the given name and nameSpace .
Definition enumeration_node.hpp:44
static EnumerationNodePtr Create(const String &name)
Creates a new EnumerationNode with the given name .
Definition enumeration_node.hpp:65
std::int64_t NumericValue() const
Gets the numeric value of this enumeration.
Definition enumeration_node.hpp:185
String ToString() const override
Same as getting the Value.
Definition enumeration_node.hpp:213
std::chrono::duration< Rep, Period > PollingTime() const
Gets the polling time by querying all ValueConfigs for it.
Definition enumeration_node.hpp:105
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
std::vector< std::shared_ptr< T > > GetDependentNodes(const NodeList &type) const
Gets the nodes categorized by this node.
Definition detail_node.hpp:410
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< EnumerationNode > EnumerationNodePtr
Convenience shared pointer for EnumerationNode.
Definition gevserver.hpp:116
@ Value
Accesses the value configuration.
Definition gevserver.hpp:210
@ String
Node is a string node (no reg).
Definition gevserver.hpp:168
@ Child
Definition gevserver.hpp:250
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
char Char
Character type for wide characters or unicode characters.
Definition string.hpp:63