sysrepo  1.4.70
YANG datastore
Struct.hpp
Go to the documentation of this file.
1 
23 #ifndef STRUCT_H
24 #define STRUCT_H
25 
26 #include <iostream>
27 #include <memory>
28 
29 #include "Sysrepo.hpp"
30 #include "Internal.hpp"
31 #include <libyang/Tree_Data.hpp>
32 
33 #include "sysrepo.h"
34 
35 namespace sysrepo {
36 
46 class Data
47 {
48 public:
50  Data(sr_data_t data, sr_type_t type, S_Deleter deleter);
51  ~Data();
53  char *get_binary() const;
55  char *get_bits() const;
57  bool get_bool() const;
59  double get_decimal64() const;
61  char *get_enum() const;
63  char *get_identityref() const;
65  char *get_instanceid() const;
67  int8_t get_int8() const;
69  int16_t get_int16() const;
71  int32_t get_int32() const;
73  int64_t get_int64() const;
75  char *get_string() const;
77  uint8_t get_uint8() const;
79  uint16_t get_uint16() const;
81  uint32_t get_uint32() const;
83  uint64_t get_uint64() const;
84 
85 private:
86  sr_data_t _d;
87  sr_type_t _t;
88  S_Deleter _deleter;
89 };
90 
95 class Val
96 {
97 public:
99  Val();
101  Val(sr_val_t *val, S_Deleter deleter);
104  Val(const char *val, sr_type_t type = SR_STRING_T);
106  explicit Val(bool bool_val, sr_type_t type = SR_BOOL_T);
108  explicit Val(double decimal64_val);
110  explicit Val(int8_t int8_val);
112  explicit Val(int16_t int16_val);
114  explicit Val(int32_t int32_val);
117  Val(int64_t int64_val, sr_type_t type = SR_INT64_T);
119  explicit Val(uint8_t uint8_val);
121  explicit Val(uint16_t uint16_val);
123  explicit Val(uint32_t uint32_val);
125  explicit Val(uint64_t uint64_val);
126  ~Val();
129  void set(const char *xpath, const char *val, sr_type_t type = SR_STRING_T);
131  void set(const char *xpath, bool bool_val, sr_type_t type = SR_BOOL_T);
133  void set(const char *xpath, double decimal64_val);
135  void set(const char *xpath, int8_t int8_val);
137  void set(const char *xpath, int16_t int16_val);
139  void set(const char *xpath, int32_t int32_val);
142  void set(const char *xpath, int64_t int64_val, sr_type_t type = SR_INT64_T);
144  void set(const char *xpath, uint8_t uint8_val);
146  void set(const char *xpath, uint16_t uint16_val);
148  void set(const char *xpath, uint32_t uint32_val);
150  void set(const char *xpath, uint64_t uint64_val);
152  char *xpath();
154  void xpath_set(const char *xpath);
158  bool dflt();
160  void dflt_set(bool data);
164  bool empty();
166  std::string to_string();
168  std::string val_to_string();
171 
172  friend class Session;
173  friend class Subscribe;
174 
175 private:
176  sr_val_t *_val;
177  S_Deleter _deleter;
178 };
179 
184 class Vals
185 {
186 public:
188  Vals(const sr_val_t *vals, const size_t cnt, S_Deleter deleter = nullptr);
190  Vals(sr_val_t **vals, size_t *cnt, S_Deleter deleter = nullptr);
192  Vals(size_t cnt);
194  Vals();
195  ~Vals();
197  S_Val val(size_t n);
199  size_t val_cnt() {return _cnt;};
203  sr_val_t* reallocate(size_t n);
204 
205  friend class Session;
206  friend class Subscribe;
207 
208 private:
209  size_t _cnt;
210  sr_val_t *_vals;
211  S_Deleter _deleter;
212 };
213 
219 {
220 public:
222  Vals_Holder(sr_val_t **vals, size_t *cnt);
224  S_Vals allocate(size_t n);
226  S_Vals reallocate(size_t n);
227  size_t val_cnt(void) { return *p_cnt; }
228  S_Vals vals(void);
230 
231 private:
232  size_t *p_cnt;
233  sr_val_t **p_vals;
234  S_Vals p_Vals;
235  bool _allocate;
236 };
237 
243 {
244 public:
249  sr_change_iter_t *iter() {return _iter;};
250 
251 private:
252  sr_change_iter_t *_iter;
253 };
254 
259 class Errors
260 {
261 public:
266  sr_error_t error_code() {return _info->err_code;};
268  const char *message(size_t idx) {return _info->err[idx].message;};
270  const char *xpath(size_t idx) {return _info->err[idx].xpath;};
272  size_t error_cnt() {return _info->err_count;};
273 
274  friend class Session;
275 
276 private:
277  const sr_error_info_t *_info;
278 };
279 
285 {
286 
287 public:
289  Iter_Change(sr_change_iter_t *iter = nullptr);
291 
292  friend class Session;
293 
294 private:
295  sr_change_iter_t *_iter;
296 };
297 
302 class Change
303 {
304 public:
309  sr_change_oper_t oper() {return _oper;};
314 
315  friend class Session;
316 
317 private:
318  sr_change_oper_t _oper;
319  sr_val_t *_new;
320  sr_val_t *_old;
321  S_Deleter _deleter_new;
322  S_Deleter _deleter_old;
323 };
324 
330 {
331 public:
336  sr_change_oper_t oper() {return _oper;};
338  libyang::S_Data_Node node();
340  const char *prev_value() {return _prev_value;};
342  const char *prev_list() {return _prev_list;};
344  bool prev_dflt() {return _prev_dflt;};
345 
346  friend class Session;
347 
348 private:
349  sr_change_oper_t _oper;
350  const struct lyd_node *_node;
351  const char *_prev_value;
352  const char *_prev_list;
353  bool _prev_dflt;
354 };
355 
358 }
359 
360 #endif
sysrepo::S_Deleter
std::shared_ptr< Deleter > S_Deleter
Definition: Sysrepo.hpp:73
sysrepo.h
public API sysrepo header
Internal.hpp
Sysrepo class header for internal C++ classes.
sysrepo::Data::get_int32
int32_t get_int32() const
sysrepo::Data::~Data
~Data()
sysrepo::Data::get_uint16
uint16_t get_uint16() const
sysrepo::Val::Val
Val(uint64_t uint64_val)
sysrepo::Vals_Holder::vals
S_Vals vals(void)
sysrepo::Errors::~Errors
~Errors()
sysrepo::Data::get_binary
char * get_binary() const
sysrepo::Val::set
void set(const char *xpath, bool bool_val, sr_type_t type=SR_BOOL_T)
sysrepo::Val::set
void set(const char *xpath, int16_t int16_val)
sysrepo::Change::Change
Change()
SR_INT64_T
@ SR_INT64_T
Definition: sysrepo.h:630
sr_error_info_msg_s::message
char * message
Definition: sysrepo.h:209
sysrepo::Data::Data
Data(sr_data_t data, sr_type_t type, S_Deleter deleter)
sysrepo::Errors::Errors
Errors()
sysrepo::Errors::error_cnt
size_t error_cnt()
Definition: Struct.hpp:272
sysrepo::Val::Val
Val(int16_t int16_val)
sysrepo
Definition: Connection.hpp:35
sysrepo::Change
Class for wrapping sr_change_oper_t.
Definition: Struct.hpp:303
sysrepo::Val::data
S_Data data()
sysrepo::Val::Val
Val(const char *val, sr_type_t type=SR_STRING_T)
sysrepo::Val::set
void set(const char *xpath, double decimal64_val)
sysrepo::Change_Iter
Class for wrapping sr_change_iter_t.
Definition: Struct.hpp:243
sysrepo::Tree_Change
Class for wrapping tree sr_change_oper_t.
Definition: Struct.hpp:330
sysrepo::Val::set
void set(const char *xpath, uint64_t uint64_val)
sysrepo::Vals::Vals
Vals()
sysrepo::Change::oper
sr_change_oper_t oper()
Definition: Struct.hpp:309
sysrepo::Iter_Change
Class for wrapping sr_change_iter_t.
Definition: Struct.hpp:285
sysrepo::Val::Val
Val(uint8_t uint8_val)
sysrepo::Session
Class for wrapping sr_session_ctx_t.
Definition: Session.hpp:53
sr_type_t
enum sr_type_e sr_type_t
Possible types of a data element stored in the sysrepo datastore.
sysrepo::Tree_Change::~Tree_Change
~Tree_Change()
sysrepo::Val::Val
Val(sr_val_t *val, S_Deleter deleter)
sysrepo::Data::get_int16
int16_t get_int16() const
sysrepo::Val::set
void set(const char *xpath, uint16_t uint16_val)
sysrepo::Data::get_int8
int8_t get_int8() const
sysrepo::Iter_Change::Iter_Change
Iter_Change(sr_change_iter_t *iter=nullptr)
sysrepo::Val::set
void set(const char *xpath, const char *val, sr_type_t type=SR_STRING_T)
sysrepo::Vals
Class for wrapping sr_val_t array.
Definition: Struct.hpp:185
sysrepo::Val::Val
Val(int64_t int64_val, sr_type_t type=SR_INT64_T)
Sysrepo.hpp
Sysrepo Sysrepo class header.
sysrepo::Vals::Vals
Vals(const sr_val_t *vals, const size_t cnt, S_Deleter deleter=nullptr)
sysrepo::Data::get_instanceid
char * get_instanceid() const
sysrepo::Tree_Change::prev_value
const char * prev_value()
Definition: Struct.hpp:340
sysrepo::Errors::xpath
const char * xpath(size_t idx)
Definition: Struct.hpp:270
sysrepo::Val::dup
S_Val dup()
sysrepo::Tree_Change::prev_list
const char * prev_list()
Definition: Struct.hpp:342
sysrepo::Val::type
sr_type_t type()
sysrepo::Vals::val
S_Val val(size_t n)
sysrepo::S_Val
std::shared_ptr< Val > S_Val
Definition: Sysrepo.hpp:65
sysrepo::Tree_Change::Tree_Change
Tree_Change()
sysrepo::Data::get_bits
char * get_bits() const
sysrepo::Vals::reallocate
sr_val_t * reallocate(size_t n)
sysrepo::Tree_Change::oper
sr_change_oper_t oper()
Definition: Struct.hpp:336
sr_change_oper_t
enum sr_change_oper_e sr_change_oper_t
Type of the operation made on an item, used by changeset retrieval in sr_get_change_next.
sysrepo::Change_Iter::Change_Iter
Change_Iter(sr_change_iter_t *iter=nullptr)
sr_error_info_s::err
sr_error_info_msg_t * err
Definition: sysrepo.h:218
sysrepo::Data::get_enum
char * get_enum() const
SR_STRING_T
@ SR_STRING_T
Definition: sysrepo.h:631
sysrepo::Val::val_to_string
std::string val_to_string()
sysrepo::Data::get_uint32
uint32_t get_uint32() const
sysrepo::Vals_Holder::Vals_Holder
Vals_Holder(sr_val_t **vals, size_t *cnt)
sysrepo::Val::Val
Val(int32_t int32_val)
sysrepo::Tree_Change::prev_dflt
bool prev_dflt()
Definition: Struct.hpp:344
sysrepo::Change_Iter::iter
sr_change_iter_t * iter()
Definition: Struct.hpp:249
sysrepo::Iter_Change::~Iter_Change
~Iter_Change()
sysrepo::Val::xpath_set
void xpath_set(const char *xpath)
sr_data_u
Data of an element (if applicable), properly set according to the type.
Definition: sysrepo.h:643
sysrepo::Val::Val
Val(bool bool_val, sr_type_t type=SR_BOOL_T)
sysrepo::Val
Class for wrapping sr_val_t.
Definition: Struct.hpp:96
sysrepo::Errors::error_code
sr_error_t error_code()
Definition: Struct.hpp:266
sysrepo::Vals::~Vals
~Vals()
sysrepo::Vals_Holder
Class for wrapping sr_val_t in callbacks.
Definition: Struct.hpp:219
sysrepo::Data
Class for wrapping sr_data_t.
Definition: Struct.hpp:47
sr_change_iter_t
struct sr_change_iter_s sr_change_iter_t
Iterator used for retrieval of a changeset using sr_get_changes_iter call.
Definition: sysrepo.h:1303
sysrepo::S_Data
std::shared_ptr< Data > S_Data
Definition: Sysrepo.hpp:64
sysrepo::Val::Val
Val()
sysrepo::Val::set
void set(const char *xpath, int8_t int8_val)
sysrepo::Vals_Holder::allocate
S_Vals allocate(size_t n)
sysrepo::Val::set
void set(const char *xpath, int64_t int64_val, sr_type_t type=SR_INT64_T)
sysrepo::Data::get_int64
int64_t get_int64() const
sysrepo::Val::set
void set(const char *xpath, uint32_t uint32_val)
sysrepo::Change::old_val
S_Val old_val()
sysrepo::Vals::val_cnt
size_t val_cnt()
Definition: Struct.hpp:199
sysrepo::S_Vals
std::shared_ptr< Vals > S_Vals
Definition: Sysrepo.hpp:67
sysrepo::Val::Val
Val(int8_t int8_val)
sysrepo::Vals::dup
S_Vals dup()
sysrepo::Vals::Vals
Vals(size_t cnt)
sysrepo::Val::dflt_set
void dflt_set(bool data)
sysrepo::Val::xpath
char * xpath()
sysrepo::Data::get_uint8
uint8_t get_uint8() const
sr_error_info_msg_s::xpath
char * xpath
Definition: sysrepo.h:210
sysrepo::Val::set
void set(const char *xpath, int32_t int32_val)
sr_error_t
enum sr_error_e sr_error_t
Sysrepo error codes.
sr_error_info_s
Detailed sysrepo session error information.
Definition: sysrepo.h:216
sysrepo::Val::set
void set(const char *xpath, uint8_t uint8_val)
sysrepo::Change::new_val
S_Val new_val()
sysrepo::Vals_Holder::~Vals_Holder
~Vals_Holder()
SR_BOOL_T
@ SR_BOOL_T
Definition: sysrepo.h:622
sysrepo::Data::get_decimal64
double get_decimal64() const
sysrepo::Data::get_string
char * get_string() const
sysrepo::Errors
Class for wrapping sr_error_info_t.
Definition: Struct.hpp:260
sysrepo::Data::get_uint64
uint64_t get_uint64() const
sysrepo::Val::to_string
std::string to_string()
sysrepo::Change_Iter::~Change_Iter
~Change_Iter()
sysrepo::Val::Val
Val(double decimal64_val)
sysrepo::Data::get_bool
bool get_bool() const
sysrepo::Val::Val
Val(uint32_t uint32_val)
sr_error_info_s::err_count
size_t err_count
Definition: sysrepo.h:219
sysrepo::Tree_Change::node
libyang::S_Data_Node node()
sysrepo::Vals_Holder::reallocate
S_Vals reallocate(size_t n)
sysrepo::Vals::Vals
Vals(sr_val_t **vals, size_t *cnt, S_Deleter deleter=nullptr)
sysrepo::Data::get_identityref
char * get_identityref() const
sysrepo::Val::Val
Val(uint16_t uint16_val)
sysrepo::Change::~Change
~Change()
sysrepo::Val::empty
bool empty()
sysrepo::Val::~Val
~Val()
sr_val_s
Structure that contains value of an data element stored in the sysrepo datastore.
Definition: sysrepo.h:670
sr_error_info_s::err_code
sr_error_t err_code
Definition: sysrepo.h:217
sysrepo::Errors::message
const char * message(size_t idx)
Definition: Struct.hpp:268
sysrepo::Subscribe
Class for wrapping sr_subscription_ctx_t.
Definition: Session.hpp:190
sysrepo::Val::dflt
bool dflt()
sysrepo::Vals_Holder::val_cnt
size_t val_cnt(void)
Definition: Struct.hpp:227