24 #include <boost/iostreams/device/file.hpp> 25 #include <boost/iostreams/filtering_stream.hpp> 26 #include <boost/algorithm/string.hpp> 36 io::filtering_istream filter_in;
41 root_node_ = std::make_shared<Node>();
46 THROW( ReaderToStorage::ExcNotJSONFormat() << ReaderToStorage::EI_JSONLine(e.
line_) << ReaderToStorage::EI_JSONColumn(e.
column_)
47 << ReaderToStorage::EI_JSONReason(e.
reason_));
50 nodes_.push_back( root_node_.get() );
82 if ( index >= array.size())
return false;
83 path_.push_back( make_pair( index,
string(
"") ) );
84 nodes_.push_back( &( array[index] ) );
94 json_spirit::mObject::const_iterator
it = obj.find(key);
95 if (it == obj.end()) {
98 path_.push_back( make_pair( (
int)(-1), key) );
99 nodes_.push_back( &( it->second ) );
107 if (
path_.size() > 1) {
120 namespace ba = boost::algorithm;
125 if (obj.size() != 1)
return NULL;
126 if (obj.begin()->first !=
"REF")
return NULL;
128 const Node &ref_node = obj.begin()->second;
130 THROW( ExcRefOfWrongType() << EI_ErrorAddress(this->
as_string()) );
133 string ref_address = ref_node.
get_str();
136 string::size_type pos = 0;
137 string::size_type new_pos = 0;
138 string address = ref_address +
'/';
140 bool relative_ref =
false;
146 THROW( ExcReferenceNotFound() << EI_RefAddress(this->
as_string()) << EI_ErrorAddress(ref_path->
as_string()) << EI_RefStr(ref_address)
147 << EI_Specification(
"cannot follow reference") );
150 while ( ( new_pos=address.find(
'/',pos) ) != string::npos ) {
151 tmp_str = address.substr(pos, new_pos - pos);
152 if (pos==0 && tmp_str ==
"") {
156 }
else if ( ba::all( tmp_str, ba::is_digit()) ) {
159 THROW( ExcReferenceNotFound() << EI_RefAddress(this->
as_string()) << EI_ErrorAddress(ref_path->
as_string()) << EI_RefStr(ref_address)
160 << EI_Specification(
"there should be Array") );
163 if ( !ref_path->
down( atoi(tmp_str.c_str()) ) ) {
164 THROW( ExcReferenceNotFound() << EI_RefAddress(this->
as_string()) << EI_ErrorAddress(ref_path->
as_string()) << EI_RefStr(ref_address)
165 << EI_Specification(
"index out of size of Array") );
168 }
else if (tmp_str ==
"..") {
170 if (ref_path->
level() <= 0 ) {
171 THROW( ExcReferenceNotFound() << EI_RefAddress(this->
as_string()) << EI_ErrorAddress(ref_path->
as_string()) << EI_RefStr(ref_address)
172 << EI_Specification(
"can not go up from root") );
178 THROW( ExcReferenceNotFound() << EI_RefAddress(this->
as_string()) << EI_ErrorAddress(ref_path->
as_string()) << EI_RefStr(ref_address)
179 << EI_Specification(
"there should be Record") );
180 if ( !ref_path->
down(tmp_str) )
181 THROW( ExcReferenceNotFound() << EI_RefAddress(this->
as_string()) << EI_ErrorAddress(ref_path->
as_string()) << EI_RefStr(ref_address)
182 << EI_Specification(
"key '"+tmp_str+
"' not found") );
203 THROW( ReaderToStorage::ExcInputError() );
214 THROW( ReaderToStorage::ExcInputError() );
227 THROW( ReaderToStorage::ExcInputError() );
238 THROW( ReaderToStorage::ExcInputError() );
254 json_spirit::mObject::const_iterator map_it;
255 std::set<string>::iterator set_it;
257 for( map_it = j_map.begin(); map_it != j_map.end(); ++map_it) {
258 keys_list.insert(map_it->first);
272 return j_array.size();
299 std::string desc_name =
"";
302 if ( type_path.
down(
"TYPE") ) {
boost::int64_t get_int64() const
#define MessageOut()
Macro defining 'message' record of log.
void read_or_throw(const std::string &s, mValue &value)
const String_type & get_str() const
const Array & get_array() const
const Object & get_obj() const
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.