CVB++ 14.0
string_reg_node.hpp
1#pragma once
2
3#include "../global.hpp"
4
5#include "string_node.hpp"
6
8#include "_detail/iconfigurable_register_node.hpp"
10
11namespace Cvb
12{
13 CVB_BEGIN_INLINE_NS
14 namespace GevServer
15 {
17
20 : public StringNode
22 , public Private::IConfigurableRegisterNode
24 {
25 public:
26 StringRegNode(HandleGuard<Node>&& guard) noexcept : StringNode(std::move(guard)) {}
27
40 static StringRegNodePtr Create(const String& name, const GevServer::Namespace& nameSpace, const std::int64_t& address, const std::int64_t& length)
41 {
42 String okName = EnsureNodeNameOnly(name);
43 return std::make_shared<StringRegNode>(HandleGuard<Node>(
44 CExports::CreateGSStringRegNodeTyped(okName.data(), static_cast<CExports::TGSNamespace>(nameSpace), address, length)));
45 }
46
62 static StringRegNodePtr Create(const String& name, const std::int64_t& address, const std::int64_t& length)
63 {
64 return Create(ParseName(name), ParseNamespace(name), address, length);
65 }
66
82 static StringRegNodePtr Create(const String& name, const std::int64_t& length)
83 {
84 return Create(ParseName(name), ParseNamespace(name), -1, length);
85 }
86
91 {
92 return static_cast<GenApi::AccessMode>(GetInfoAsInt(NodeInfo::AccessMode));
93 }
94
103 {
104 SetInfoAsInt(NodeInfo::AccessMode, static_cast<std::int64_t>(value));
105 }
106
108
112 std::int64_t Address() const { return StringNode::GetInfoAsInt(NodeInfo::RegisterAddress); }
113
131 {
132 return GetDependentNodes<IntegerBaseNode>(NodeList::Addresses);
133 }
134
139 {
140 return static_cast<GenApi::CacheMode>(GetInfoAsInt(NodeInfo::CachingMode));
141 }
142
151 {
152 SetInfoAsInt(NodeInfo::CachingMode, static_cast<std::int64_t>(value));
153 }
154
165 std::vector<NodePtr> InvalidatorNodes() const noexcept { return GetDependentNodes<Node>(NodeList::Invalidator); }
166
168
172 std::int64_t Length() const { return StringNode::GetInfoAsInt(NodeInfo::RegisterLength); }
173
181 template <class Rep, class Period> std::chrono::duration<Rep, Period> PollingTime() const
182 {
183 auto timespan = GetInfoAsInt(NodeInfo::PollingTime);
184 if (timespan > 0)
185 return std::chrono::duration<Rep, Period>(timespan);
186 else
188 }
189
202 template <class Rep, class Period> void SetPollingTime(const std::chrono::duration<Rep, Period>& timespan)
203 {
205 SetInfoAsInt(NodeInfo::PollingTime, -1);
206 else
207 SetInfoAsInt(NodeInfo::PollingTime, std::chrono::duration_cast<std::chrono::milliseconds>(timespan).count());
208 }
209
211
215 String Value() const
216 {
217 auto bufferSize = NativeCall<size_t>(
218 [&](size_t& size) { return CExports::GSNGetAsStringTyped(Handle(), reinterpret_cast<Char*>(0), size); });
219 bufferSize += sizeof(Char);
220 std::vector<Char> buffer(bufferSize);
221 NativeCall([&]() { return CExports::GSNGetAsStringTyped(Handle(), buffer.data(), bufferSize); });
222 return buffer.data();
223 }
224
226
230 void SetValue(const String& value)
231 {
232 NativeCall([&]() { return CExports::GSNSetAsStringTyped(Handle(), value.data()); });
233 }
234 };
235 }
236 CVB_END_INLINE_NS
237}
static GevServer::Namespace ParseNamespace(const String &name)
Gets the Namespace from the given name .
Definition: decl_node.hpp:585
static String EnsureNodeNameOnly(const String &name)
Throws if the given name has a namespace prefix.
Definition: decl_node.hpp:558
static String ParseName(const String &name)
Gets the name part of the given node name .
Definition: decl_node.hpp:607
void * Handle() const noexcept
Classic API node handle.
Definition: decl_node.hpp:101
String value node.
Definition: string_node.hpp:26
String value register.
Definition: string_reg_node.hpp:24
static StringRegNodePtr Create(const String &name, const std::int64_t &length)
Creates a new StringRegNode with the given name .
Definition: string_reg_node.hpp:82
std::vector< IntegerBaseNodePtr > AddressNodes() const
Gets the collection of nodes which define the nodes address.
Definition: string_reg_node.hpp:130
void SetValue(const String &value)
Sets the value of this string register node.
Definition: string_reg_node.hpp:230
void SetPollingTime(const std::chrono::duration< Rep, Period > &timespan)
Sets the polling time of this value.
Definition: string_reg_node.hpp:202
String Value() const
Gets the value of this string register node.
Definition: string_reg_node.hpp:215
void SetCacheMode(const GenApi::CacheMode &value)
Sets the caching mode of this register node.
Definition: string_reg_node.hpp:150
static StringRegNodePtr Create(const String &name, const GevServer::Namespace &nameSpace, const std::int64_t &address, const std::int64_t &length)
Creates a new StringRegNode with the given name and nameSpace .
Definition: string_reg_node.hpp:40
GenApi::CacheMode CacheMode() const override
Gets the caching mode of this register node.
Definition: string_reg_node.hpp:138
GenApi::AccessMode AccessMode() const override
Gets the GenApi::AccessMode of this node.
Definition: string_reg_node.hpp:90
std::int64_t Length() const
Gets the number of bytes the register occupies.
Definition: string_reg_node.hpp:172
std::int64_t Address() const
Gets the registers address.
Definition: string_reg_node.hpp:112
void SetAccessMode(const GenApi::AccessMode &value)
Gets the GenApi::AccessMode of this node.
Definition: string_reg_node.hpp:102
static StringRegNodePtr Create(const String &name, const std::int64_t &address, const std::int64_t &length)
Creates a new StringRegNode with the given name .
Definition: string_reg_node.hpp:62
std::vector< NodePtr > InvalidatorNodes() const noexcept
Gets the collection of nodes which, when changed, invalidate this node's cache.
Definition: string_reg_node.hpp:165
std::chrono::duration< Rep, Period > PollingTime() const
Gets the polling time of this value.
Definition: string_reg_node.hpp:181
CacheMode
Defines how the value is cached.
Definition: genapi.hpp:220
AccessMode
Access possibility of the node.
Definition: genapi.hpp:185
Namespace
The possible name spaces a node can be in.
Definition: gevserver.hpp:148
@ AccessMode
Gets the access mode of the node.
@ PollingTime
Gets the polling time in ms.
@ CachingMode
Gets the caching mode.
@ RegisterAddress
Gets the current address of the register (can change).
@ RegisterLength
Gets the register nodes length in bytes.
@ Addresses
Node accesses the register address nodes (not constants).
@ Invalidator
Node accesses the invalidator nodes.
Root namespace for the Image Manager interface.
Definition: c_barcode.h:24
char Char
Character type for wide characters or unicode characters.
Definition: string.hpp:59