COVISE Core
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
15namespace covise
16{
17
19{
20
21private:
23 virtual ~coCoviseConfig();
24
25public:
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:
81
82 virtual ~RefPtr()
83 {
84 //COCONFIGLOG("coCoviseConfig::RefPtr<T>::<dest> info: destroying");
85 release();
86 }
87
89 const T getValue() const;
90
91 protected:
92 virtual void release();
93
94 T ptr;
95 unsigned int refCount;
96 };
97
98 class CONFIGEXPORT ScopeEntries : public RefPtr<const char **>
99 {
100 public:
101 ScopeEntries(const char *scope, const char *name);
102
103 const char **getValue();
104 const char **getValue() const;
105
106 ScopeEntries &operator=(const ScopeEntries &s);
107
108 private:
109 virtual void release();
110 };
111};
112
113template <typename T>
115{
116 //COCONFIGLOG("coCoviseConfig::RefPtr<T>::<init> info: creating");
117 ptr = 0;
118 refCount = 1;
119}
120
121template <typename T>
123{
124 if (ptr != s.ptr)
125 {
126 //COCONFIGLOG("coCoviseConfig::RefPtr<T>::<init> info: copying");
127 ptr = s.ptr;
128 refCount = s.refCount;
129 if (ptr)
130 ++refCount;
131 }
132}
133
134template <typename T>
136{
137 if (ptr != s.ptr)
138 {
139 //COCONFIGLOG("coCoviseConfig::RefPtr<T>::operator= info: copying");
140 release();
141 refCount = s.refCount;
142 ptr = s.ptr;
143 if (ptr)
144 ++refCount;
145 }
146 return *this;
147}
148
149template <typename T>
151{
152 return ptr;
153}
154
155template <typename T>
157{
158 return ptr;
159}
160
161template <typename T>
163{
164 if (ptr)
165 {
166 if (--refCount == 0)
167 {
168 //COCONFIGLOG("coCoviseConfig::RefPtr<T>::release info: destroying ptr");
169 delete[] ptr;
170 ptr = 0;
171 }
172 }
173}
174}
175#endif
#define CONFIGEXPORT
Definition: coExport.h:367
GLsizei const GLchar *const * string
Definition: khronos-glext.h:6750
GLenum GLenum variable
Definition: khronos-glext.h:9990
GLuint const GLchar * name
Definition: khronos-glext.h:6722
GLdouble s
Definition: khronos-glext.h:6441
list of all chemical elements
Definition: coConfig.h:27
Definition: CoviseConfig.h:19
Definition: CoviseConfig.h:75
unsigned int refCount
Definition: CoviseConfig.h:95
RefPtr< T > & operator=(const RefPtr< T > &s)
Definition: CoviseConfig.h:135
const T getValue() const
Definition: CoviseConfig.h:156
T getValue()
Definition: CoviseConfig.h:150
RefPtr()
Definition: CoviseConfig.h:114
virtual ~RefPtr()
Definition: CoviseConfig.h:82
RefPtr(const RefPtr< T > &s)
Definition: CoviseConfig.h:122
T ptr
Definition: CoviseConfig.h:94
virtual void release()
Definition: CoviseConfig.h:162
Definition: CoviseConfig.h:99