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/iconfigurable_enumeration_node.hpp"
10 #include "_detail/ihas_value_config.hpp"
12 
13 namespace Cvb
14 {
15 CVB_BEGIN_INLINE_NS
16 namespace GevServer
17 {
19 
22  : public SelectorNode
24  , public Private::IConfigurableEnumerationNode
25  , public Private::IHasValueConfig<IntegerBaseNodePtr>
27 {
28 public:
29  EnumerationNode(HandleGuard<Node> &&guard) noexcept : SelectorNode(std::move(guard)) {}
30 
41  static EnumerationNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
42  {
43  String okName = EnsureNodeNameOnly(name);
44  return std::make_shared<EnumerationNode>(HandleGuard<Node>(
45  CExports::CreateGSEnumerationNodeTyped(okName.data(), static_cast<CExports::TGSNamespace>(nameSpace))));
46  }
47 
62  static EnumerationNodePtr Create(const String &name) { return Create(ParseName(name), ParseNamespace(name)); }
63 
68  GenApi::AccessMode AccessMode() const override
69  {
70  auto value = GetTerminalRegisterNode<EnumerationNode, IntegerBaseNodePtr>(
71  this, [](Node *node) { return dynamic_cast<GenApi::Private::IRegisterNode *>(node) ? true : false; });
72  if (value == nullptr)
74  else
75  return value->AccessMode();
76  }
77 
83  GenApi::CacheMode CacheMode() const override
84  {
85  auto value = GetTerminalRegisterNode<EnumerationNode, IntegerBaseNodePtr>(
86  this, [](Node *node) { return dynamic_cast<GenApi::Private::IRegisterNode *>(node) ? true : false; });
87  if (value == nullptr)
89  else
90  return value->CacheMode();
91  }
92 
98  template <class Rep, class Period> std::chrono::duration<Rep, Period> PollingTime() const
99  {
100  auto value = GetTerminalRegisterNode<EnumerationNode, IntegerBaseNodePtr>(this, [](Node *node) {
101  auto isRegisterNode = dynamic_cast<GenApi::Private::IRegisterNode *>(node);
102  auto isCommandNode = dynamic_cast<GenApi::Private::ICommandNode *>(node);
103  return (isRegisterNode || isCommandNode) ? true : false;
104  });
105  if (value == nullptr)
107  else
108  return value->template PollingTime<Rep, Period>();
109  }
110 
117  std::vector<EnumEntryNodePtr> Entries() const { return GetDependentNodes<EnumEntryNode>(NodeList::Child); }
118 
119  IntegerBaseNodePtr ValueConfigAsNode() const override;
120 
130  template <class T> T ValueConfig() const
131  {
132  throw std::runtime_error("requested value config type must be derived from GSIntergerBaseNode "
133  "or be of type int64_t");
134  }
135 
149 
150  template <class T> void SetValueConfig(const T & /*value*/)
151  {
152  throw std::runtime_error("requested value config type must be derived from "
153  "IntegerBaseNode or be of type std::int64_t");
154  }
155 
157 
161  String Value() const { return ToString(); }
162 
164 
168  void SetValue(const String &value) { FromString(value); }
169 
174  void FromString(const String &value) override
175  {
176  NativeCall([&]() { return CExports::GSNSetAsStringTyped(Handle(), value.data()); });
177  }
178 
183  virtual String ToString() const override
184  {
185  auto bufferSize = NativeCall<size_t>(
186  [&](size_t &size) { return CExports::GSNGetAsStringTyped(Handle(), reinterpret_cast<Char *>(0), size); });
187  bufferSize += sizeof(Char);
188  std::vector<Char> buffer(bufferSize);
189  NativeCall([&]() { return CExports::GSNGetAsStringTyped(Handle(), buffer.data(), bufferSize); });
190  return buffer.data();
191  }
192 };
193 
194 template <> inline std::int64_t EnumerationNode::ValueConfig<std::int64_t>() const
195 {
196  return GetInfoAsInt(NodeInfo::Value);
197 }
198 
199 template <> inline void EnumerationNode::SetValueConfig<std::int64_t>(const std::int64_t &value)
200 {
201  SetInfoAsInt(NodeInfo::Value, value);
202 }
203 }
204 CVB_END_INLINE_NS
205 }
STL class.
static String ParseName(const String &name)
Gets the name part of the given node name .
Definition: decl_node.hpp:606
static GevServer::Namespace ParseNamespace(const String &name)
Gets the Namespace from the given name .
Definition: decl_node.hpp:584
std::chrono::duration< Rep, Period > PollingTime() const
Gets the polling time by querying all ValueConfigs for it.
Definition: enumeration_node.hpp:98
static EnumerationNodePtr Create(const String &name)
Creates a new EnumerationNode with the given name .
Definition: enumeration_node.hpp:62
Namespace
The possible name spaces a node can be in.
Definition: gevserver.hpp:147
virtual String ToString() const override
Same as getting the Value.
Definition: enumeration_node.hpp:183
T ValueConfig() const
Gets the value configuration of this enumeration node.
Definition: enumeration_node.hpp:130
A GenApi::EnumerationNode that is configurable.
Definition: enumeration_node.hpp:21
static String EnsureNodeNameOnly(const String &name)
Throws if the given name has a namespace prefix.
Definition: decl_node.hpp:557
STL class.
Root namespace for the Image Manager interface.
Definition: version.hpp:11
String Value() const
Gets the symbolic value of this enumeration.
Definition: enumeration_node.hpp:161
static EnumerationNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new EnumerationNode with the given name and nameSpace .
Definition: enumeration_node.hpp:41
void FromString(const String &value) override
Same as assigning value to Value.
Definition: enumeration_node.hpp:174
Node can be read and written to.
char Char
Character type for wide characters or unicode characters.
Definition: string.hpp:59
void SetValueConfig(const T &)
Sets the value configuration of this enumeration node.
Definition: enumeration_node.hpp:150
Accesses the value configuration.
GenApi::AccessMode AccessMode() const override
Gets the access mode by querying all ValueConfigs for it.
Definition: enumeration_node.hpp:68
Groups other nodes that are dependent on this one.
Definition: selector_node.hpp:24
STL class.
GenApi::CacheMode CacheMode() const override
Gets the cache mode by querying all ValueConfigs for it.
Definition: enumeration_node.hpp:83
Basic GevServer node for device feature access.
Definition: decl_node.hpp:37
std::vector< EnumEntryNodePtr > Entries() const
Gets all enum entries of this enumeration.
Definition: enumeration_node.hpp:117
void * Handle() const noexcept
Classic API node handle.
Definition: decl_node.hpp:101
CacheMode
Defines how the value is cached.
Definition: genapi.hpp:219
void SetValue(const String &value)
Sets the symbolic value of this enumeration.
Definition: enumeration_node.hpp:168
AccessMode
Access possibility of the node.
Definition: genapi.hpp:184