Skip to content

Commit

Permalink
Use nlohmann json parser
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesBremner committed Mar 6, 2017
1 parent 98fa66b commit 46a5002
Show file tree
Hide file tree
Showing 6 changed files with 13,067 additions and 1,819 deletions.
5 changes: 3 additions & 2 deletions schedule.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
<Unit filename="src/cSchedule.h" />
<Unit filename="src/cShop.cpp" />
<Unit filename="src/cShop.h" />
<Unit filename="src/ext/json.cpp" />
<Unit filename="src/ext/json.h" />
<Unit filename="src/ext/json.hpp" />
<Unit filename="src/ext/nlohmann_json.cpp" />
<Unit filename="src/ext/nlohmann_json.hpp" />
<Extensions>
<code_completion />
<envvars />
Expand Down
21 changes: 13 additions & 8 deletions src/cSchedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ cStep::cStep( string name, string machine, float time )



json::Object cStep::json()
nlohmann::json cStep::json()
{
json::Object j;
nlohmann::json j;
j["name"] = myName;
j["machine"] = myMachine;
j["time"] = myTime;
Expand All @@ -30,9 +30,9 @@ json::Object cStep::json()
return j;
}

json::Object cJob::json()
nlohmann::json cJob::json()
{
json::Object j;
nlohmann::json j;
j["name"] = myName;
j["earliest"] = myEarliestStart;
switch( myType )
Expand All @@ -44,7 +44,7 @@ json::Object cJob::json()
j["type"] = "anyone";
break;
}
json::Array steps;
nlohmann::json steps;
for( auto& s : myStep )
{
steps.push_back( s.json() );
Expand Down Expand Up @@ -80,16 +80,21 @@ void cJob::AddSteps( vector< cStep >& vStep )
vStep.push_back( s );
}
}


string cSchedule::json()
{
json::Object s;
json::Array ja;

nlohmann::json s;
nlohmann::json ja;
for( auto& j : myJob )
{
ja.push_back( j.json() );
}
s["jobs"] = ja;
return json::Serialize( s );
string ret;
ret = s.dump();
return ret;
}

void cSchedule::Steps( vector< cStep >& vStep )
Expand Down
7 changes: 4 additions & 3 deletions src/cSchedule.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <iostream>
#include <vector>
#include "json.h"

#include "nlohmann_json.hpp"

using namespace std;

Expand Down Expand Up @@ -48,7 +49,7 @@ class cStep
}

/** Output the step in JSON format */
json::Object json();
nlohmann::json json();

/** Name of machine used to process step */
string Machine() const
Expand Down Expand Up @@ -156,7 +157,7 @@ class cJob
float time );

/** Job in JSON format */
json::Object json();
nlohmann::json json();

/** Steps in the job
@return new vector containing steps in this job
Expand Down

0 comments on commit 46a5002

Please sign in to comment.