CVB++ 15.0
Loading...
Searching...
No Matches
detail_node_map.hpp
1#pragma once
2
3#include <memory>
4#include <stdexcept>
5#include <vector>
6
7#include "../../_cexports/c_gev_server.h"
8
9#include "../../global.hpp"
10
11#include "../_decl/decl_node.hpp"
12#include "../_decl/decl_node_map.hpp"
13#include "../_decl/decl_server.hpp"
14
15#include "../../_decl/decl_device.hpp"
16
17#include "../category_node.hpp"
18#include "../value_node.hpp"
19
20namespace Cvb
21{
22 CVB_BEGIN_INLINE_NS
23 namespace GevServer
24 {
25 inline std::map<String, NodePtr> NodeMap::Nodes() const
26 {
27 std::map<String, NodePtr> nodes;
28 for (const auto &entry : nodes_)
29 nodes[entry.first] = Node(entry.first);
30 return nodes;
31 }
32
33 inline void NodeMap::FillNodeKeys()
34 {
35 std::size_t numNodes = 0;
36 auto resultNum = CVB_CALL_CAPI(GSNodeCount(Handle(), numNodes));
37 if (resultNum < 0)
38 std::rethrow_exception(CvbException::FromCvbResult(resultNum, "failed to get node count"));
39
40 for (std::size_t i = 0; i < numNodes; ++i)
41 {
42 size_t nameLength = 0;
43 auto resultNameLength = CVB_CALL_CAPI(GSNodeList(Handle(), i, nullptr, nameLength));
44 if (resultNameLength < 0)
45 std::rethrow_exception(CvbException::FromCvbResult(resultNameLength, "failed to get node name length"));
46
47 std::vector<char> buffer(static_cast<size_t>(nameLength));
48 auto resultBuffer = CVB_CALL_CAPI(GSNodeList(Handle(), i, &buffer[0], nameLength));
49 if (resultBuffer < 0)
50 std::rethrow_exception(CvbException::FromCvbResult(resultBuffer, "failed to get node name"));
51 String keyString(buffer.begin(), buffer.end() - 1);
52
53 nodes_[keyString] = std::shared_ptr<class Node>();
54 }
55 }
56 inline void NodeMap::AddNode(const String &key, const NodePtr &value, const NodeList &kind)
57 {
58 if (key.empty())
59 throw std::runtime_error("key must not be empty");
60 if (!value)
61 throw std::runtime_error("node must not be null");
62 auto name = value->NameOnly();
63 if (key != name)
64 throw std::runtime_error("key and value->NameOnly() must be equal");
65
66 NativeCall([&]() {
67 return CExports::GSNAddNodeExTyped(value->Handle(), static_cast<CExports::TGSNodeList>(kind), key.data(),
68 value->Handle());
69 });
70
71 // add node map to item
72 value->SetNodeMap(std::const_pointer_cast<NodeMap>(shared_from_this()));
73
74 nodes_[key] = value;
75 }
76
77 } // namespace GevServer
78 CVB_END_INLINE_NS
79} // namespace Cvb
Basic GevServer node for device feature access.
Definition decl_node.hpp:34
std::map< String, NodePtr > Nodes() const
Get a dictionary contain all nodes of this node map.
Definition detail_node_map.hpp:105
Describes a GenICam Pixel Format Naming Convention (PFNC) compatible image memory buffer with possibl...
Definition decl_int_swiss_knife_node.hpp:11
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition gevserver.hpp:32
@ String
Node is a string node (no reg).
Definition gevserver.hpp:168
NodeList
Node access.
Definition gevserver.hpp:249
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17