CVB++ 15.0
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 NodeMap::NodeMap(const ServerPtr &server) noexcept
26 : server_(server)
27 {
28 FillNodeKeys();
29 }
30
31 inline std::map<String, NodePtr> NodeMap::Nodes() const
32 {
33 std::map<String, NodePtr> nodes;
34 for (const auto &entry : nodes_)
35 nodes[entry.first] = Node(entry.first);
36 return nodes;
37 }
38
39 inline void NodeMap::FillNodeKeys()
40 {
41 std::size_t numNodes = 0;
42 auto resultNum = CVB_CALL_CAPI(GSNodeCount(Handle(), numNodes));
43 if (resultNum < 0)
44 std::rethrow_exception(CvbException::FromCvbResult(resultNum, "failed to get node count"));
45
46 for (std::size_t i = 0; i < numNodes; ++i)
47 {
48 size_t nameLength = 0;
49 auto resultNameLength = CVB_CALL_CAPI(GSNodeList(Handle(), i, nullptr, nameLength));
50 if (resultNameLength < 0)
51 std::rethrow_exception(CvbException::FromCvbResult(resultNameLength, "failed to get node name length"));
52
53 std::vector<char> buffer(static_cast<size_t>(nameLength));
54 auto resultBuffer = CVB_CALL_CAPI(GSNodeList(Handle(), i, &buffer[0], nameLength));
55 if (resultBuffer < 0)
56 std::rethrow_exception(CvbException::FromCvbResult(resultBuffer, "failed to get node name"));
57 String keyString(buffer.begin(), buffer.end() - 1);
58
59 nodes_[keyString] = std::shared_ptr<class Node>();
60 }
61 }
62 inline void NodeMap::AddNode(const String &key, const NodePtr &value, const NodeList &kind)
63 {
64 if (key.empty())
65 throw std::runtime_error("key must not be empty");
66 if (!value)
67 throw std::runtime_error("node must not be null");
68 auto name = value->NameOnly();
69 if (key != name)
70 throw std::runtime_error("key and value->NameOnly() must be equal");
71
72 NativeCall([&]() {
73 return CExports::GSNAddNodeExTyped(value->Handle(), static_cast<CExports::TGSNodeList>(kind), key.data(),
74 value->Handle());
75 });
76
77 // add node map to item
78 value->SetNodeMap(std::const_pointer_cast<NodeMap>(shared_from_this()));
79
80 nodes_[key] = value;
81 }
82
83 } // namespace GevServer
84 CVB_END_INLINE_NS
85} // 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
Namespace for GevServer based device configuration.
Definition decl_int_swiss_knife_node.hpp:11
std::shared_ptr< Node > NodePtr
Convenience shared pointer for Node.
Definition gevserver.hpp:41
std::shared_ptr< Server > ServerPtr
Convenience shared pointer for GevServer.
Definition gevserver.hpp:37
@ String
Node is a string node (no reg).
Definition gevserver.hpp:177
NodeList
Node access.
Definition gevserver.hpp:258
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17