IDS peak genericC++  v1.5.0
peak_string_node.hpp
Go to the documentation of this file.
1 
11 #pragma once
12 
13 
15 #include <peak/dll_interface/peak_dll_interface_util.hpp>
18 
19 #include <cstdint>
20 #include <string>
21 
22 namespace peak
23 {
24 namespace core
25 {
26 namespace nodes
27 {
28 
33 class StringNode : public Node
34 {
35 public:
36  StringNode() = delete;
37  ~StringNode() override = default;
38  StringNode(const StringNode& other) = delete;
39  StringNode& operator=(const StringNode& other) = delete;
40  StringNode(StringNode&& other) = delete;
41  StringNode& operator=(StringNode&& other) = delete;
42 
52  int64_t MaximumLength() const;
53 
55  std::string Value(NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
57  void SetValue(const std::string& value);
58 
59 private:
60  friend ClassCreator<StringNode>;
61  StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
62  PEAK_STRING_NODE_HANDLE m_backendHandle;
63 };
64 
65 } /* namespace nodes */
66 } /* namespace core */
67 } /* namespace peak */
68 
69 /* Implementation */
70 namespace peak
71 {
72 namespace core
73 {
74 namespace nodes
75 {
76 
77 inline StringNode::StringNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
78  : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
79  return PEAK_C_ABI_PREFIX PEAK_StringNode_ToNode(stringNodeHandle, nodeHandle);
80  }),
81  parentNodeMap)
82  , m_backendHandle(stringNodeHandle)
83 {}
84 
85 inline int64_t StringNode::MaximumLength() const
86 {
87  return QueryNumericFromCInterfaceFunction<int64_t>([&](int64_t* maximumLength) {
88  return PEAK_C_ABI_PREFIX PEAK_StringNode_GetMaximumLength(m_backendHandle, maximumLength);
89  });
90 }
91 
92 inline std::string StringNode::Value(NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
93 {
94  auto lock = ParentNodeMap()->Lock();
95 
96  return QueryStringFromCInterfaceFunction([&](char* value, size_t* valueSize) {
98  m_backendHandle, static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), value, valueSize);
99  });
100 }
101 
102 inline void StringNode::SetValue(const std::string& value)
103 {
104  auto lock = ParentNodeMap()->Lock();
105 
106  CallAndCheckCInterfaceFunction([&] {
107  return PEAK_C_ABI_PREFIX PEAK_StringNode_SetValue(m_backendHandle, value.c_str(), value.size() + 1);
108  });
109 }
110 
111 } /* namespace nodes */
112 } /* namespace core */
113 } /* namespace peak */
StringNode & operator=(const StringNode &other)=delete
void SetValue(const std::string &value)
Sets the given value.
Definition: peak_string_node.hpp:102
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.
int64_t MaximumLength() const
Returns the maximum length.
Definition: peak_string_node.hpp:85
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
NodeCacheUsePolicy
Definition: peak_common_node_enums.hpp:24
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition: peak_backend.h:409
std::string Value(NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Returns the value.
Definition: peak_string_node.hpp:92
PEAK_C_API PEAK_StringNode_ToNode(PEAK_STRING_NODE_HANDLE stringNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given string node to a node.
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.
struct PEAK_STRING_NODE * PEAK_STRING_NODE_HANDLE
Definition: peak_backend.h:429
std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition: peak_node.hpp:839
Represents a GenAPI string node.
Definition: peak_string_node.hpp:33
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
Represents a GenAPI node.
Definition: peak_node.hpp:121
PEAK_C_API PEAK_StringNode_GetMaximumLength(PEAK_STRING_NODE_HANDLE stringNodeHandle, int64_t *maximumLength)
Asks the given string node for its maximum length.
~StringNode() override=default