...
 
Commits (3)
......@@ -25,6 +25,7 @@
</Linker>
<ResourceCompiler Options=""/>
</GlobalSettings>
<Configuration Name="Release_RaspberryPi" CompilerType="Cross GCC ( arm-linux-gnueabihf )" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Configuration Name="Release_RaspberryPi" CompilerType="Cross GCC (arm-linux-gnueabihf)" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-pedantic-errors;-Wfatal-errors;-O1;-pedantic;-W;-std=c++11;-Wall;-fPIC" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
......
The MIT License (MIT)
Copyright (c) 2016 Karl Blotnicki
Copyright (c) 2018 Karl Herbig
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
......
......@@ -58,7 +58,9 @@ public:
Value& operator=(Value&& other);
Value& operator[](const std::string& key);
const Value& operator[](const std::string& key) const;
Value& operator[](const int key);
const Value& operator[](const int key) const;
explicit operator double() const { return _dobValue; }
explicit operator int() const { return _intValue; }
......@@ -69,15 +71,15 @@ public:
friend std::ostream& operator<<(std::ostream& os, const Value& val);
ValueType type();
ValueType type() const;
int toInt();
double toDouble();
std::string& toString();
bool toBool();
int toInt() const;
double toDouble() const;
const std::string& toString() const;
bool toBool() const;
Array toArray();
Object toObject();
Array toArray() const;
Object toObject() const;
};
}
......
......@@ -4,11 +4,13 @@
using namespace std;
namespace Ccd {
namespace Json {
namespace Ccd
{
namespace Json
{
Value::Value() : _type ( ValueType::Null ) {}
Value::Value ( const int value ) : _type ( ValueType::Int ), _intValue ( value ) { }
Value::Value ( const double value ) : _type ( ValueType::Double ), _dobValue ( value ) {}
......@@ -23,99 +25,103 @@ Value::Value ( const Array& array ) : _type ( ValueType::Array ), _aryValue ( ar
Value::Value ( const Object& obj ) : _type ( ValueType::Object ), _objValue ( obj ) {}
Value::Value ( std::string&& value ) : _type ( ValueType::String ), _strValue ( move(value) ) {}
Value::Value ( std::string&& value ) : _type ( ValueType::String ), _strValue ( move ( value ) ) {}
Value::Value ( Array&& array ) : _type ( ValueType::Array ), _aryValue ( move(array) ) {}
Value::Value ( Array&& array ) : _type ( ValueType::Array ), _aryValue ( move ( array ) ) {}
Value::Value ( Object&& obj ) : _type ( ValueType::Object ), _objValue ( move(obj) ) {}
Value::Value ( Object&& obj ) : _type ( ValueType::Object ), _objValue ( move ( obj ) ) {}
Value::Value ( std::nullptr_t ) : _type ( ValueType::Null ) {}
<<<<<<< HEAD
Value::Value ( const initializer_list<Value> list ) : _type ( ValueType::Array ), _aryValue ( list ) {}
=======
Value::Value(const initializer_list<Value> list) : _type ( ValueType::Array ), _aryValue ( list ) {}
>>>>>>> fc06715cdf035e9d87b66c5410867101247fc219
Value::Value ( const Value& other )
Value::Value ( const Value& other )
{
_type = other._type;
switch ( other._type ) {
case ValueType::Int:
_intValue = other._intValue;
break;
case ValueType::Double:
_dobValue = other._dobValue;
break;
case ValueType::Bool:
_bolValue = other._bolValue;
break;
case ValueType::String:
_strValue = other._strValue;
break;
case ValueType::Object:
_objValue = other._objValue;
break;
case ValueType::Array:
_aryValue = other._aryValue;
break;
case ValueType::Null:
default:
break;
case ValueType::Int:
_intValue = other._intValue;
break;
case ValueType::Double:
_dobValue = other._dobValue;
break;
case ValueType::Bool:
_bolValue = other._bolValue;
break;
case ValueType::String:
_strValue = other._strValue;
break;
case ValueType::Object:
_objValue = other._objValue;
break;
case ValueType::Array:
_aryValue = other._aryValue;
break;
case ValueType::Null:
default:
break;
}
}
Value::Value ( Value&& other )
Value::Value ( Value&& other )
{
_type = other._type;
switch ( other._type ) {
case ValueType::Int:
_intValue = other._intValue;
break;
case ValueType::Double:
_dobValue = other._dobValue;
break;
case ValueType::Bool:
_bolValue = other._bolValue;
break;
case ValueType::String:
_strValue = move(other._strValue);
break;
case ValueType::Object:
_objValue = move(other._objValue);
break;
case ValueType::Array:
_aryValue = move(other._aryValue);
break;
case ValueType::Null:
default:
break;
case ValueType::Int:
_intValue = other._intValue;
break;
case ValueType::Double:
_dobValue = other._dobValue;
break;
case ValueType::Bool:
_bolValue = other._bolValue;
break;
case ValueType::String:
_strValue = move ( other._strValue );
break;
case ValueType::Object:
_objValue = move ( other._objValue );
break;
case ValueType::Array:
_aryValue = move ( other._aryValue );
break;
case ValueType::Null:
default:
break;
}
}
Value& Value::operator = (const Value& other )
Value& Value::operator = ( const Value& other )
{
_type = other._type;
switch ( other._type ) {
case ValueType::Int:
_intValue = other._intValue;
break;
case ValueType::Double:
_dobValue = other._dobValue;
break;
case ValueType::Bool:
_bolValue = other._bolValue;
break;
case ValueType::String:
_strValue = other._strValue;
break;
case ValueType::Object:
_objValue = other._objValue;
break;
case ValueType::Array:
_aryValue = other._aryValue;
break;
case ValueType::Null:
default:
break;
case ValueType::Int:
_intValue = other._intValue;
break;
case ValueType::Double:
_dobValue = other._dobValue;
break;
case ValueType::Bool:
_bolValue = other._bolValue;
break;
case ValueType::String:
_strValue = other._strValue;
break;
case ValueType::Object:
_objValue = other._objValue;
break;
case ValueType::Array:
_aryValue = other._aryValue;
break;
case ValueType::Null:
default:
break;
}
return *this;
}
......@@ -123,94 +129,115 @@ Value& Value::operator = ( Value&& other )
{
_type = other._type;
switch ( other._type ) {
case ValueType::Int:
_intValue = move(other._intValue);
break;
case ValueType::Double:
_dobValue = move(other._dobValue);
break;
case ValueType::Bool:
_bolValue = move(other._bolValue);
break;
case ValueType::String:
_strValue = move(other._strValue);
break;
case ValueType::Object:
_objValue = move(other._objValue);
break;
case ValueType::Array:
_aryValue = move(other._aryValue);
break;
case ValueType::Null:
default:
break;
case ValueType::Int:
_intValue = move ( other._intValue );
break;
case ValueType::Double:
_dobValue = move ( other._dobValue );
break;
case ValueType::Bool:
_bolValue = move ( other._bolValue );
break;
case ValueType::String:
_strValue = move ( other._strValue );
break;
case ValueType::Object:
_objValue = move ( other._objValue );
break;
case ValueType::Array:
_aryValue = move ( other._aryValue );
break;
case ValueType::Null:
default:
break;
}
return *this;
}
Value& Value::operator[](const std::string& key)
Value& Value::operator[] ( const std::string& key )
{
if ( _type == ValueType::Null ){
if ( _type == ValueType::Null ) {
_type = ValueType::Object;
}
if ( _type != ValueType::Object )
throw std::string ("Item is no Object");
throw std::string ( "Item is no Object" );
return _objValue[key];
}
Value& Value::operator[](const int key)
const Value& Value::operator[] ( const std::string& key ) const
{
if ( _type != ValueType::Object )
throw std::string ( "Item is no Object" );
try {
return _objValue.at ( key );
} catch ( const std::out_of_range& oor ) {
//std::cerr << "Out of Range error (" << key << "): " << oor.what() << '\n';
return *this;
}
}
Value& Value::operator[] ( const int key )
{
if ( _type != ValueType::Array )
throw std::string ("Item is no Array");
throw std::string ( "Item is no Array" );
return _aryValue[key];
}
const Value& Value::operator[] ( const int key ) const
{
if ( _type != ValueType::Array )
throw std::string ( "Item is no Array" );
return _aryValue[key];
}
ValueType Value::type()
ValueType Value::type() const
{
return _type;
}
int Value::toInt()
int Value::toInt() const
{
return _intValue;
}
double Value::toDouble()
double Value::toDouble() const
{
return _dobValue;
}
std::string& Value::toString()
const std::string& Value::toString() const
{
return _strValue;
}
bool Value::toBool()
bool Value::toBool() const
{
return _bolValue;
}
Array Value::toArray()
Array Value::toArray() const
{
return _aryValue;
}
Object Value::toObject()
Object Value::toObject() const
{
return _objValue;
}
static unsigned int indentLvl = 0;
inline static void indent(std::ostream& os)
inline static void indent ( std::ostream& os )
{
for ( auto indentIdx = 0u ; indentIdx < indentLvl; indentIdx++ ) {
os << "\t";
os << "\t";
}
}
......@@ -218,17 +245,17 @@ std::ostream& operator<< ( std::ostream& os, const Object& obj )
{
os << "{" << std::endl;
indentLvl++;
for ( auto item = obj.begin() ; item != obj.end(); ) {
indent(os);
indent ( os );
os << "\"" + item->first + "\":" << item->second;
if ( ++item != obj.end() )
os << "," << std::endl;
}
os << std::endl;
indentLvl--;
indent(os);
indent ( os );
os << "}";
return os;
......@@ -250,29 +277,29 @@ std::ostream & operator<< ( std::ostream & os, const Array& array )
std::ostream & operator<< ( std::ostream & os, const Value& val )
{
switch ( val._type ) {
case ValueType::Int:
os << val._intValue;
break;
case ValueType::Double:
os << val._dobValue;
break;
case ValueType::Bool:
os << ( val._bolValue?"true":"false" );
break;
case ValueType::String:
os << "\"" + val._strValue + "\"";
break;
case ValueType::Object:
os << val._objValue;
break;
case ValueType::Array:
os << val._aryValue;
break;
case ValueType::Null:
os << "null";
break;
default:
break;
case ValueType::Int:
os << val._intValue;
break;
case ValueType::Double:
os << val._dobValue;
break;
case ValueType::Bool:
os << ( val._bolValue?"true":"false" );
break;
case ValueType::String:
os << "\"" + val._strValue + "\"";
break;
case ValueType::Object:
os << val._objValue;
break;
case ValueType::Array:
os << val._aryValue;
break;
case ValueType::Null:
os << "null";
break;
default:
break;
}
return os;
}
......