sysrepo  1.4.70
YANG datastore
Xpath.hpp
Go to the documentation of this file.
1 
23 #ifndef XPATH_H
24 #define XPATH_H
25 
26 #include <iostream>
27 
28 #include "utils/xpath.h"
29 
30 namespace sysrepo {
31 
41 class Xpath_Ctx
42 {
43 public:
47  char *begining() {if (_state != nullptr) return _state->begining; return nullptr;};
49  char *current_node() {if (_state != nullptr) return _state->current_node; return nullptr;};
51  char *replaced_position() {if (_state != nullptr) return _state->replaced_position; return nullptr;};
53  char replaced_char() {if (_state != nullptr) return _state->replaced_char; return (char) 0;};
56  char *next_node(char *xpath) {return sr_xpath_next_node(xpath, _state);};
58  char *next_node_with_ns(char *xpath) {return sr_xpath_next_node_with_ns(xpath, _state);};
60  char *next_key_name(char *xpath) {return sr_xpath_next_key_name(xpath, _state);};
62  char *next_key_value(char *xpath) {return sr_xpath_next_key_value(xpath, _state);};
64  char *node(char *xpath, const char *node_name) {return sr_xpath_node(xpath, node_name, _state);};
66  char *node_rel(char *xpath, const char *node_name) {return sr_xpath_node_rel(xpath, node_name, _state);};
68  char *node_idx(char *xpath, size_t index) {return sr_xpath_node_idx(xpath, index, _state);};
70  char *node_idx_rel(char *xpath, size_t index) {return sr_xpath_node_idx_rel(xpath, index, _state);};
72  char *node_key_value(char *xpath, const char *key) {return sr_xpath_node_key_value(xpath, key, _state);};
74  char *node_key_value_idx(char *xpath, size_t index) {return sr_xpath_node_key_value_idx(xpath, index, _state);};
76  char *key_value(char *xpath, const char *node_name, const char *key_name) {
77  return sr_xpath_key_value(xpath, node_name, key_name, _state);};
79  char *key_value_idx(char *xpath, size_t node_index, size_t key_index) {
80  return sr_xpath_key_value_idx(xpath, node_index, key_index, _state);};
82  char *last_node(char *xpath) {return sr_xpath_last_node(xpath, _state);};
84  char *node_name(const char *xpath) {return sr_xpath_node_name(xpath);};
86  bool node_name_eq(const char *xpath, const char *node_str) {return sr_xpath_node_name_eq(xpath, node_str);};
88  void recover() {return sr_xpath_recover(_state);};
89 
90 private:
91  sr_xpath_ctx_t *_state;
92 };
93 
95 }
96 
97 #endif
sr_xpath_next_key_value
char * sr_xpath_next_key_value(char *xpath, sr_xpath_ctx_t *state)
Returns the value of the next key at the current level in processed xpath.
sysrepo::Xpath_Ctx::next_key_value
char * next_key_value(char *xpath)
Definition: Xpath.hpp:62
sysrepo::Xpath_Ctx::replaced_char
char replaced_char()
Definition: Xpath.hpp:53
sysrepo
Definition: Connection.hpp:35
sr_xpath_node_name
char * sr_xpath_node_name(const char *xpath)
Returns pointer to the string after the last slash in xpath (node name).
sysrepo::Xpath_Ctx::next_key_name
char * next_key_name(char *xpath)
Definition: Xpath.hpp:60
sysrepo::Xpath_Ctx::node_idx
char * node_idx(char *xpath, size_t index)
Definition: Xpath.hpp:68
sysrepo::Xpath_Ctx::node
char * node(char *xpath, const char *node_name)
Definition: Xpath.hpp:64
sr_xpath_node_key_value_idx
char * sr_xpath_node_key_value_idx(char *xpath, size_t index, sr_xpath_ctx_t *state)
Looks up the value for the key at the current level in xpath specified by index. First key has index ...
sr_xpath_ctx_s::begining
char * begining
Definition: xpath.h:53
sysrepo::Xpath_Ctx::~Xpath_Ctx
~Xpath_Ctx()
sysrepo::Xpath_Ctx::Xpath_Ctx
Xpath_Ctx()
sysrepo::Xpath_Ctx::node_key_value
char * node_key_value(char *xpath, const char *key)
Definition: Xpath.hpp:72
xpath.h
Sysrepo helpers for node's address manipulation.
sr_xpath_node_key_value
char * sr_xpath_node_key_value(char *xpath, const char *key, sr_xpath_ctx_t *state)
Looks up the value for the key at the current level in xpath.
sr_xpath_node_rel
char * sr_xpath_node_rel(char *xpath, const char *node_name, sr_xpath_ctx_t *state)
Similar to sr_xpath_node. The difference is that search start at current node according to the state.
sysrepo::Xpath_Ctx::node_name_eq
bool node_name_eq(const char *xpath, const char *node_str)
Definition: Xpath.hpp:86
sr_xpath_next_key_name
char * sr_xpath_next_key_name(char *xpath, sr_xpath_ctx_t *state)
Returns the name of the next key at the current level in processed xpath.
sysrepo::Xpath_Ctx::replaced_position
char * replaced_position()
Definition: Xpath.hpp:51
sysrepo::Xpath_Ctx::next_node
char * next_node(char *xpath)
Definition: Xpath.hpp:56
sysrepo::Xpath_Ctx::next_node_with_ns
char * next_node_with_ns(char *xpath)
Definition: Xpath.hpp:58
sysrepo::Xpath_Ctx
Class for wrapping sr_xpath_ctx_t.
Definition: Xpath.hpp:42
sr_xpath_ctx_s::replaced_char
char replaced_char
Definition: xpath.h:56
sr_xpath_ctx_s::current_node
char * current_node
Definition: xpath.h:54
sysrepo::Xpath_Ctx::node_rel
char * node_rel(char *xpath, const char *node_name)
Definition: Xpath.hpp:66
sysrepo::Xpath_Ctx::last_node
char * last_node(char *xpath)
Definition: Xpath.hpp:82
sr_xpath_next_node
char * sr_xpath_next_node(char *xpath, sr_xpath_ctx_t *state)
The function returns a pointer to the following node. If xpath is not NULL returns the first node nam...
sysrepo::Xpath_Ctx::key_value
char * key_value(char *xpath, const char *node_name, const char *key_name)
Definition: Xpath.hpp:76
sr_xpath_recover
void sr_xpath_recover(sr_xpath_ctx_t *state)
Recovers the xpath string to the original state (puts back the character that was replaced by termina...
sysrepo::Xpath_Ctx::current_node
char * current_node()
Definition: Xpath.hpp:49
sysrepo::Xpath_Ctx::node_idx_rel
char * node_idx_rel(char *xpath, size_t index)
Definition: Xpath.hpp:70
sysrepo::Xpath_Ctx::node_key_value_idx
char * node_key_value_idx(char *xpath, size_t index)
Definition: Xpath.hpp:74
sr_xpath_key_value
char * sr_xpath_key_value(char *xpath, const char *node_name, const char *key_name, sr_xpath_ctx_t *state)
Looks up the value of the key in a node specified by name.
sr_xpath_key_value_idx
char * sr_xpath_key_value_idx(char *xpath, size_t node_index, size_t key_index, sr_xpath_ctx_t *state)
Looks up the value of the key in a node specified by index. First node has index zero.
sysrepo::Xpath_Ctx::recover
void recover()
Definition: Xpath.hpp:88
sr_xpath_ctx_s
State of xpath parsing. User must not modify nor rely on the content of the structure.
Definition: xpath.h:52
sr_xpath_next_node_with_ns
char * sr_xpath_next_node_with_ns(char *xpath, sr_xpath_ctx_t *state)
Same as sr_xpath_next_node with the difference that namespace is included in result if present in xpa...
sr_xpath_node_idx
char * sr_xpath_node_idx(char *xpath, size_t index, sr_xpath_ctx_t *state)
Returns node specified by index starting at the begin of expression. First node has index 0.
sysrepo::Xpath_Ctx::node_name
char * node_name(const char *xpath)
Definition: Xpath.hpp:84
sr_xpath_node_name_eq
bool sr_xpath_node_name_eq(const char *xpath, const char *node_str)
Compares string after the last slash in xpath (node name) with provided string.
sr_xpath_node
char * sr_xpath_node(char *xpath, const char *node_name, sr_xpath_ctx_t *state)
Returns a pointer to the node specified by name. It searches from the beginning of the xpath,...
sr_xpath_ctx_s::replaced_position
char * replaced_position
Definition: xpath.h:55
sysrepo::Xpath_Ctx::key_value_idx
char * key_value_idx(char *xpath, size_t node_index, size_t key_index)
Definition: Xpath.hpp:79
sr_xpath_node_idx_rel
char * sr_xpath_node_idx_rel(char *xpath, size_t index, sr_xpath_ctx_t *state)
Return node specified by index. Following node has index zero.
sysrepo::Xpath_Ctx::begining
char * begining()
Definition: Xpath.hpp:47
sr_xpath_last_node
char * sr_xpath_last_node(char *xpath, sr_xpath_ctx_t *state)
Returns pointer to the last node.