IDS peak genericC++ v1.14.0
Loading...
Searching...
No Matches
peak_string_node.hpp
Go to the documentation of this file.
1
10
11#pragma once
12
13
15#include <peak/dll_interface/peak_dll_interface_util.hpp>
18
19#include <cstdint>
20#include <string>
21#include <type_traits>
22
23namespace peak
24{
25namespace core
26{
27namespace nodes
28{
29
35class StringNode : public Node
36{
37public:
38 static constexpr auto NodeType = nodes::NodeType::String;
39 using NodeDataType = std::string;
40 using NodeHasRange = std::false_type;
41
42 StringNode() = delete;
43 ~StringNode() override = default;
44 StringNode(const StringNode& other) = delete;
45 StringNode& operator=(const StringNode& other) = delete;
46 StringNode(StringNode&& other) = delete;
47 StringNode& operator=(StringNode&& other) = delete;
48
58 int64_t MaximumLength() const;
59
61 std::string Value(NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
62
64 void SetValue(const std::string& value);
65
66private:
67 friend ClassCreator<StringNode>;
68 StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
69 PEAK_STRING_NODE_HANDLE m_backendHandle;
70};
71
72} /* namespace nodes */
73} /* namespace core */
74} /* namespace peak */
75
76/* Implementation */
77namespace peak
78{
79namespace core
80{
81namespace nodes
82{
83
84inline StringNode::StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
85 : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
86 return PEAK_C_ABI_PREFIX PEAK_StringNode_ToNode(stringNodeHandle, nodeHandle);
87 }),
88 parentNodeMap)
89 , m_backendHandle(stringNodeHandle)
90{}
91
92inline int64_t StringNode::MaximumLength() const
93{
94 return QueryNumericFromCInterfaceFunction<int64_t>([&](int64_t* maximumLength) {
95 return PEAK_C_ABI_PREFIX PEAK_StringNode_GetMaximumLength(m_backendHandle, maximumLength);
96 });
97}
98
99inline std::string StringNode::Value(NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
100{
101 auto lock = ParentNodeMap()->Lock();
102
103 return QueryStringFromCInterfaceFunction([&](char* value, size_t* valueSize) {
105 m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), value, valueSize);
106 });
107}
108
109inline void StringNode::SetValue(const std::string& value)
110{
111 auto lock = ParentNodeMap()->Lock();
112
113 CallAndCheckCInterfaceFunction([&] {
114 return PEAK_C_ABI_PREFIX PEAK_StringNode_SetValue(m_backendHandle, value.c_str(), value.size() + 1);
115 });
116}
117
118} /* namespace nodes */
119} /* namespace core */
120} /* namespace peak */
std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition peak_node.hpp:939
StringNode & operator=(StringNode &&other)=delete
std::string NodeDataType
Definition peak_string_node.hpp:39
static constexpr auto NodeType
Definition peak_string_node.hpp:38
void SetValue(const std::string &value)
Sets the given value.
Definition peak_string_node.hpp:109
~StringNode() override=default
StringNode(const StringNode &other)=delete
std::false_type NodeHasRange
Definition peak_string_node.hpp:40
StringNode & operator=(const StringNode &other)=delete
int64_t MaximumLength() const
Returns the maximum length.
Definition peak_string_node.hpp:92
std::string Value(NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Returns the value.
Definition peak_string_node.hpp:99
StringNode(StringNode &&other)=delete
NodeCacheUsePolicy
Definition peak_common_node_enums.hpp:26
@ String
Definition peak_node.hpp:96
@ UseCache
Definition peak_common_node_enums.hpp:27
The "nodes" namespace contains all GenAPI node types.
Definition peak_boolean_node.hpp:26
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33
struct PEAK_STRING_NODE * PEAK_STRING_NODE_HANDLE
Definition peak_backend.h:449
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition peak_backend.h:429
PEAK_C_API PEAK_StringNode_GetValue(PEAK_STRING_NODE_HANDLE stringNodeHandle, PEAK_NODE_CACHE_USE_POLICY cacheUsePolicy, char *value, size_t *valueSize)
Asks the given string node for its value.
PEAK_C_API PEAK_StringNode_ToNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given string node to a node.
int32_t PEAK_NODE_CACHE_USE_POLICY
Definition peak_backend.h:242
PEAK_C_API PEAK_StringNode_SetValue(PEAK_STRING_NODE_HANDLE stringNodeHandle, const char *value, size_t valueSize)
Tells the given string node to set the given value.
PEAK_C_API PEAK_StringNode_GetMaximumLength(PEAK_STRING_NODE_HANDLE stringNodeHandle, int64_t *maximumLength)
Asks the given string node for its maximum length.
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:16