IDS peak genericC++  v1.7.0
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 
58  std::shared_ptr<EnumerationEntryNode> CurrentEntry(
59  NodeCacheUsePolicy cacheUsePolicy = NodeCacheUsePolicy::UseCache) const;
60 
72  void SetCurrentEntry(const std::shared_ptr<EnumerationEntryNode>& entry);
73 
85  void SetCurrentEntry(const std::string& symbolicValue);
86 
98  void SetCurrentEntry(int64_t value);
99 
113  std::shared_ptr<EnumerationEntryNode> FindEntry(const std::string& symbolicValue) const;
114 
128  std::shared_ptr<EnumerationEntryNode> FindEntry(int64_t value) const;
129 
139  std::vector<std::shared_ptr<EnumerationEntryNode>> Entries() const;
140 
141 private:
142  friend ClassCreator<EnumerationNode>;
143  EnumerationNode(PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap);
144  PEAK_ENUMERATION_NODE_HANDLE m_backendHandle;
145 };
146 
147 } /* namespace nodes */
148 } /* namespace core */
149 } /* namespace peak */
150 
151 /* Implementation */
152 namespace peak
153 {
154 namespace core
155 {
156 namespace nodes
157 {
158 
160  PEAK_ENUMERATION_NODE_HANDLE enumerationNodeHandle, const std::weak_ptr<NodeMap>& parentNodeMap)
161  : Node(QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* nodeHandle) {
162  return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_ToNode(enumerationNodeHandle, nodeHandle);
163  }),
164  parentNodeMap)
165  , m_backendHandle(enumerationNodeHandle)
166 {}
167 
168 inline std::shared_ptr<EnumerationEntryNode> EnumerationNode::CurrentEntry(
169  NodeCacheUsePolicy cacheUsePolicy /* = NodeCacheUsePolicy::UseCache */) const
170 {
171  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
172  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
174  static_cast<PEAK_NODE_CACHE_USE_POLICY>(cacheUsePolicy), _enumerationEntryNodeHandle);
175  });
176 
177  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* _nodeHandle) {
178  return PEAK_C_ABI_PREFIX PEAK_EnumerationEntryNode_ToNode(enumerationEntryNodeHandle, _nodeHandle);
179  });
180 
181  auto nodeName = GetNodeName(nodeHandle);
182 
183  return std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName));
184 }
185 
186 inline void EnumerationNode::SetCurrentEntry(const std::shared_ptr<EnumerationEntryNode>& entry)
187 {
188  if (entry == nullptr)
189  {
190  throw InvalidArgumentException("The given entry is a nullptr!");
191  }
192 
193  CallAndCheckCInterfaceFunction([&] {
194  return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_SetCurrentEntry(m_backendHandle, entry->m_backendHandle);
195  });
196 }
197 
198 inline void EnumerationNode::SetCurrentEntry(const std::string& symbolicValue)
199 {
200  CallAndCheckCInterfaceFunction([&] {
202  m_backendHandle, symbolicValue.c_str(), symbolicValue.size() + 1);
203  });
204 }
205 
206 inline void EnumerationNode::SetCurrentEntry(int64_t value)
207 {
208  CallAndCheckCInterfaceFunction(
209  [&] { return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_SetCurrentEntryByValue(m_backendHandle, value); });
210 }
211 
212 inline std::shared_ptr<EnumerationEntryNode> EnumerationNode::FindEntry(const std::string& symbolicValue) const
213 {
214  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
215  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
217  m_backendHandle, symbolicValue.c_str(), symbolicValue.size() + 1, _enumerationEntryNodeHandle);
218  });
219 
220  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* _nodeHandle) {
221  return PEAK_C_ABI_PREFIX PEAK_EnumerationEntryNode_ToNode(enumerationEntryNodeHandle, _nodeHandle);
222  });
223 
224  auto nodeName = GetNodeName(nodeHandle);
225 
226  return std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName));
227 }
228 
229 inline std::shared_ptr<EnumerationEntryNode> EnumerationNode::FindEntry(int64_t value) const
230 {
231  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
232  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
234  m_backendHandle, value, _enumerationEntryNodeHandle);
235  });
236 
237  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>([&](PEAK_NODE_HANDLE* _nodeHandle) {
238  return PEAK_C_ABI_PREFIX PEAK_EnumerationEntryNode_ToNode(enumerationEntryNodeHandle, _nodeHandle);
239  });
240 
241  auto nodeName = GetNodeName(nodeHandle);
242 
243  return std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName));
244 }
245 
246 inline std::vector<std::shared_ptr<EnumerationEntryNode>> EnumerationNode::Entries() const
247 {
248  auto numEntries = QueryNumericFromCInterfaceFunction<size_t>([&](size_t* _numEntries) {
249  return PEAK_C_ABI_PREFIX PEAK_EnumerationNode_GetNumEntries(m_backendHandle, _numEntries);
250  });
251 
252  std::vector<std::shared_ptr<EnumerationEntryNode>> entries;
253  for (size_t x = 0; x < numEntries; ++x)
254  {
255  auto enumerationEntryNodeHandle = QueryNumericFromCInterfaceFunction<PEAK_ENUMERATION_ENTRY_NODE_HANDLE>(
256  [&](PEAK_ENUMERATION_ENTRY_NODE_HANDLE* _enumerationEntryNodeHandle) {
258  m_backendHandle, x, _enumerationEntryNodeHandle);
259  });
260 
261  auto nodeHandle = QueryNumericFromCInterfaceFunction<PEAK_NODE_HANDLE>(
262  [&](PEAK_NODE_HANDLE* _nodeHandle) {
264  enumerationEntryNodeHandle, _nodeHandle);
265  });
266 
267  auto nodeName = GetNodeName(nodeHandle);
268 
269  entries.emplace_back(std::dynamic_pointer_cast<EnumerationEntryNode>(ParentNodeMap()->FindNode(nodeName)));
270  }
271 
272  return entries;
273 }
274 
275 } /* namespace nodes */
276 } /* namespace core */
277 } /* 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:186
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:168
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:411
struct PEAK_ENUMERATION_ENTRY_NODE * PEAK_ENUMERATION_ENTRY_NODE_HANDLE
Definition: peak_backend.h:447
struct PEAK_ENUMERATION_NODE * PEAK_ENUMERATION_NODE_HANDLE
Definition: peak_backend.h:443
std::vector< std::shared_ptr< EnumerationEntryNode > > Entries() const
Returns the entries.
Definition: peak_enumeration_node.hpp:246
std::shared_ptr< NodeMap > ParentNodeMap() const
Returns the parent node map.
Definition: peak_node.hpp:867
~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:580
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:212
Represents a GenAPI enumeration node.
Definition: peak_enumeration_node.hpp:36