IDS peak genericC++ v1.12.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
34class StringNode : public Node
35{
36public:
37 static constexpr auto NodeType = nodes::NodeType::String;
38 using NodeDataType = std::string;
39 using NodeHasRange = std::false_type;
40
41 StringNode() = delete;
42 ~StringNode() override = default;
43 StringNode(const StringNode& other) = delete;
44 StringNode& operator=(const StringNode& other) = delete;
45 StringNode(StringNode&& other) = delete;
46 StringNode& operator=(StringNode&& other) = delete;
47
57 int64_t MaximumLength() const;
58
60 std::string Value(NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
61
63 void SetValue(const std::string& value);
64
65private:
66 friend ClassCreator<StringNode>;
67 StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
68 PEAK_STRING_NODE_HANDLE m_backendHandle;
69};
70
71} /* namespace nodes */
72} /* namespace core */
73} /* namespace peak */
74
75/* Implementation */
76namespace peak
77{
78namespace core
79{
80namespace nodes
81{
82
83inline StringNode::StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
84 : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
85 return PEAK_C_ABI_PREFIX PEAK_StringNode_ToNode(stringNodeHandle, nodeHandle);
86 }),
87 parentNodeMap)
88 , m_backendHandle(stringNodeHandle)
89{}
90
91inline int64_t StringNode::MaximumLength() const
92{
93 return QueryNumericFromCInterfaceFunction<int64_t>([&](int64_t* maximumLength) {
94 return PEAK_C_ABI_PREFIX PEAK_StringNode_GetMaximumLength(m_backendHandle, maximumLength);
95 });
96}
97
98inline std::string StringNode::Value(NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
99{
100 auto lock = ParentNodeMap()->Lock();
101
102 return QueryStringFromCInterfaceFunction([&](char* value, size_t* valueSize) {
104 m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), value, valueSize);
105 });
106}
107
108inline void StringNode::SetValue(const std::string& value)
109{
110 auto lock = ParentNodeMap()->Lock();
111
112 CallAndCheckCInterfaceFunction([&] {
113 return PEAK_C_ABI_PREFIX PEAK_StringNode_SetValue(m_backendHandle, value.c_str(), value.size() + 1);
114 });
115}
116
117} /* namespace nodes */
118} /* namespace core */
119} /* namespace peak */
std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition peak_node.hpp:933
StringNode & operator=(StringNode &&other)=delete
std::string NodeDataType
Definition peak_string_node.hpp:38
static constexpr auto NodeType
Definition peak_string_node.hpp:37
void SetValue(const std::string &value)
Sets the given value.
Definition peak_string_node.hpp:108
~StringNode() override=default
StringNode(const StringNode &other)=delete
std::false_type NodeHasRange
Definition peak_string_node.hpp:39
StringNode & operator=(const StringNode &other)=delete
int64_t MaximumLength() const
Returns the maximum length.
Definition peak_string_node.hpp:91
std::string Value(NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Returns the value.
Definition peak_string_node.hpp:98
StringNode(StringNode &&other)=delete
The "nodes" namespace contains all GenAPI node types.
Definition peak_boolean_node.hpp:26
@ String
Definition peak_node.hpp:92
NodeCacheUsePolicy
Definition peak_common_node_enums.hpp:25
@ UseCache
Definition peak_common_node_enums.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