Skip to content
Snippets Groups Projects

Add a GUI

Merged Chao Peng requested to merge gui into master
35 files
+ 3147
381
Compare changes
  • Side-by-side
  • Inline
Files
35
@@ -9,6 +9,7 @@
@@ -9,6 +9,7 @@
// 10/31/2016 //
// 10/31/2016 //
//============================================================================//
//============================================================================//
 
#include <cstdlib>
#include <fstream>
#include <fstream>
#include <iostream>
#include <iostream>
#include <iomanip>
#include <iomanip>
@@ -16,7 +17,6 @@
@@ -16,7 +17,6 @@
#include "ConfigObject.h"
#include "ConfigObject.h"
//============================================================================//
//============================================================================//
// Constructor, Destructor //
// Constructor, Destructor //
//============================================================================//
//============================================================================//
@@ -26,7 +26,7 @@ ConfigObject::ConfigObject(const std::string &splitter, const std::string &ignor
@@ -26,7 +26,7 @@ ConfigObject::ConfigObject(const std::string &splitter, const std::string &ignor
: split_chars(splitter), ignore_chars(ignore), case_insensitive(case_ins), __empty_value("")
: split_chars(splitter), ignore_chars(ignore), case_insensitive(case_ins), __empty_value("")
{
{
// set default replace bracket
// set default replace bracket
replace_pair = std::make_pair("{", "}");
replace_pair = std::make_pair("${", "}");
}
}
// destructor
// destructor
@@ -79,36 +79,33 @@ bool ConfigObject::ReadConfigFile(const std::string &path)
@@ -79,36 +79,33 @@ bool ConfigObject::ReadConfigFile(const std::string &path)
}
}
// read the configuration string directly
// read the configuration string directly
void ConfigObject::ReadConfigString(const std::string &content)
void ConfigObject::ReadConfigString(const std::string &content, const std::string &path)
{
{
ConfigParser c_parser;
ConfigParser c_parser;
c_parser.SetSplitters(split_chars);
c_parser.SetSplitters(split_chars);
c_parser.ReadBuffer(content.c_str());
c_parser.ReadBuffer(content.c_str());
parserProcess(c_parser, "buffer_string");
parserProcess(c_parser, path);
}
}
// continue parse the terms
// continue parse the terms
void ConfigObject::parserProcess(ConfigParser &c_parser, const std::string &source)
void ConfigObject::parserProcess(ConfigParser &c_parser, const std::string &source)
{
{
std::string cur_dir = ConfigParser::decompose_path(source).dir;
char abs_path[2048];
 
realpath(source.c_str(), abs_path);
 
std::string cur_dir = ConfigParser::decompose_path(abs_path).dir;
 
SetConfigValue("THIS_DIR", cur_dir);
while (c_parser.ParseLine()) {
while (c_parser.ParseLine()) {
// possible control words
// possible control words
if (c_parser.NbofElements() == 1) {
if (c_parser.NbofElements() == 1) {
std::string control = c_parser.TakeFirst();
std::string control = c_parser.TakeFirst();
size_t pos = control.find("{THIS_DIR}");
if(pos != std::string::npos)
control.replace(pos, 10, cur_dir);
parseControl(control);
parseControl(control);
// var_name and var_value
// var_name and var_value
} else if (c_parser.NbofElements() == 2) {
} else if (c_parser.NbofElements() == 2) {
std::string var_name, key, var_value;
std::string var_name, key, var_value;
c_parser >> var_name >> var_value;
c_parser >> var_name >> var_value;
size_t pos = var_value.find("{THIS_DIR}");
if(pos != std::string::npos)
var_value.replace(pos, 10, cur_dir);
parseTerm(std::move(var_name), std::move(var_value));
parseTerm(std::move(var_name), std::move(var_value));
// unsupported format
// unsupported format
} else {
} else {
@@ -258,17 +255,7 @@ const
@@ -258,17 +255,7 @@ const
reform(var, op, cl);
reform(var, op, cl);
// replace content
// replace content
std::string val;
std::string val = HasKey(var) ? GetConfigValue(var)._value : std::getenv(var.c_str());
// environment variable
if (rpair.first > 0 && input.at(rpair.first - 1) == '$') {
val = std::getenv(var.c_str());
// replace $ mark also
rpair.first--;
// ConfigObject variable
} else {
val = GetConfigValue(var)._value;
}
// replace variable with configuration value
// replace variable with configuration value
input.replace(rpair.first, rpair.second - rpair.first + cl.size(), val);
input.replace(rpair.first, rpair.second - rpair.first + cl.size(), val);
Loading