|
osgEarth 2.1.1
|
Classes | |
| class | StaticString |
| Lightweight wrapper to tag static string. More... | |
| class | Value |
| Represents a JSON value. More... | |
| class | PathArgument |
| Experimental and untested: represents an element of the "path" to access a node. More... | |
| class | Path |
| Experimental and untested: represents a "path" to access a node. More... | |
| class | ValueAllocator |
| Allocator to customize member name and string value memory management done by Value. More... | |
| class | ValueIteratorBase |
| Experimental and untested: base class for Value iterators. More... | |
| class | ValueConstIterator |
| Experimental and untested: const iterator for object and array value. More... | |
| class | ValueIterator |
| Experimental and untested: iterator for object and array value. More... | |
| class | Writer |
| Abstract class for writers. More... | |
| class | FastWriter |
| Outputs a Value in JSON format without formatting (not human friendly). More... | |
| class | StyledWriter |
| Writes a Value in JSON format in a human friendly way. More... | |
| class | StyledStreamWriter |
| Writes a Value in JSON format in a human friendly way, to a stream rather than to a string. More... | |
| class | Reader |
| Unserialize a JSON document into a Value. More... | |
| class | DefaultValueAllocator |
Enumerations | |
| enum | ValueType { nullValue = 0, intValue, uintValue, realValue, stringValue, booleanValue, arrayValue, objectValue } |
Type of the value held by a Value object. More... | |
| enum | CommentPlacement { commentBefore = 0, commentAfterOnSameLine, commentAfter, numberOfCommentPlacement } |
Functions | |
| std::string JSON_API | valueToString (Value::Int value) |
| std::string JSON_API | valueToString (Value::UInt value) |
| std::string JSON_API | valueToString (double value) |
| std::string JSON_API | valueToString (bool value) |
| std::string JSON_API | valueToQuotedString (const char *value) |
| std::ostream & | operator<< (std::ostream &, const Value &root) |
| Output using the StyledStreamWriter. | |
| std::istream & | operator>> (std::istream &, Value &) |
| Read from 'sin' into 'root'. | |
| static bool | in (Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4) |
| static bool | in (Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4, Reader::Char c5) |
| static bool | containsNewLine (Reader::Location begin, Reader::Location end) |
| static void | uintToString (unsigned int value, char *¤t) |
Type of the value held by a Value object.
Definition at line 80 of file JsonUtils.
{
nullValue = 0,
intValue,
uintValue,
realValue,
stringValue,
booleanValue,
arrayValue,
objectValue
};
| static bool osgEarth::Json::containsNewLine | ( | Reader::Location | begin, |
| Reader::Location | end | ||
| ) | [static] |
Definition at line 2003 of file JsonUtils.cpp.
{
for ( ;begin < end; ++begin )
if ( *begin == '\n' || *begin == '\r' )
return true;
return false;
}
Here is the caller graph for this function:| static bool osgEarth::Json::in | ( | Reader::Char | c, |
| Reader::Char | c1, | ||
| Reader::Char | c2, | ||
| Reader::Char | c3, | ||
| Reader::Char | c4 | ||
| ) | [inline, static] |
Definition at line 1990 of file JsonUtils.cpp.
{
return c == c1 || c == c2 || c == c3 || c == c4;
}
Here is the caller graph for this function:| static bool osgEarth::Json::in | ( | Reader::Char | c, |
| Reader::Char | c1, | ||
| Reader::Char | c2, | ||
| Reader::Char | c3, | ||
| Reader::Char | c4, | ||
| Reader::Char | c5 | ||
| ) | [inline, static] |
Definition at line 1996 of file JsonUtils.cpp.
{
return c == c1 || c == c2 || c == c3 || c == c4 || c == c5;
}
| std::ostream& osgEarth::Json::operator<< | ( | std::ostream & | , |
| const Value & | root | ||
| ) |
Output using the StyledStreamWriter.
Definition at line 3511 of file JsonUtils.cpp.
{
Json::StyledStreamWriter writer;
writer.write(sout, root);
return sout;
}
Here is the call graph for this function:| std::istream& osgEarth::Json::operator>> | ( | std::istream & | , |
| Value & | |||
| ) |
Read from 'sin' into 'root'.
Always keep comments from the input JSON.
This can be used to read a file into a particular sub-object. For example:
Json::Value root;
cin >> root["dir"]["file"];
cout << root;
Result:
{
"dir": {
"file": {
// The input stream JSON would be nested here.
}
}
}
| std::exception | on parse error. |
Definition at line 2719 of file JsonUtils.cpp.
{
Json::Reader reader;
bool ok = reader.parse(sin, root, true);
//JSON_ASSERT( ok );
if (!ok) throw std::runtime_error(reader.getFormatedErrorMessages());
return sin;
}
Here is the call graph for this function:| static void osgEarth::Json::uintToString | ( | unsigned int | value, |
| char *& | current | ||
| ) | [static] |
Definition at line 2731 of file JsonUtils.cpp.
{
*--current = 0;
do
{
*--current = (value % 10) + '0';
value /= 10;
}
while ( value != 0 );
}
Here is the caller graph for this function:| std::string osgEarth::Json::valueToQuotedString | ( | const char * | value | ) |
Definition at line 2812 of file JsonUtils.cpp.
{
if (value == NULL)
return "";
// Not sure how to handle unicode...
if (strpbrk(value, "\"\\\b\f\n\r\t") == NULL)
return std::string("\"") + std::string(value) + std::string("\"");
// We have to walk value and escape any special characters.
// Appending to std::string is not efficient, but this should be rare.
// (Note: forward slashes are *not* rare, but I am not escaping them.)
unsigned maxsize = strlen(value)*2 + 3; // allescaped+quotes+NULL
std::string result;
result.reserve(maxsize); // to avoid lots of mallocs
result += "\"";
for (const char* c=value; *c != 0; ++c){
switch(*c){
case '\"':
result += "\\\"";
break;
case '\\':
result += "\\\\";
break;
case '\b':
result += "\\b";
break;
case '\f':
result += "\\f";
break;
case '\n':
result += "\\n";
break;
case '\r':
result += "\\r";
break;
case '\t':
result += "\\t";
break;
case '/':
// Even though \/ is considered a legal escape in JSON, a bare
// slash is also legal, so I see no reason to escape it.
// (I hope I am not misunderstanding something.)
default:
result += *c;
}
}
result += "\"";
return result;
}
Here is the caller graph for this function:| std::string osgEarth::Json::valueToString | ( | Value::Int | value | ) |
Definition at line 2743 of file JsonUtils.cpp.
{
char buffer[32];
char *current = buffer + sizeof(buffer);
bool isNegative = value < 0;
if ( isNegative )
value = -value;
uintToString( Value::UInt(value), current );
if ( isNegative )
*--current = '-';
assert( current >= buffer );
return current;
}
Here is the call graph for this function:
Here is the caller graph for this function:| std::string osgEarth::Json::valueToString | ( | Value::UInt | value | ) |
Definition at line 2758 of file JsonUtils.cpp.
{
char buffer[32];
char *current = buffer + sizeof(buffer);
uintToString( value, current );
assert( current >= buffer );
return current;
}
Here is the call graph for this function:| std::string osgEarth::Json::valueToString | ( | double | value | ) |
Definition at line 2767 of file JsonUtils.cpp.
{
char buffer[32];
#ifdef __STDC_SECURE_LIB__ // Use secure version with visual studio 2005 to avoid warning.
sprintf_s(buffer, sizeof(buffer), "%#.16g", value);
#else
sprintf(buffer, "%#.16g", value);
#endif
char* ch = buffer + strlen(buffer) - 1;
if (*ch != '0') return buffer; // nothing to truncate, so save time
while(ch > buffer && *ch == '0'){
--ch;
}
char* last_nonzero = ch;
while(ch >= buffer){
switch(*ch){
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
--ch;
continue;
case '.':
// Truncate zeroes to save bytes in output, but keep one.
*(last_nonzero+2) = '\0';
return buffer;
default:
return buffer;
}
}
return buffer;
}
| std::string osgEarth::Json::valueToString | ( | bool | value | ) |
Definition at line 2807 of file JsonUtils.cpp.
{
return value ? "true" : "false";
}
1.7.3