IDS peak genericC++ v1.17.0
Loading...
Searching...
No Matches
peak_string_node.hpp
Go to the documentation of this file.
1
6
7#pragma once
8
10
12#include <peak/dll_interface/peak_dll_interface_util.hpp>
15
16#include <type_traits>
17#include <cstdint>
18#include <string>
19
20namespace peak
21{
22namespace core
23{
24namespace nodes
25{
26
32class StringNode : public Node
33{
34public:
35 static constexpr auto NodeType = nodes::NodeType::String;
36 using NodeDataType = std::string;
37 using NodeHasRange = std::false_type;
38
39 StringNode() = delete;
40 ~StringNode() override = default;
41 StringNode(const StringNode& other) = delete;
42 StringNode& operator=(const StringNode& other) = delete;
43 StringNode(StringNode&& other) = delete;
44 StringNode& operator=(StringNode&& other) = delete;
45
56
58 PEAK_COMMON_NO_DISCARD std::string Value(
60
62 void SetValue(const std::string& value);
63
64private:
65 friend ClassCreator<StringNode>;
66 StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
67 PEAK_STRING_NODE_HANDLE m_backendHandle;
68};
69
70} /* namespace nodes */
71} /* namespace core */
72} /* namespace peak */
73
74/* Implementation */
75namespace peak
76{
77namespace core
78{
79namespace nodes
80{
81
82inline StringNode::StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
83 : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
84 return PEAK_C_ABI_PREFIX PEAK_StringNode_ToNode(stringNodeHandle, nodeHandle);
85 }),
86 parentNodeMap)
87 , m_backendHandle(stringNodeHandle)
88{}
89
90inline int64_t StringNode::MaximumLength() const
91{
92 return QueryNumericFromCInterfaceFunction<int64_t>([&](int64_t* maximumLength) {
93 return PEAK_C_ABI_PREFIX PEAK_StringNode_GetMaximumLength(m_backendHandle, maximumLength);
94 });
95}
96
97inline std::string StringNode::Value(NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
98{
99 auto lock = ParentNodeMap()->Lock();
100
101 return QueryStringFromCInterfaceFunction([&](char* value, size_t* valueSize) {
103 m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), value, valueSize);
104 });
105}
106
107inline void StringNode::SetValue(const std::string& value)
108{
109 auto lock = ParentNodeMap()->Lock();
110
111 CallAndCheckCInterfaceFunction([&] {
112 return PEAK_C_ABI_PREFIX PEAK_StringNode_SetValue(m_backendHandle, value.c_str(), value.size() + 1);
113 });
114}
115
116} /* namespace nodes */
117} /* namespace core */
118} /* namespace peak */
PEAK_COMMON_NO_DISCARD std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition peak_node.hpp:969
StringNode & operator=(StringNode &&other)=delete
std::string NodeDataType
Definition peak_string_node.hpp:36
static constexpr auto NodeType
Definition peak_string_node.hpp:35
void SetValue(const std::string &value)
Sets the given value.
Definition peak_string_node.hpp:107
~StringNode() override=default
StringNode(const StringNode &other)=delete
std::false_type NodeHasRange
Definition peak_string_node.hpp:37
StringNode & operator=(const StringNode &other)=delete
PEAK_COMMON_NO_DISCARD int64_t MaximumLength() const
Returns the maximum length.
Definition peak_string_node.hpp:90
PEAK_COMMON_NO_DISCARD std::string Value(NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Returns the value.
Definition peak_string_node.hpp:97
StringNode(StringNode &&other)=delete
NodeCacheUsePolicy
Defines how node value access should interact with the internal cache.
Definition peak_common_node_enums.hpp:36
@ String
Definition peak_node.hpp:93
@ UseCache
Definition peak_common_node_enums.hpp:38
The "nodes" namespace contains all GenAPI node types.
Definition peak_utils.hpp:31
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
struct PEAK_STRING_NODE * PEAK_STRING_NODE_HANDLE
Definition peak_backend.h:447
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition peak_backend.h:427
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:240
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_COMMON_NO_DISCARD
Definition peak_common_defines.h:89
#define PEAK_C_ABI_PREFIX
Definition peak_dll_defines.h:13