rework of suite and unit
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
#include "Unit.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
Unit::Unit() {}
|
||||
Unit::Unit( Json::Value loader_root )
|
||||
/*
|
||||
* Constructor for Unit type. Receives a UnitHolder loader_root.
|
||||
*/
|
||||
{
|
||||
this->load_root( loader_root );
|
||||
}
|
||||
|
||||
int Unit::load_root(Json::Value loader_root)
|
||||
{
|
||||
@@ -22,9 +17,41 @@ int Unit::load_root(Json::Value loader_root)
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
/*
|
||||
* getters for Unit type.
|
||||
*/
|
||||
|
||||
// TODO CHANGE HOW THIS WORKS
|
||||
int Unit::load_string(std::string json_val)
|
||||
{
|
||||
// reads from a string into a Json::Value type.
|
||||
Json::Reader json_reader;
|
||||
|
||||
// the deserialized json type to contain what's read by the reader
|
||||
Json::Value serialized;
|
||||
|
||||
// create the ifstream file handle for the parser method to consume
|
||||
std::ifstream json_file_ifstream( json_val.c_str(), std::ifstream::binary );
|
||||
|
||||
// use the reader to parse the ifstream to the local property
|
||||
bool parsingSuccessful = json_reader.parse( json_file_ifstream, serialized );
|
||||
|
||||
if (! parsingSuccessful )
|
||||
{
|
||||
std::cerr << "Failed to parse adhoc JSON value." << std::endl << json_val << std::endl << std::endl << json_reader.getFormattedErrorMessages();
|
||||
throw JSON_Loader_InvalidJSON();
|
||||
|
||||
} else {
|
||||
// if in verbose mode, give the user an "it worked" message
|
||||
if ( verbose )
|
||||
{
|
||||
std::cout << "Successfully parsed JSON string with " << this->json_root.size() << " elements. Value:" << std::endl;
|
||||
std::cout << json_val << std::endl << std::endl;
|
||||
}
|
||||
}
|
||||
// exit successfully
|
||||
this->populated = true;
|
||||
}
|
||||
|
||||
|
||||
// getters for Unit type.
|
||||
std::string Unit::get_name()
|
||||
{
|
||||
return this->name;
|
||||
|
||||
Reference in New Issue
Block a user