fixed units and unit collection type, kinda
This commit is contained in:
@@ -1,15 +1,6 @@
|
||||
//
|
||||
// Created by phanes on 4/16/17.
|
||||
//
|
||||
|
||||
#include "loaders.h"
|
||||
#include "json/json.h"
|
||||
#include "json/json-forwards.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
inline bool exists(const std::string& name)
|
||||
{
|
||||
struct stat buffer;
|
||||
@@ -33,7 +24,7 @@ JLoader::JLoader( std::string filename )
|
||||
if (! parsingSuccessful )
|
||||
{
|
||||
std::cerr << "Failed to parse " << filename << ":\n\t" << reader.getFormattedErrorMessages();
|
||||
exit(1);
|
||||
exit( 1 );
|
||||
} else {
|
||||
std::cout << "Parsed " << filename << " with " << this->json_root.size() << " elements." << std::endl;
|
||||
}
|
||||
@@ -44,15 +35,40 @@ Json::Value JLoader::get_root()
|
||||
return this->json_root;
|
||||
}
|
||||
|
||||
|
||||
Unit::Unit( std::string filename ): JLoader( filename )
|
||||
Unit::Unit( Json::Value loader_root )
|
||||
{
|
||||
this->name = loader_root.get("name", "?").asString();
|
||||
this->target = loader_root.get("target", "?").asString();
|
||||
this->output = loader_root.get("output", "?").asString();
|
||||
this->rectifier = loader_root.get("rectifier", "?").asString();
|
||||
this->active = loader_root.get("active", "?").asString();
|
||||
this->required = loader_root.get("required", "?").asString();
|
||||
this->rectify = loader_root.get("rectify", "?").asString();
|
||||
}
|
||||
std::string Unit::get_name() { return this->name; }
|
||||
std::string Unit::get_target() { return this->target; }
|
||||
std::string Unit::get_output() { return this->output; }
|
||||
std::string Unit::get_rectifier() { return this->rectifier; }
|
||||
std::string Unit::get_active() { return this->active; }
|
||||
std::string Unit::get_required() { return this->required; }
|
||||
std::string Unit::get_rectify() { return this->rectify; }
|
||||
|
||||
UnitHolder::UnitHolder( std::string filename ): JLoader( filename )
|
||||
{
|
||||
/* UnitHolder loads a file and deserializes the Unit JSON object to Unit types as a vector member
|
||||
* UnitHolder { vector<Unit> }
|
||||
*/
|
||||
Json::Value raw_units = this->get_root()["units"];
|
||||
|
||||
for ( int index = 0; index < raw_units.size(); index++ )
|
||||
{
|
||||
this->Units.push_back(Unit( raw_units[index] ));
|
||||
}
|
||||
};
|
||||
|
||||
Plan::Plan( std::string filename ): JLoader( filename )
|
||||
{
|
||||
|
||||
// TODO: Implement
|
||||
};
|
||||
|
||||
Conf::Conf( std::string filename ): JLoader( filename )
|
||||
|
||||
@@ -22,29 +22,48 @@ class JLoader
|
||||
Json::Value get_root();
|
||||
};
|
||||
|
||||
class Unit: public JLoader
|
||||
class Unit
|
||||
{
|
||||
private:
|
||||
Json::Value json_root;
|
||||
std::string name;
|
||||
std::string target;
|
||||
std::string output;
|
||||
std::string rectifier;
|
||||
std::string active;
|
||||
std::string required;
|
||||
std::string rectify;
|
||||
|
||||
public:
|
||||
Unit( Json::Value loader_root );
|
||||
std::string get_name();
|
||||
std::string get_target();
|
||||
std::string get_output();
|
||||
std::string get_rectifier();
|
||||
std::string get_active();
|
||||
std::string get_required();
|
||||
std::string get_rectify();
|
||||
};
|
||||
|
||||
class UnitHolder: public JLoader
|
||||
{
|
||||
private:
|
||||
std::vector<Unit> Units;
|
||||
|
||||
public:
|
||||
using JLoader::JLoader;
|
||||
Unit( std::string filename );
|
||||
UnitHolder( std::string filename );
|
||||
};
|
||||
|
||||
class Plan: public JLoader
|
||||
{
|
||||
private:
|
||||
Json::Value json_root;
|
||||
public:
|
||||
using JLoader::JLoader;
|
||||
Plan( std::string filename );
|
||||
};
|
||||
|
||||
|
||||
class Conf: public JLoader
|
||||
{
|
||||
private:
|
||||
Json::Value json_root;
|
||||
std::string plan_path;
|
||||
std::string units_path;
|
||||
|
||||
@@ -55,5 +74,4 @@ class Conf: public JLoader
|
||||
std::string get_units_path();
|
||||
};
|
||||
|
||||
|
||||
#endif //FTESTS_LOADERS_H
|
||||
|
||||
Reference in New Issue
Block a user