Debian Codegraph @

GVars2.h.historic

raw
1 /*
2 This file shows how GVars2 used to work. Now this functionality is provided by GVars3
3 via the GVars2.h compatibility wrapper.
4
5 This file is part of the GVars3 Library.
6
7 Copyright (C) 2005 The Authors
8
9 This library is free software, see LICENSE file for details
10 */
11
12 #ifndef __GVARS_2_H
13 #define __GVARS_2_H
14
15 #include <string>
16 #include <map>
17 #include <numerics.h>
18
19 using namespace std;
20
21 template <class T> class gvar2
22 {
23 friend class GVars2;
24 public:
25 gvar2() {datapointer_ptr=NULL;};
26 inline T& operator*() {return **datapointer_ptr;};
27 void SafeSet(T tNewVal); // This swaps pointer, which is assumed to be atomic.
28 // Use this if setting vects, matrices or strings in threaded environments.
29 private:
30 T **datapointer_ptr;
31 static const T tDefaultVal;
32 static const int nTypeNum;
33 };
34
35
36 typedef gvar2< Vector<> > gvar2_Vector;
37 typedef gvar2< Matrix<> > gvar2_Matrix;
38 typedef gvar2<double> gvar2_double;
39 typedef gvar2<std::string> gvar2_string;
40 typedef gvar2<int> gvar2_int;
41
42
43 enum GVar2Type {gvar2_int_Type,
44 gvar2_double_Type,
45 gvar2_string_Type,
46 gvar2_Vector_Type,
47 gvar2_Matrix_Type};
48
49
50 struct GVar2PointerElement
51 {
52 void* datapointer;
53 string* psName;
54 GVar2Type nType;
55 };
56
57
58
59
60
61 class GVars2
62 {
63 public:
64 GVars2();
65 void Register(gvar2_string& gv2, string sName, string sDefault, bool bSilent =false );
66 template <class T> void Register(gvar2<T>& gv2, string sName, string sDefault, bool bSilent = false );
67 template <class T> void Register(gvar2<T>& gv2, string sName, T tDefault=DefaultForType<T>(), bool bSilent = false );
68
69 void SetVar(string sVar, string sValue);
70 void SetVar(string s);
71
72
73 int GetInt(string sName, int nDefault=0, bool bSilent = false);
74 double GetDouble(string sName, double dDefault=0.0, bool bSilent = false);
75 string GetString(string sName, string sDefault="", bool bSilent = false);
76 Vector<> GetVector(string sName, Vector<> vDefault=(Vector<1>)((double[]){0}), bool bSilent = false);
77 Matrix<> GetMatrix(string sName, Matrix<> mDefault=(Matrix<1>)((double[]){0}), bool bSilent = false);
78
79 int GetInt(string sName, string sDefault, bool bSilent = false);
80 double GetDouble(string sName, string sDefault, bool bSilent = false);
81 Vector<> GetVector(string sName, string sDefault, bool bSilent = false);
82 Matrix<> GetMatrix(string sName, string sDefault, bool bSilent = false);
83
84 void Load(string sFileName);
85
86 void PrintVarList(ostream& os=cout);
87 void PrintVar(string s, ostream& os, bool bEndl = true);
88
89 string StringValue(const string &sVarName, bool bNoQuotes=false);
90
91
92 char* ReadlineCommandGenerator(const char *szText, int nState);
93
94 private:
95 template <class T> void ReallyRegister(gvar2<T>& gv2, string sName, T tDefault, bool bSilent=false);
96
97 template <class T> void SetRegisteredVar(string sVar, GVar2PointerElement *pgvpe, string sValue);
98
99 template <class T> static string TypeName();
100 template <class T> static GVar2Type WhatType();
101 template <class T> static T DefaultForType();
102
103 // template <class T> T* ParseAndAllocate(string s); // Now in GStringUtil.h
104
105 map<string,string> mUnmatchedTags;
106 map<string,GVar2PointerElement*> mRegisteredTags;
107
108
109 };
110
111
112
113 #endif
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134