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_children_parser.cpp
Go to the documentation of this file.
2 #include "irods_log.hpp"
3 #include "rodsErrorTable.h"
4 
5 #include <sstream>
6 #include <iostream>
7 
8 namespace irods {
9 
11  }
12 
14  // TODO - stub
15  }
16 
18  children_map_t& list ) {
20  return SUCCESS();
21  }
22 
24  std::string& ret_string ) const {
25  std::stringstream children_stream;
26  bool first = true;
27  children_map_t::const_iterator itr;
28  for ( itr = children_list_.begin(); itr != children_list_.end(); ++itr ) {
29  if ( first ) {
30  first = false;
31  }
32  else {
33  children_stream << ";";
34  }
35  children_stream << itr->first << "{" << itr->second << "}";
36  }
37  ret_string = children_stream.str();
38  return SUCCESS();
39  }
40 
42  const std::string& child,
43  const std::string& context ) {
44  error ret = SUCCESS();
45  children_map_t::const_iterator itr = children_list_.find( child );
46  if ( itr != children_list_.end() ) {
47  std::stringstream msg;
48  msg << "child [" << child << "] already exists";
49  ret = ERROR( CHILD_EXISTS, msg.str() );
50  }
51  else {
52  children_list_[child] = context;
53  }
54  return ret;
55  }
56 
58  const std::string& child ) {
59  error ret = SUCCESS();
60  children_map_t::iterator itr = children_list_.find( child );
61  if ( itr == children_list_.end() ) {
62  std::stringstream msg;
63  msg << "child [" << child << "] not found";
64  ret = ERROR( CHILD_NOT_FOUND, msg.str() );
65  }
66  else {
67  children_list_.erase( itr );
68  }
69 
70  return ret;
71  }
72 
74  std::string& _child ) {
75  error result = SUCCESS();
76  if ( children_list_.begin() != children_list_.end() ) {
77  _child = children_list_.begin()->first;
78  }
79  else {
80  _child.clear();
81  std::stringstream msg;
82  msg << __FUNCTION__;
83  msg << " - Trying to retrieve first child from children string but string appears to be empty.";
84  result = ERROR( CHILD_NOT_FOUND, msg.str() );
85  }
86  return result;
87  }
88 
89 
91  std::string& _child ) {
92  error result = SUCCESS();
93  if ( children_list_.begin() != children_list_.end() ) {
95  itr--;
96  _child = itr->first;
97  }
98  else {
99  _child.clear();
100  std::stringstream msg;
101  msg << __FUNCTION__;
102  msg << " - Trying to retrieve last child from children string but string appears to be empty.";
103  result = ERROR( CHILD_NOT_FOUND, msg.str() );
104  }
105  return result;
106  }
107 
108 
109 
111  const std::string& str ) {
112  error result = SUCCESS();
113 
114  // clear existing map
115  children_list_.clear();
116 
117  // check if the string is empty
118  if ( !str.empty() ) {
119 
120  // loop until we have parsed all of the children
121  bool done = false;
122  std::size_t current_pos = 0;
123  while ( result.ok() && !done ) {
124 
125  // get the complete child string
126  std::size_t end_pos = str.find( ";", current_pos );
127  std::string complete_child = str.substr( current_pos, end_pos - current_pos );
128 
129  // get the child context string if there is one
130  std::size_t context_start = complete_child.find( "{" );
131  std::string child = complete_child.substr( 0, context_start );
132  std::string context;
133  if ( context_start != std::string::npos ) {
134  ++context_start;
135  std::size_t context_end = complete_child.find( "}", context_start );
136  if ( context_end == std::string::npos ) {
137  std::stringstream msg;
138  msg << "missing matching \"}\" in child context string \"" << str << "\"";
139  result = ERROR( CHILD_NOT_FOUND, msg.str() );
140  }
141  else {
142  context = complete_child.substr( context_start, context_end - context_start );
143  }
144  }
145 
146  // add the child to the map
147  if ( result.ok() ) {
148  children_list_[child] = context;
149  if ( end_pos == std::string::npos ) {
150  done = true;
151  }
152  else {
153  current_pos = end_pos + 1;
154  // check for trailing semicolon
155  if ( current_pos >= str.size() ) {
156  done = true;
157  }
158  }
159  }
160  }
161  }
162 
163  return result;
164  }
165 
166 
168  return children_list_.begin();
169  }
170 
172  return children_list_.end();
173  }
174 
175 }; // namespace irods
irods_children_parser.hpp
irods::children_parser::children_parser
children_parser(void)
Definition: irods_children_parser.cpp:10
irods::children_parser::last_child
error last_child(std::string &_child)
Definition: irods_children_parser.cpp:90
irods::children_parser::const_iterator
children_map_t::const_iterator const_iterator
Definition: irods_children_parser.hpp:18
irods::children_parser::end
const_iterator end(void) const
Definition: irods_children_parser.cpp:171
irods::children_parser::list
error list(children_map_t &list)
Definition: irods_children_parser.cpp:17
irods::children_parser::set_string
error set_string(const std::string &str)
Definition: irods_children_parser.cpp:110
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
CHILD_EXISTS
@ CHILD_EXISTS
Definition: rodsErrorTable.h:751
irods::children_parser::begin
const_iterator begin(void) const
Definition: irods_children_parser.cpp:167
irods::children_parser::children_map_t
std::map< std::string, std::string > children_map_t
Definition: irods_children_parser.hpp:17
irods::children_parser::add_child
error add_child(const std::string &child, const std::string &context)
Definition: irods_children_parser.cpp:41
irods::children_parser::remove_child
error remove_child(const std::string &child)
Definition: irods_children_parser.cpp:57
irods
Definition: apiHandler.hpp:35
irods::children_parser::children_list_
children_map_t children_list_
Definition: irods_children_parser.hpp:55
irods::children_parser::first_child
error first_child(std::string &_child)
Definition: irods_children_parser.cpp:73
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods::children_parser::str
error str(std::string &ret_string) const
Definition: irods_children_parser.cpp:23
CHILD_NOT_FOUND
@ CHILD_NOT_FOUND
Definition: rodsErrorTable.h:753
rodsErrorTable.h
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::children_parser::~children_parser
virtual ~children_parser(void)
Definition: irods_children_parser.cpp:13
irods_log.hpp
list
Definition: irods_list.h:13