irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

irods_hierarchy_parser.cpp
Go to the documentation of this file.
3 #include "rodsErrorTable.h"
4 #include "irods_log.hpp"
5 
6 #include <iostream>
7 #include <sstream>
8 
9 namespace irods {
10 
11  static const std::string DELIM = ";";
12 
14  }
15 
16  hierarchy_parser::hierarchy_parser(const std::string& _hier) {
17  resc_list_.clear();
19  if (resc_list_.empty()) {
20  THROW(SYS_INVALID_INPUT_PARAM, "invalid hierarchy string");
21  }
22  }
23 
25  const hierarchy_parser& parser ) {
27  for ( it = parser.begin(); it != parser.end(); ++it ) {
28  add_child( *it );
29  }
30  }
31 
33  // TODO - stub
34  }
35 
37  const std::string& _resc_hier ) {
38  resc_list_.clear();
39  string_tokenize( _resc_hier, DELIM, resc_list_ );
40  if (resc_list_.empty()) {
41  return ERROR( SYS_INVALID_INPUT_PARAM, "empty hierarchy string" );
42  }
43  return SUCCESS();
44  }
45 
47  std::string& _ret_string,
48  const std::string& _term_resc ) const {
49 
50  error result = SUCCESS();
51  _ret_string.clear();
52  bool first = true;
53  bool done = false;
54  for ( resc_list_t::const_iterator itr = resc_list_.begin();
55  !done && itr != resc_list_.end(); ++itr ) {
56  if ( first ) {
57  first = false;
58  }
59  else {
60  _ret_string += DELIM;
61  }
62  _ret_string += *itr;
63  if ( *itr == _term_resc ) {
64  done = true;
65  }
66  }
67  return result;
68  }
69 
70  std::string hierarchy_parser::str(const std::string& _term_resc) const {
71  std::string ret_string{};
72  bool first = true;
73  for (const auto& resc : resc_list_) {
74  if ( first ) {
75  first = false;
76  }
77  else {
78  ret_string += DELIM;
79  }
80  ret_string += resc;
81  if (resc == _term_resc) {
82  break;
83  }
84  }
85  return ret_string;
86  }
87 
89  const std::string& _resc ) {
90 
91  error result = SUCCESS();
92  resc_list_.push_back( _resc );
93  return result;
94  }
95 
97  std::string& _ret_resc ) const {
98 
99  error result = SUCCESS();
100  if ( resc_list_.size() ) {
101  _ret_resc = resc_list_.front();
102  }
103  else {
104  _ret_resc.clear(); // return empty string
105  }
106  return result;
107  }
108 
110  std::string& _ret_resc ) const {
111 
112  error result = SUCCESS();
113  if ( resc_list_.size() ) {
114  _ret_resc = resc_list_.back();
115  }
116  else {
117  _ret_resc.clear(); // return empty string
118  }
119  return result;
120  }
121 
122  std::string hierarchy_parser::first_resc() const {
123  if (resc_list_.size()) {
124  return resc_list_.front();
125  }
126  return {};
127  }
128 
129  std::string hierarchy_parser::last_resc() const {
130  if (resc_list_.size()) {
131  return resc_list_.back();
132  }
133  return {};
134  }
135 
137  const std::string& _current,
138  std::string& _ret_resc ) const {
139 
140  error result = SUCCESS();
141  _ret_resc.clear();
142  bool found = false;
143  for ( resc_list_t::const_iterator itr = resc_list_.begin();
144  !found && itr != resc_list_.end(); ++itr ) {
145  if ( *itr == _current ) {
146  found = true;
147  resc_list_t::const_iterator next_itr = itr + 1;
148  if ( next_itr != resc_list_.end() ) {
149  _ret_resc = *next_itr;
150  }
151  else {
152  std::stringstream msg;
153  msg << "there is no next resource. [" << _current;
154  msg << "] is a leaf resource.";
155  result = ERROR( NO_NEXT_RESC_FOUND, msg.str() );
156  }
157  }
158  }
159  if ( !found ) {
160  std::stringstream msg;
161  msg << "resource [" << _current << "] not in hierarchy.";
162  result = ERROR( CHILD_NOT_FOUND, msg.str() );
163  }
164  return result;
165  }
166 
168  const std::string& _current) const {
169  for (resc_list_t::const_iterator itr = resc_list_.begin();
170  itr != resc_list_.end(); ++itr) {
171  if (*itr == _current) {
172  resc_list_t::const_iterator next_itr = itr + 1;
173  if (next_itr != resc_list_.end()) {
174  return *next_itr;
175  }
176  THROW(NO_NEXT_RESC_FOUND, (boost::format(
177  "there is no next resource. [%s] is a leaf resource.") % _current).str());
178  }
179  }
180  THROW(CHILD_NOT_FOUND, (boost::format(
181  "resource [%s] not in hierarchy.") % _current).str());
182  }
183 
184 
186  int& levels ) const {
187  error result = SUCCESS();
188  levels = resc_list_.size();
189  return result;
190  }
191 
193  return resc_list_.size();
194  }
195 
197  return resc_list_.begin();
198  }
199 
201  return resc_list_.end();
202  }
203 
205  const hierarchy_parser& rhs ) {
206  resc_list_ = rhs.resc_list_;
207  return *this;
208  }
209 
210  const std::string& hierarchy_parser::delimiter( void ) {
211  return DELIM;
212  }
213 
214  bool hierarchy_parser::resc_in_hier(const std::string& _resc) const {
215  return std::any_of(resc_list_.begin(), resc_list_.end(),
216  [&](const std::string& _r) { return _r == _resc; });
217  }
218 
219 }; // namespace irods
THROW
#define THROW(_code, _msg)
Definition: irods_exception.hpp:68
irods::hierarchy_parser::operator=
hierarchy_parser & operator=(const hierarchy_parser &parser)
Definition: irods_hierarchy_parser.cpp:204
irods::hierarchy_parser
Definition: irods_hierarchy_parser.hpp:14
irods::hierarchy_parser::last_resc
std::string last_resc() const
Definition: irods_hierarchy_parser.cpp:129
irods::hierarchy_parser::hierarchy_parser
hierarchy_parser(void)
Definition: irods_hierarchy_parser.cpp:13
deploy_schemas_locally.parser
parser
Definition: deploy_schemas_locally.py:59
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
irods::string_tokenize
void string_tokenize(const std::string &, const std::string &, std::vector< std::string > &)
Definition: irods_string_tokenize.cpp:9
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods_string_tokenize.hpp
irods::hierarchy_parser::add_child
error add_child(const std::string &_resc)
Definition: irods_hierarchy_parser.cpp:88
irods::hierarchy_parser::resc_in_hier
bool resc_in_hier(const std::string &_resc) const
Definition: irods_hierarchy_parser.cpp:214
irods
Definition: apiHandler.hpp:35
irods::DELIM
static const std::string DELIM
Definition: irods_hierarchy_parser.cpp:11
irods::hierarchy_parser::num_levels
int num_levels() const
Definition: irods_hierarchy_parser.cpp:192
irods::hierarchy_parser::~hierarchy_parser
virtual ~hierarchy_parser()
Definition: irods_hierarchy_parser.cpp:32
irods::hierarchy_parser::set_string
error set_string(const std::string &_resc_hier)
Definition: irods_hierarchy_parser.cpp:36
irods::hierarchy_parser::delimiter
static const std::string & delimiter(void)
Definition: irods_hierarchy_parser.cpp:210
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods::hierarchy_parser::end
const_iterator end(void) const
Definition: irods_hierarchy_parser.cpp:200
irods_hierarchy_parser.hpp
irods::hierarchy_parser::str
error str(std::string &_ret_string, const std::string &_term_resc="") const
Definition: irods_hierarchy_parser.cpp:46
irods::hierarchy_parser::next
error next(const std::string &_current, std::string &_ret_resc) const
Definition: irods_hierarchy_parser.cpp:136
CHILD_NOT_FOUND
@ CHILD_NOT_FOUND
Definition: rodsErrorTable.h:753
irods::hierarchy_parser::first_resc
std::string first_resc() const
Definition: irods_hierarchy_parser.cpp:122
rodsErrorTable.h
irods::hierarchy_parser::resc_list_
resc_list_t resc_list_
Definition: irods_hierarchy_parser.hpp:88
NO_NEXT_RESC_FOUND
@ NO_NEXT_RESC_FOUND
Definition: rodsErrorTable.h:754
irods::hierarchy_parser::const_iterator
resc_list_t::const_iterator const_iterator
Definition: irods_hierarchy_parser.hpp:17
irods_log.hpp
irods::hierarchy_parser::begin
const_iterator begin(void) const
Definition: irods_hierarchy_parser.cpp:196