COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
CoviseConfig.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef CO_COVISE_CONFIG_H
9 #define CO_COVISE_CONFIG_H
10 #include <util/coTypes.h>
11 
12 #include <string>
13 #include <vector>
14 
15 namespace covise
16 {
17 
19 {
20 
21 private:
23  virtual ~coCoviseConfig();
24 
25 public:
26  class ScopeEntries;
27 
28  static std::string getEntry(const std::string &entry, bool *exists = 0);
29  static std::string getEntry(const std::string &variable, const std::string &entry, bool *exists = 0);
30  static std::string getEntry(const std::string &variable, const std::string &entry, const std::string &defaultValue, bool *exists = 0);
31 
32  static int getInt(const std::string &entry, int defaultValue, bool *exists = 0);
33  static int getInt(const std::string &variable, const std::string &entry, int defaultValue, bool *exists = 0);
34 
35  static long getLong(const std::string &entry, long defaultValue, bool *exists = 0);
36  static long getLong(const std::string &variable, const std::string &entry, long defaultValue, bool *exists = 0);
37 
38  static bool isOn(const std::string &entry, bool defaultValue, bool *exists = 0);
39  static bool isOn(const std::string &variable, const std::string &entry, bool defaultValue, bool *exists = 0);
40 
41  // get float value of "Scope.Name"
42  static float getFloat(const std::string &entry, float defaultValue, bool *exists = 0);
43  static float getFloat(const std::string &variable, const std::string &entry, float defaultValue, bool *exists = 0);
44 
45  // retrieve all names of a scope
46  static std::vector<std::string> getScopeNames(const std::string &scope, const std::string &name = "");
47 
48  // retrieve all values of a scope: return 2n+1 arr name/val/name.../val/NULL
49  // ScopeEntries is reference counted, its contents are valid, as long a reference to
50  // the object exists. Thus, do not use getScopeEntries().getValue() directly.
51  static ScopeEntries getScopeEntries(const std::string &scope);
52 
53  // get all entries for one scope/name
54  // ScopeEntries is reference counted, its contents are valid, as long a reference to
55  // the object exists. Thus, do not use getScopeEntries().getValue() directly.
56  static ScopeEntries getScopeEntries(const std::string &scope, const std::string &name);
57 
58  // returns the number of tokens, returns -1 if entry is missing
59  // puts the tokens into token array
60  // examples:
61  // XXXConfig
62  //{
63  // ENTRY1 "aaa" "bbb"
64  // ENTRY2 aaa bbb
65  // ENTRY3 aaa"bbb"
66  //}
67  // returns
68  // for ENTRY1 aaa and bbb
69  // for ENTRY2 aaa and bbb
70  // for entry3 aaabbb
71  // static int getTokens(const char *entry, char **&tokens);
72 
73  template <typename T>
74  class RefPtr
75  {
76 
77  public:
78  RefPtr();
79  RefPtr(const RefPtr<T> &s);
80  RefPtr<T> &operator=(const RefPtr<T> &s);
81 
82  virtual ~RefPtr();
83 
84  T getValue();
85  const T getValue() const;
86 
87  protected:
88  virtual void release();
89 
90  T ptr;
91  unsigned int refCount;
92  };
93 
94  class CONFIGEXPORT ScopeEntries : public RefPtr<const char **>
95  {
96  public:
97  ScopeEntries(const char *scope, const char *name);
98 
99  const char **getValue();
100  const char **getValue() const;
101 
102  ScopeEntries &operator=(const ScopeEntries &s);
103 
104  private:
105  virtual void release();
106  };
107 };
108 
109 template <typename T>
111 {
112  //COCONFIGLOG("coCoviseConfig::RefPtr<T>::<init> info: creating");
113  ptr = 0;
114  refCount = 1;
115 }
116 
117 template <typename T>
119 {
120  //COCONFIGLOG("coCoviseConfig::RefPtr<T>::<dest> info: destroying");
121  release();
122 }
123 
124 template <typename T>
126 {
127  if (ptr != s.ptr)
128  {
129  //COCONFIGLOG("coCoviseConfig::RefPtr<T>::<init> info: copying");
130  ptr = s.ptr;
131  refCount = s.refCount;
132  if (ptr)
133  ++refCount;
134  }
135 }
136 
137 template <typename T>
139 {
140  if (ptr != s.ptr)
141  {
142  //COCONFIGLOG("coCoviseConfig::RefPtr<T>::operator= info: copying");
143  release();
144  refCount = s.refCount;
145  ptr = s.ptr;
146  if (ptr)
147  ++refCount;
148  }
149  return *this;
150 }
151 
152 template <typename T>
154 {
155  return ptr;
156 }
157 
158 template <typename T>
160 {
161  return ptr;
162 }
163 
164 template <typename T>
166 {
167  if (ptr)
168  {
169  if (--refCount == 0)
170  {
171  //COCONFIGLOG("coCoviseConfig::RefPtr<T>::release info: destroying ptr");
172  delete[] ptr;
173  ptr = 0;
174  }
175  }
176 }
177 }
178 #endif
GLsizei const GLchar *const * string
Definition: khronos-glext.h:6750
#define CONFIGEXPORT
Definition: coExport.h:355
GLenum GLenum variable
Definition: khronos-glext.h:9990
GLuint const GLchar * name
Definition: khronos-glext.h:6722
virtual ~RefPtr()
Definition: CoviseConfig.h:118
T ptr
Definition: CoviseConfig.h:90
unsigned int refCount
Definition: CoviseConfig.h:91
virtual void release()
Definition: CoviseConfig.h:165
RefPtr< T > & operator=(const RefPtr< T > &s)
Definition: CoviseConfig.h:138
GLdouble s
Definition: khronos-glext.h:6441
RefPtr()
Definition: CoviseConfig.h:110
Definition: CoviseConfig.h:18
Definition: CoviseConfig.h:94
Definition: CoviseConfig.h:74
T getValue()
Definition: CoviseConfig.h:153