IDS peak genericC++  v1.6.2
peak_enumeration_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 <cstddef>
20 #include <cstdint>
21 #include <string>
22 #include <vector>
23 
24 
25 namespace peak
26 {
27 namespace core
28 {
29 namespace nodes
30 {
31 
36 class EnumerationNode : public Node
37 {
38 public:
39  EnumerationNode() = delete;
40  ~EnumerationNode() override = default;
41  EnumerationNode(const EnumerationNode& other) = delete;
42  EnumerationNode& operator=(const EnumerationNode& other) = delete;
43  EnumerationNode(EnumerationNode&& other) = delete;
44  EnumerationNode& operator=(EnumerationNode&& other) = delete;
45 
57  std::shared_ptr<EnumerationEntryNode> CurrentEntry(
58  NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
69  void SetCurrentEntry(const std::shared_ptr<EnumerationEntryNode>& entry);
80  void SetCurrentEntry(const std::string& symbolicValue);
91  void SetCurrentEntry(int64_t value);
105  std::shared_ptr<EnumerationEntryNode> FindEntry(const std::string& symbolicValue) const;
119  std::shared_ptr<EnumerationEntryNode> FindEntry(int64_t value) const;
129  std::vector<std::shared_ptr<EnumerationEntryNode>> Entries() const;
130 
131 private:
132  friend ClassCreator<EnumerationNode>;
133  EnumerationNode(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
134  PEAK_ENUMERATION_NODE_HANDLE m_backendHandle;
135 };
136 
137 } /* namespace nodes */
138 } /* namespace core */
139 } /* namespace peak */
140 
141 /* Implementation */
142 namespace peak
143 {
144 namespace core
145 {
146 namespace nodes
147 {
148 
150  PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
151  : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
152  return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_ToNode(enumerationNodeHandle, nodeHandle);
153  }),
154  parentNodeMap)
155  , m_backendHandle(enumerationNodeHandle)
156 {}
157 
158 inline std::shared_ptr<EnumerationEntryNode> EnumerationNode::CurrentEntry(
159  NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
160 {
161  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
162  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
164  static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), _enumerationEntryNodeHandle);
165  });
166 
167  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* _nodeHandle) {
168  return PEAK_C_ABI_PREFIX PEAK_EnumerationEntryNode_ToNode(enumerationEntryNodeHandle, _nodeHandle);
169  });
170 
171  auto nodeName = GetNodeName(nodeHandle);
172 
173  return std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName));
174 }
175 
176 inline void EnumerationNode::SetCurrentEntry(const std::shared_ptr<EnumerationEntryNode>& entry)
177 {
178  if (entry == nullptr)
179  {
180  throw InvalidArgumentException("The given entry is a nullptr!");
181  }
182 
183  CallAndCheckCInterfaceFunction([&] {
184  return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_SetCurrentEntry(m_backendHandle, entry->m_backendHandle);
185  });
186 }
187 
188 inline void EnumerationNode::SetCurrentEntry(const std::string& symbolicValue)
189 {
190  CallAndCheckCInterfaceFunction([&] {
192  m_backendHandle, symbolicValue.c_str(), symbolicValue.size() + 1);
193  });
194 }
195 
196 inline void EnumerationNode::SetCurrentEntry(int64_t value)
197 {
198  CallAndCheckCInterfaceFunction(
199  [&] { return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_SetCurrentEntryByValue(m_backendHandle, value); });
200 }
201 
202 inline std::shared_ptr<EnumerationEntryNode> EnumerationNode::FindEntry(const std::string& symbolicValue) const
203 {
204  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
205  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
207  m_backendHandle, symbolicValue.c_str(), symbolicValue.size() + 1, _enumerationEntryNodeHandle);
208  });
209 
210  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* _nodeHandle) {
211  return PEAK_C_ABI_PREFIX PEAK_EnumerationEntryNode_ToNode(enumerationEntryNodeHandle, _nodeHandle);
212  });
213 
214  auto nodeName = GetNodeName(nodeHandle);
215 
216  return std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName));
217 }
218 
219 inline std::shared_ptr<EnumerationEntryNode> EnumerationNode::FindEntry(int64_t value) const
220 {
221  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
222  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
224  m_backendHandle, value, _enumerationEntryNodeHandle);
225  });
226 
227  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* _nodeHandle) {
228  return PEAK_C_ABI_PREFIX PEAK_EnumerationEntryNode_ToNode(enumerationEntryNodeHandle, _nodeHandle);
229  });
230 
231  auto nodeName = GetNodeName(nodeHandle);
232 
233  return std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName));
234 }
235 
236 inline std::vector<std::shared_ptr<EnumerationEntryNode>> EnumerationNode::Entries() const
237 {
238  auto numEntries = QueryNumericFromCInterfaceFunction<size_t>([&](size_t* _numEntries) {
239  return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_GetNumEntries(m_backendHandle, _numEntries);
240  });
241 
242  std::vector<std::shared_ptr<EnumerationEntryNode>> entries;
243  for (size_t x = 0; x < numEntries; ++x)
244  {
245  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
246  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
248  m_backendHandle, x, _enumerationEntryNodeHandle);
249  });
250 
251  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
252  [&](PEAK_NODE_HANDLE* _nodeHandle) {
254  enumerationEntryNodeHandle, _nodeHandle);
255  });
256 
257  auto nodeName = GetNodeName(nodeHandle);
258 
259  entries.emplace_back(std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName)));
260  }
261 
262  return entries;
263 }
264 
265 } /* namespace nodes */
266 } /* namespace core */
267 } /* namespace peak */
Represents a GenAPI enumeration entry node.
Definition: peak_enumeration_entry_node.hpp:34
EnumerationNode & operator=(const EnumerationNode &other)=delete
The exception thrown for pass an invalid argument to a function.
Definition: peak_exception.hpp:73
void SetCurrentEntry(const std::shared_ptr< EnumerationEntryNode > &entry)
Sets the current entry.
Definition: peak_enumeration_node.hpp:176
PEAK_C_API PEAK_EnumerationNode_GetNumEntries(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, size_t *numEntries)
Asks the given enumeration node for its number of entries.
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
PEAK_C_API PEAK_EnumerationNode_SetCurrentEntryBySymbolicValue(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, const char *symbolicValue, size_t symbolicValueSize)
Tells the given enumeration node to set its current entry by the given symbolic value.
PEAK_C_API PEAK_EnumerationNode_SetCurrentEntry(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, PEAK_ENUMERATION_ENTRY_NODE_HANDLE enumerationEntryNodeHandle)
Tells the given enumeration node to set its current entry to the given entry.
NodeCacheUsePolicy
Definition: peak_common_node_enums.hpp:24
std::shared_ptr< EnumerationEntryNode > CurrentEntry(NodeCacheUsePolicy cacheUsePolicy=NodeCacheUsePolicy::UseCache) const
Returns the current entry.
Definition: peak_enumeration_node.hpp:158
PEAK_C_API PEAK_EnumerationNode_ToNode(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given enumeration node to a node.
struct PEAK_NODE * PEAK_NODE_HANDLE
Definition: peak_backend.h:409
struct PEAK_ENUMERATION_ENTRY_NODE * PEAK_ENUMERATION_ENTRY_NODE_HANDLE
Definition: peak_backend.h:445
struct PEAK_ENUMERATION_NODE * PEAK_ENUMERATION_NODE_HANDLE
Definition: peak_backend.h:441
std::vector< std::shared_ptr< EnumerationEntryNode > > Entries() const
Returns the entries.
Definition: peak_enumeration_node.hpp:236
std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition: peak_node.hpp:839
~EnumerationNode() override=default
PEAK_C_API PEAK_EnumerationNode_SetCurrentEntryByValue(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, int64_t value)
Tells the given enumeration node to set its current entry by the given value.
PEAK_C_API PEAK_EnumerationNode_GetEntry(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, size_t index, PEAK_ENUMERATION_ENTRY_NODE_HANDLE *enumerationEntryNodeHandle)
Asks the given enumeration node for the entry with the given index.
PEAK_C_API PEAK_EnumerationEntryNode_ToNode(PEAK_ENUMERATION_ENTRY_NODE_HANDLE enumerationEntryNodeHandle, PEAK_NODE_HANDLE *nodeHandle)
Casts the given enumeration entry node to a node.
#define PEAK_C_ABI_PREFIX
Definition: peak_dll_defines.h:16
PEAK_C_API PEAK_EnumerationNode_FindEntryBySymbolicValue(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, const char *symbolicValue, size_t symbolicValueSize, PEAK_ENUMERATION_ENTRY_NODE_HANDLE *enumerationEntryNodeHandle)
Tells the given enumeration node to find a entry with the given symbolic value.
PEAK_C_API PEAK_EnumerationNode_GetCurrentEntry(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, PEAK_NODE_CACHE_USE_POLICY cacheUsePolicy, PEAK_ENUMERATION_ENTRY_NODE_HANDLE *enumerationEntryNodeHandle)
Asks the given enumeration node for its current entry.
PEAK_C_API PEAK_EnumerationNode_FindEntryByValue(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, int64_t value, PEAK_ENUMERATION_ENTRY_NODE_HANDLE *enumerationEntryNodeHandle)
Tells the given enumeration node to find a entry with the given value.
Represents a GenAPI node.
Definition: peak_node.hpp:121
std::string GetNodeName(PEAK_NODE_HANDLE nodeHandle)
Definition: peak_node.hpp:552
std::shared_ptr< EnumerationEntryNode > FindEntry(const std::string &symbolicValue) const
Tries to find a entry with the given symbolic value.
Definition: peak_enumeration_node.hpp:202
Represents a GenAPI enumeration node.
Definition: peak_enumeration_node.hpp:36