CVB++ 14.1
string_node.hpp
1#pragma once
2
3#include "../global.hpp"
4
5#include "selector_node.hpp"
6
8#include "_detail/ihas_value_config.hpp"
9#include "_detail/iconfigurable_register_node.hpp"
11
12namespace Cvb
13{
14CVB_BEGIN_INLINE_NS
15namespace GevServer
16{
18
21 : public SelectorNode
23 , public Private::IHasValueConfig<StringNodePtr>
25{
26public:
27 explicit StringNode(HandleGuard<Node> &&guard) : SelectorNode(std::move(guard)) {}
28
39 static StringNodePtr Create(const String& name, const GevServer::Namespace& nameSpace)
40 {
41 String okName = EnsureNodeNameOnly(name);
42 return std::make_shared<StringNode>(HandleGuard<Node>(
43 CExports::CreateGSStringNodeExTyped(okName.data(), static_cast<CExports::TGSNamespace>(nameSpace))));
44 }
45
59 static StringNodePtr Create(const String& name)
60 {
61 return Create(ParseName(name), ParseNamespace(name));
62 }
63
69 {
70 auto value = GetTerminalRegisterNode<StringNode, StringNodePtr>(
71 this, [](Node* node) { return dynamic_cast<GevServer::Private::IConfigurableRegisterNode*>(node) ? true : false; });
72 if (value == nullptr)
74 else
75 return value->AccessMode();
76 }
77
83 {
84 auto value = GetTerminalRegisterNode<StringNode, StringNodePtr>(
85 this, [](Node* node) { return dynamic_cast<Private::IConfigurableRegisterNode*>(node) ? true : false; });
86 if (value == nullptr)
88 else
89 return value->CacheMode();
90 }
91
92 StringNodePtr ValueConfigAsNode() const override;
93
95
99 String Value() const { return ToString(); }
100
102
106 void SetValue(const String &value) { FromString(value); }
107
108
118 template <class T> T ValueConfig() const
119 {
120 throw std::runtime_error("requested value config type must be derived from StringNode or be "
121 "of type Cvb::String");
122 }
123
137 template <class T> void SetValueConfig(const T& /*value*/)
138 {
139 throw std::runtime_error("requested value config type must be derived from "
140 "StringNode or be of Cvb::String type");
141 }
142};
143
144template <> inline Cvb::String StringNode::ValueConfig<Cvb::String>() const
145{
146 return GetInfoAsString(NodeInfo::Value);
147}
148
149template <> inline void StringNode::SetValueConfig<Cvb::String>(const Cvb::String& value)
150{
151 SetInfoAsString(NodeInfo::Value, value);
152}
153
154}
155CVB_END_INLINE_NS
156}
Basic GevServer node for device feature access.
Definition: decl_node.hpp:36
static GevServer::Namespace ParseNamespace(const String &name)
Gets the Namespace from the given name .
Definition: decl_node.hpp:567
static String EnsureNodeNameOnly(const String &name)
Throws if the given name has a namespace prefix.
Definition: decl_node.hpp:540
static String ParseName(const String &name)
Gets the name part of the given node name .
Definition: decl_node.hpp:588
Groups other nodes that are dependent on this one.
Definition: selector_node.hpp:24
String value node.
Definition: string_node.hpp:25
void SetValue(const String &value)
Sets the string value.
Definition: string_node.hpp:106
String Value() const
Gets the string value.
Definition: string_node.hpp:99
void SetValueConfig(const T &)
Sets the value configuration of this string node.
Definition: string_node.hpp:137
static StringNodePtr Create(const String &name)
Creates a new StringNode with the given name .
Definition: string_node.hpp:59
GenApi::CacheMode CacheMode() const override
Gets the cache mode of this node.
Definition: string_node.hpp:82
T ValueConfig() const
Gets the value configuration of this string node.
Definition: string_node.hpp:118
GenApi::AccessMode AccessMode() const override
Definition: string_node.hpp:68
static StringNodePtr Create(const String &name, const GevServer::Namespace &nameSpace)
Creates a new StringNode with the given name and nameSpace .
Definition: string_node.hpp:39
virtual String ToString() const
Returns this node's value as a string representation.
Definition: value_node.hpp:94
virtual void FromString(const String &value)
Sets this node's value from the string value.
Definition: value_node.hpp:109
CacheMode
Defines how the value is cached.
Definition: genapi.hpp:220
@ NoCache
No caching used.
AccessMode
Access possibility of the node.
Definition: genapi.hpp:185
@ ReadWrite
Node can be read and written to.
Namespace
The possible name spaces a node can be in.
Definition: gevserver.hpp:147
@ Value
Accesses the value configuration.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24