| 1 | /* |
| 2 | This file is part of the GVars3 Library. |
| 3 | |
| 4 | Copyright (C) 2005 The Authors |
| 5 | |
| 6 | This library is free software, see LICENSE file for details |
| 7 | */ |
| 8 | |
| 9 | #include "gvars3/gvars3.h" |
| 10 | |
| 11 | using namespace std; |
| 12 | |
| 13 | |
| 14 | namespace GVars3 |
| 15 | { |
| 16 | void GVars2::SetVar(std::string sVar, std::string sValue, bool s) |
| 17 | { |
| 18 | GV3::set_var(sVar, sValue, s); |
| 19 | } |
| 20 | |
| 21 | |
| 22 | void GVars2::SetVar(std::string s) |
| 23 | { |
| 24 | // Expected format: "foo = bar" |
| 25 | // So crack the string in two at the equals sign. Easy. |
| 26 | // SetVar(string,string) is quite tolerant to whitespace. |
| 27 | |
| 28 | string::size_type n; |
| 29 | n=s.find("="); |
| 30 | if(n>=s.find("//")) // Perhaps the line is a comment? |
| 31 | return; |
| 32 | if(n==s.npos) |
| 33 | { |
| 34 | cout << "? Gvars::SetVar(string): No equals sign found in \""<<s<<"\""<< endl; |
| 35 | return; |
| 36 | }; |
| 37 | SetVar(s.substr(0,n),s.substr(n+1,s.npos-n)); |
| 38 | } |
| 39 | |
| 40 | int& GVars2::GetInt(const string& name, int default_val, int flags) |
| 41 | { |
| 42 | return Get<int>(name, default_val, flags); |
| 43 | } |
| 44 | |
| 45 | double& GVars2::GetDouble(const string& name, double default_val, int flags) |
| 46 | { |
| 47 | return Get<double>(name, default_val, flags); |
| 48 | } |
| 49 | string& GVars2::GetString(const string& name, const string& default_val, int flags) |
| 50 | { |
| 51 | return Get<string>(name, default_val, flags); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | int& GVars2::GetInt(const string& name, const string& default_val, int flags) |
| 56 | { |
| 57 | return Get<int>(name, default_val, flags); |
| 58 | } |
| 59 | |
| 60 | double& GVars2::GetDouble(const string& name, const string& default_val, int flags) |
| 61 | { |
| 62 | return Get<double>(name, default_val, flags); |
| 63 | } |
| 64 | |
| 65 | string GVars2::StringValue(const string &name, bool no_quotes) |
| 66 | { |
| 67 | if(no_quotes) |
| 68 | return GV3::get_var(name); |
| 69 | else |
| 70 | return "\"" + GV3::get_var(name) + "\""; |
| 71 | } |
| 72 | |
| 73 | void GVars2::PrintVarList(ostream& os) |
| 74 | { |
| 75 | GV3::print_var_list(os); |
| 76 | } |
| 77 | |
| 78 | void GVars2::PrintVar(string s, ostream& os, bool bEndl) |
| 79 | { |
| 80 | os << s << "=" << StringValue(s, true); |
| 81 | if(bEndl) |
| 82 | os << endl; |
| 83 | |
| 84 | } |
| 85 | } |
| 86 |