aboutsummaryrefslogtreecommitdiffstats
path: root/test/mocks/pnfsimulator/netconfsimulator/netopeer-change-saver-native/sysrepo/Tree.hpp
blob: 31f3abd475bb30296f0478a0192780588a735dba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**
 * @file Trees.h
 * @author Mislav Novakovic <mislav.novakovic@sartura.hr>
 * @brief Sysrepo class header for C header trees.h.
 *
 * @copyright
 * Copyright 2016 Deutsche Telekom AG.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef TREE_H
#define TREE_H

#include "Sysrepo.hpp"
#include "Struct.hpp"

extern "C" {
#include "../sysrepo.h"
#include "../sysrepo/trees.h"
}

namespace sysrepo {

/**
 * @defgroup classes C++/Python
 * @{
 */

/**
 * @brief Class for wrapping sr_node_t.
 * @class Tree
 */
class Tree
{
public:
    /** Constructor for an empty [sr_node_t](@ref sr_node_t).*/
    Tree();
    /** Wrapper for [sr_new_tree](@ref sr_new_tree).*/
    Tree(const char *root_name, const char *root_module_name);
    /** Wrapper for [sr_node_t](@ref sr_node_t).*/
    Tree(sr_node_t *tree, S_Deleter deleter);
    /** Wrapper for [sr_dup_tree](@ref sr_dup_tree).*/
    S_Tree dup();
    /** Get the node value.*/
    S_Tree node();
    /** Getter for name.*/
    char *name() {return _node->name;};
    /** Getter for type.*/
    sr_type_t type() {return _node->type;};
    /** Getter for dflt.*/
    bool dflt() {return _node->dflt;};
    /** Getter for data.*/
    S_Data data() {S_Data data(new Data(_node->data, _node->type, _deleter)); return data;};
    /** Getter for module_name.*/
    char *module_name() {return _node->module_name;};
    /** Getter for parent.*/
    S_Tree parent();
    /** Getter for next.*/
    S_Tree next();
    /** Getter for prev.*/
    S_Tree prev();
    /** Getter for first_child.*/
    S_Tree first_child();
    /** Getter for last_child.*/
    S_Tree last_child();
    /** Wrapper for [sr_print_tree_mem](@ref sr_print_tree_mem).*/
    std::string to_string(int depth_limit);
    /** Wrapper for [sr_print_val_mem](@ref sr_print_val_mem).*/
    std::string value_to_string();
    /** Wrapper for [sr_node_set_name](@ref sr_node_set_name).*/
    void set_name(const char *name);
    /** Wrapper for [sr_node_set_module](@ref sr_node_set_module).*/
    void set_module(const char *module_name);
    /** Wrapper for [sr_node_set_str_data](@ref sr_node_set_str_data).*/
    void set_str_data(sr_type_t type, const char *string_val);
    /** Wrapper for [sr_node_add_child](@ref sr_node_add_child).*/
    void add_child(const char *child_name, const char *child_module_name, S_Tree child);
    /** Setter for string value, type can be SR_STRING_T, SR_BINARY_T, SR_BITS_T, SR_ENUM_T,
     * SR_IDENTITYREF_T and SR_INSTANCEID_T.*/
    void set(const char *val, sr_type_t type = SR_STRING_T);
    /** Setter for bool value.*/
    void set(bool bool_val, sr_type_t type = SR_BOOL_T);
    /** Setter for decimal64 value.*/
    void set(double decimal64_val);
    /** Setter for int8 value, C++ only.*/
    void set(int8_t int8_val, sr_type_t type);
    /** Setter for int16 value, C++ only.*/
    void set(int16_t int16_val, sr_type_t type);
    /** Setter for int32 value, C++ only.*/
    void set(int32_t int32_val, sr_type_t type);
    /** Setter for int64 value, type can be SR_INT8_T, SR_INT16_T, SR_INT32_T,
     * SR_INT64_T, SR_UINT8_T, SR_UINT16_T and SR_UINT32_T,*/
    void set(int64_t int64_val, sr_type_t type);
    /** Setter for uint8 value, C++ only.*/
    void set(uint8_t uint8_val, sr_type_t type);
    /** Setter for uint16 value, C++ only.*/
    void set(uint16_t uint16_val, sr_type_t type);
    /** Setter for uint32 value, C++ only.*/
    void set(uint32_t uint32_val, sr_type_t type);
    /** Setter for uint64 value, C++ only.*/
    void set(uint64_t uint64_val, sr_type_t type);
    ~Tree();

    friend class Session;
    friend class Subscribe;

private:
    sr_node_t *_node;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_node_t array.
 * @class Trees
 */
class Trees
{
public:
    /** Constructor for an empty [sr_node_t](@ref sr_node_t) array.*/
    Trees();
    /** Wrapper for [sr_node_t](@ref sr_node_t) array, create n-array.*/
    Trees(size_t n);
    /** Wrapper for [sr_node_t](@ref sr_node_t) array, internal use only.*/
    Trees(sr_node_t **trees, size_t *cnt, S_Deleter deleter = nullptr);
    /** Wrapper for [sr_node_t](@ref sr_node_t) array, internal use only.*/
    Trees(const sr_node_t *trees, const size_t n, S_Deleter deleter = nullptr);
    /** Getter for [sr_node_t](@ref sr_node_t), get the n-th element in array.*/
    S_Tree tree(size_t n);
    /** Wrapper for [sr_dup_trees](@ref sr_dup_trees) */
    S_Trees dup();
    /** Getter for array size */
    size_t tree_cnt() {return _cnt;};
    ~Trees();

    friend class Session;
    friend class Subscribe;

private:
    size_t _cnt;
    sr_node_t *_trees;
    S_Deleter _deleter;
};

/**
 * @brief Class for wrapping sr_node_t in callbacks.
 * @class Trees_Holder
 */
class Trees_Holder
{
public:
    /** Wrapper for [sr_node_t](@ref sr_node_t) array, used only in callbacks.*/
    Trees_Holder(sr_node_t **trees, size_t *cnt);
    /** Create [sr_node_t](@ref sr_node_t) array of n size.*/
    S_Trees allocate(size_t n);
    ~Trees_Holder();

private:
    size_t *p_cnt;
    sr_node_t **p_trees;
    bool _allocate;
};

/**@} */
}
#endif