19 : TNamed(name, name), fValue(value), fPriority(priority)
44double GValue::Value(
const std::string& name,
const double& defaultValue)
55 if(gvalue ==
nullptr) {
56 gvalue =
new GValue(name.c_str(), value, priority);
58 }
else if(priority <= gvalue->
fPriority) {
67 if(name.length() == 0u) {
79 if(strlen(GetName()) != 0u) {
80 oldvalue->SetName(GetName());
108 if(value ==
nullptr) {
111 std::string temp_string = value->GetName();
112 if(temp_string.empty()) {
119 if(oldvalue !=
nullptr) {
132 buffer.append(GetName());
133 buffer.append(
"\t{\n");
134 buffer.append(Form(
"value:\t%f\n",
fValue));
136 buffer.append(
"info:\t");
140 buffer.append(
"}\n");
152 if(filename.length() != 0u) {
153 std::ofstream outfile;
154 outfile.open(filename.c_str());
155 if(!outfile.is_open()) {
159 outfile << iter.second->PrintToString() << std::endl
164 std::cout << iter.second->PrintToString() << std::endl
178 buffer.append(iter.second->PrintToString());
196 std::string infilename = filename;
197 if(infilename.length() == 0) {
201 std::ifstream infile;
202 infile.open(infilename.c_str());
204 std::cerr << __PRETTY_FUNCTION__ <<
": could not open infile " << infilename << std::endl;
207 infile.seekg(0, std::ios::end);
208 size_t length = infile.tellg();
210 std::cerr << __PRETTY_FUNCTION__ <<
": infile " << infilename <<
" appears to be empty." << std::endl;
215 std::vector<char> buffer(length);
216 infile.seekg(0, std::ios::beg);
217 infile.read(buffer.data(),
static_cast<int>(length));
218 sbuffer.assign(buffer.data());
232 std::istringstream infile(input);
238 bool brace_open =
false;
241 while(!std::getline(infile, line).fail()) {
244 size_t comment = line.find(
"//");
245 if(comment != std::string::npos) {
246 line = line.substr(0, comment);
248 if(line.length() == 0) {
251 size_t openbrace = line.find(
'{');
252 size_t closebrace = line.find(
'}');
253 size_t colon = line.find(
':');
256 if(openbrace == std::string::npos && closebrace == std::string::npos && colon == std::string::npos) {
260 if(openbrace != std::string::npos) {
262 name = line.substr(0, openbrace);
264 value =
new GValue(name.c_str());
268 if(colon != std::string::npos) {
270 if(openbrace == std::string::npos || openbrace > colon) {
271 type = line.substr(0, colon);
273 type = line.substr(openbrace + 1, colon - (openbrace + 1));
275 line = line.substr(colon + 1, line.length());
278 std::transform(type.begin(), type.end(), type.begin(), ::toupper);
280 value->SetName(line.c_str());
281 }
else if(type ==
"VALUE") {
282 value->
SetValue(std::atof(line.c_str()));
284 }
else if(type ==
"INFO") {
290 if(closebrace != std::string::npos) {
292 if(value !=
nullptr) {
295 if(cur_value ==
nullptr) {
308 if(strcmp(opt,
"debug") == 0) {
309 std::cout <<
"parsed " << linenumber <<
" lines" << std::endl;
314void GValue::Streamer(TBuffer& R__b)
319 if(R__b.IsReading()) {
320 Version_t R__v = R__b.ReadVersion(&R__s, &R__c);
321 TNamed::Streamer(R__b);
326 R__str.Streamer(R__b);
329 R__b.CheckByteCount(R__s, R__c, GValue::IsA());
331 R__c = R__b.WriteVersion(GValue::IsA(),
true);
332 TNamed::Streamer(R__b);
335 R__str.Streamer(R__b);
337 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