Commit f5432bef authored by Karl Herbig's avatar Karl Herbig

Fix const-ness + code formating

parent 0f2552ad
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="JsonPP" InternalType="Library">
<CodeLite_Project Name="JsonPP" InternalType="Library" Version="10.0.0">
<Plugins>
<Plugin Name="qmake">
<![CDATA[00020001N0005Debug0000000000000001N0007Release000000000000]]>
<![CDATA[00040001N0005Debug0000000000000001N0007Release0000000000000001N0019Release_RaspberryPi0000000000000001N0014Release_Ubuntu000000000000]]>
</Plugin>
</Plugins>
<Description/>
......@@ -25,6 +25,51 @@
</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">
<Compiler Options="-pedantic-errors;-Wfatal-errors;-g;-O0;-pedantic;-W;-std=c++11;-Wall;-fPIC" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
<IncludePath Value="../../include"/>
</Compiler>
<Linker Options="" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName).so" IntermediateDirectory="./Release" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="yes">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild>
<Command Enabled="yes">cp Release/JsonPP.so /opt/lib/pi</Command>
<Command Enabled="yes">cp ../../include/JsonPP.h /opt/include</Command>
<Command Enabled="yes">cp ../../include/Value.h /opt/include</Command>
<Command Enabled="yes">sshpass -p "raspberry" scp Release/JsonPP.so pi@200.150.100.85:/opt/lib/pi</Command>
</PostBuild>
<CustomBuild Enabled="no">
<RebuildCommand/>
<CleanCommand/>
<BuildCommand/>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName/>
<WorkingDirectory/>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
<Configuration Name="Release_Ubuntu" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-O1;-O;-O0;-O2;-std=c++14;-Wall;-fPIC" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
......@@ -33,6 +78,7 @@
<Linker Options="-Os" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="$(IntermediateDirectory)/$(ProjectName).so" IntermediateDirectory="./Release" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<BuildSystem Name="Default"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
......@@ -42,7 +88,11 @@
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<PostBuild>
<Command Enabled="yes">cp Release/JsonPP.so /opt/lib</Command>
<Command Enabled="yes">cp ../../include/JsonPP.h /opt/include</Command>
<Command Enabled="yes">cp ../../include/Value.h /opt/include</Command>
</PostBuild>
<CustomBuild Enabled="no">
<RebuildCommand/>
<CleanCommand/>
......
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="JsonPP" Database="">
<CodeLite_Workspace Name="JsonPP" Database="" Version="10.0.0">
<Project Name="JsonPP" Path="JsonPP.project" Active="Yes"/>
<BuildMatrix>
<WorkspaceConfiguration Name="Release_Ubuntu" Selected="yes">
<Environment/>
<Project Name="JsonPP" ConfigName="Release_Ubuntu"/>
</WorkspaceConfiguration>
<WorkspaceConfiguration Name="Release_RaspberryPi" Selected="no">
<Environment/>
<Project Name="JsonPP" ConfigName="Release_RaspberryPi"/>
</WorkspaceConfiguration>
</BuildMatrix>
</CodeLite_Workspace>
......@@ -10,7 +10,6 @@ namespace Json {
class JsonPP
{
JsonPP();
static Value arrayFromString(std::string jsonArrayString);
public:
static Value objectFromString(std::string jsonString);
......
......@@ -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;
};
}
......
......@@ -455,7 +455,7 @@ Value JsonPP::objectFromString(std::string jsonString)
std::string JsonPP::stringFromObject ( Object& jsonObject )
{
auto jss = std::stringstream {};
std::stringstream jss;
jss << jsonObject;
return jss.str();
}
......
......@@ -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,99 @@ 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 np ) : _type ( ValueType::Null ) {}
Value::Value(const initializer_list<Value> list) : _type ( ValueType::Array ), _aryValue ( list ) {};
Value::Value ( const initializer_list<Value> list ) : _type ( ValueType::Array ), _aryValue ( list ) {}
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 +125,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 +241,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 +273,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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment