20 : TNamed(name, name), fValue(value), fPriority(priority)
45double GValue::Value(
const std::string& name,
const double& defaultValue)
56 if(gvalue ==
nullptr) {
57 gvalue =
new GValue(name.c_str(), value, priority);
59 }
else if(priority <= gvalue->
fPriority) {
68 if(name.length() == 0u) {
80 if(strlen(GetName()) != 0u) {
81 oldvalue->SetName(GetName());
109 if(value ==
nullptr) {
112 std::string temp_string = value->GetName();
113 if(temp_string.empty()) {
120 if(oldvalue !=
nullptr) {
133 buffer.append(GetName());
134 buffer.append(
"\t{\n");
135 buffer.append(Form(
"value:\t%f\n",
fValue));
137 buffer.append(
"info:\t");
141 buffer.append(
"}\n");
153 if(filename.length() != 0u) {
154 std::ofstream outfile;
155 outfile.open(filename.c_str());
156 if(!outfile.is_open()) {
160 outfile << iter.second->PrintToString() << std::endl
165 std::cout << iter.second->PrintToString() << std::endl
179 buffer.append(iter.second->PrintToString());
197 std::string infilename = filename;
198 if(infilename.length() == 0) {
202 std::ifstream infile;
203 infile.open(infilename.c_str());
205 std::cerr << __PRETTY_FUNCTION__ <<
": could not open infile " << infilename << std::endl;
208 infile.seekg(0, std::ios::end);
209 size_t length = infile.tellg();
211 std::cerr << __PRETTY_FUNCTION__ <<
": infile " << infilename <<
" appears to be empty." << std::endl;
216 std::vector<char> buffer(length);
217 infile.seekg(0, std::ios::beg);
218 infile.read(buffer.data(),
static_cast<int>(length));
219 sbuffer.assign(buffer.data());
233 std::istringstream infile(input);
239 bool brace_open =
false;
242 while(!std::getline(infile, line).fail()) {
245 size_t comment = line.find(
"//");
246 if(comment != std::string::npos) {
247 line = line.substr(0, comment);
249 if(line.length() == 0) {
252 size_t openbrace = line.find(
'{');
253 size_t closebrace = line.find(
'}');
254 size_t colon = line.find(
':');
257 if(openbrace == std::string::npos && closebrace == std::string::npos && colon == std::string::npos) {
261 if(openbrace != std::string::npos) {
263 name = line.substr(0, openbrace);
265 value =
new GValue(name.c_str());
269 if(colon != std::string::npos) {
271 if(openbrace == std::string::npos || openbrace > colon) {
272 type = line.substr(0, colon);
274 type = line.substr(openbrace + 1, colon - (openbrace + 1));
276 line = line.substr(colon + 1, line.length());
279 std::transform(type.begin(), type.end(), type.begin(), ::toupper);
281 value->SetName(line.c_str());
282 }
else if(type ==
"VALUE") {
283 value->
SetValue(std::atof(line.c_str()));
285 }
else if(type ==
"INFO") {
291 if(closebrace != std::string::npos) {
293 if(value !=
nullptr) {
296 if(cur_value ==
nullptr) {
309 if(strcmp(opt,
"debug") == 0) {
310 std::cout <<
"parsed " << linenumber <<
" lines" << std::endl;
315void GValue::Streamer(TBuffer& R__b)
320 if(R__b.IsReading()) {
321 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
322 TNamed::Streamer(R__b);
327 R__str.Streamer(R__b);
330 R__b.CheckByteCount(R__s, R__c, GValue::IsA());
332 R__c = R__b.WriteVersion(GValue::IsA(),
true);
333 TNamed::Streamer(R__b);
336 R__str.Streamer(R__b);
338 R__b.SetByteCount(R__c,
true);
void trim(std::string &line, const std::string &trimChars=" \f\n\r\t\v")
static GValue * fDefaultValue
static bool AddValue(GValue *, Option_t *opt="")
static void SetReplaceValue(const std::string &name, double value, EPriority priority=EPriority::kUser)
void SetValue(double value)
static std::map< std::string, GValue * > fValueVector
static int ReadValFile(const char *filename="", Option_t *opt="replace")
void Copy(TObject &obj) const override
const char * GetInfo() const
bool ReplaceValue(GValue *)
static int WriteValFile(const std::string &filename="", Option_t *opt="")
static GValue * FindValue(const std::string &="")
bool AppendValue(GValue *)
static int ParseInputData(const std::string &input, EPriority priority, Option_t *opt="")
static GValue * GetDefaultValue()
static std::string WriteToBuffer(Option_t *opt="")
static double Value(const std::string &)
void SetInfo(const char *temp)
std::string PrintToString() const
void Print(Option_t *opt="") const override