/* This file shows how GVars2 used to work. Now this functionality is provided by GVars3 via the GVars2.h compatibility wrapper. This file is part of the GVars3 Library. Copyright (C) 2005 The Authors This library is free software, see LICENSE file for details */ #ifndef __GVARS_2_H #define __GVARS_2_H #include #include #include using namespace std; template class gvar2 { friend class GVars2; public: gvar2() {datapointer_ptr=NULL;}; inline T& operator*() {return **datapointer_ptr;}; void SafeSet(T tNewVal); // This swaps pointer, which is assumed to be atomic. // Use this if setting vects, matrices or strings in threaded environments. private: T **datapointer_ptr; static const T tDefaultVal; static const int nTypeNum; }; typedef gvar2< Vector<> > gvar2_Vector; typedef gvar2< Matrix<> > gvar2_Matrix; typedef gvar2 gvar2_double; typedef gvar2 gvar2_string; typedef gvar2 gvar2_int; enum GVar2Type {gvar2_int_Type, gvar2_double_Type, gvar2_string_Type, gvar2_Vector_Type, gvar2_Matrix_Type}; struct GVar2PointerElement { void* datapointer; string* psName; GVar2Type nType; }; class GVars2 { public: GVars2(); void Register(gvar2_string& gv2, string sName, string sDefault, bool bSilent =false ); template void Register(gvar2& gv2, string sName, string sDefault, bool bSilent = false ); template void Register(gvar2& gv2, string sName, T tDefault=DefaultForType(), bool bSilent = false ); void SetVar(string sVar, string sValue); void SetVar(string s); int GetInt(string sName, int nDefault=0, bool bSilent = false); double GetDouble(string sName, double dDefault=0.0, bool bSilent = false); string GetString(string sName, string sDefault="", bool bSilent = false); Vector<> GetVector(string sName, Vector<> vDefault=(Vector<1>)((double[]){0}), bool bSilent = false); Matrix<> GetMatrix(string sName, Matrix<> mDefault=(Matrix<1>)((double[]){0}), bool bSilent = false); int GetInt(string sName, string sDefault, bool bSilent = false); double GetDouble(string sName, string sDefault, bool bSilent = false); Vector<> GetVector(string sName, string sDefault, bool bSilent = false); Matrix<> GetMatrix(string sName, string sDefault, bool bSilent = false); void Load(string sFileName); void PrintVarList(ostream& os=cout); void PrintVar(string s, ostream& os, bool bEndl = true); string StringValue(const string &sVarName, bool bNoQuotes=false); char* ReadlineCommandGenerator(const char *szText, int nState); private: template void ReallyRegister(gvar2& gv2, string sName, T tDefault, bool bSilent=false); template void SetRegisteredVar(string sVar, GVar2PointerElement *pgvpe, string sValue); template static string TypeName(); template static GVar2Type WhatType(); template static T DefaultForType(); // template T* ParseAndAllocate(string s); // Now in GStringUtil.h map mUnmatchedTags; map mRegisteredTags; }; #endif