29 #include "nomlib/json/FileReader.hpp"
34 FileReader::FileReader (
void ) {}
35 FileReader::~FileReader (
void ) {}
38 const std::string& filename,
48 if ( fp.is_open() ==
false || fp.good() == false )
50 NOM_LOG_ERR ( NOM,
"Could not open given file: " + filename );
55 if ( parser.
parse ( fp,
object.get(), parse_comments ) ==
false )
57 NOM_LOG_ERR ( NOM,
"Unable to parse input JSON file: " + filename );
71 default: printf (
" [type=%d, size=%d]", key.type(), key.
size() );
break;
75 printf (
" [type=nullValue, size=%d]", key.
size() );
81 printf (
" [type=intValue, size=%lu]",
sizeof ( key.asInt() ) );
87 printf (
" [type=uintValue, size=%lu]",
sizeof ( key.asUInt() ) );
93 printf (
" [type=realValue, size=%lu]",
sizeof ( key.asDouble() ) );
99 printf (
" [type=stringValue, size=%lu]", key.asString().length() );
105 printf (
" [type=booleanValue, size=%lu]",
sizeof ( key.asBool() ) );
111 printf (
" [type=arrayValue, size=%d]", key.
size() );
117 printf (
" [type=objectValue, size=%d]", key.
size() );
125 if ( value.isString() )
127 printf (
"string (%s)", value.asString().c_str() );
129 else if ( value.isBool() )
131 printf (
"bool (%d)", value.asBool() );
133 else if ( value.isInt() )
135 printf (
"int (%d)", value.asInt() );
137 else if ( value.isUInt() )
139 printf (
"uint (%u)", value.asUInt() );
141 else if ( value.isDouble() )
143 printf (
"double (%f)", value.asDouble() );
147 printf (
"unknown type=%d", value.type() );
157 if ( root.
size() > 0 )
159 std::cout << std::endl;
160 for (
auto itr = root.begin() ; itr != root.end() ; ++itr )
163 for (
auto tab = 0 ; tab < depth; tab++ )
168 std::cout <<
" subvalue (";
171 this->
dump ( *itr, depth );
180 std::cout << std::endl;
bool dump(const ValueType &object, int depth=0) const
Interface class for JSON data types.
bool load(const std::string &filename, Value &object, bool parse_comments=false)
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
void dump_key(const ValueType &object) const
Debugging aid; helper method for nom::JSON::FileReader::dump.
ArrayIndex size() const
Number of values in array or object.
void dump_value(const ValueType &key) const
Debugging aid; helper method for nom::JSON::FileReader::dump.
Unserialize a JSON document into a Value.