RTXI  2.4
The Real-Time eXperiment Interface Documentation
settings.h
Go to the documentation of this file.
1 /*
2  The Real-Time eXperiment Interface (RTXI)
3  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 */
19 
20 #ifndef SETTINGS_H
21 #define SETTINGS_H
22 
23 #include <QString>
24 #include <debug.h>
25 #include <list>
26 #include <map>
27 #include <mutex.h>
28 #include <string>
29 
30 class QDomDocument;
31 class QDomElement;
32 
34 
37 namespace Settings
38 {
39 
43 class Object
44 {
45 
46  friend class Manager;
47 
48 public:
49 
53  typedef unsigned long ID;
57  const static ID INVALID = 0;
58 
62  class State
63  {
64 
65  friend class Manager;
66  friend class Object;
67 
68  public:
69 
70  State(void);
71  State(ID n);
72  ~State(void);
73 
77  double loadDouble(const std::string &name) const;
81  int loadInteger(const std::string &name) const;
85  std::string loadString(const std::string &name) const;
89  void saveDouble(const std::string &name,double);
93  void saveInteger(const std::string &name,int);
97  void saveString(const std::string &name,const std::string &value);
98 
102  State loadState(const std::string &name) const;
106  void saveState(const std::string &name,const State &value);
107 
111  QDomElement xml(QDomDocument &) const;
115  void xml(const QDomElement &);
116 
117  private:
118 
119  ID id;
120  std::map<std::string,std::string> paramMap;
121  std::map<std::string,State> stateMap;
122 
123  };
124 
125  Object(void);
126  virtual ~Object(void);
127 
131  ID getID(void) const
132  {
133  return id;
134  };
135 
139  State save(void) const;
143  void load(const State &);
147  void deferred(const State &);
148 
149 protected:
150 
154  virtual void doLoad(const State &) {};
158  virtual void doDeferred(const State &) {};
162  virtual void doSave(State &) const {};
163 
164 private:
165 
166  ID id;
167 
168 }; // class Object
169 
173 class Manager
174 {
175 
176  friend class Object;
177 
178 public:
179 
183  static Manager *getInstance(void);
184 
188  Object *getObject(Object::ID) const;
192  void foreachObject(void (*callback)(Object *,void *),void *param);
193 
197  int load(const std::string &);
201  int save(const std::string &);
202 
203 private:
204 
205  Manager(void) : mutex(Mutex::RECURSIVE), currentID(Object::INVALID+1) {};
206  ~Manager(void) {};
207  Manager(const Manager &) {};
208  Manager &operator=(const Manager &)
209  {
210  return *getInstance();
211  };
212 
213  static Manager *instance;
214 
215  void acquireID(Object *,Object::ID =Object::INVALID);
216  void releaseID(Object *);
217 
218  void insertObject(Object *);
219  void removeObject(Object *);
220 
221  mutable Mutex mutex;
222  Object::ID currentID;
223  std::list<Object *> objectList;
224  std::map<Object::ID,Object *> objectMap;
225 
226 }; // class Manager
227 
228 }; // namespace Settings
229 
230 #endif // SETTINGS_H
Settings::Object::State::xml
QDomElement xml(QDomDocument &) const
Definition: settings.cpp:141
Settings::Manager::getInstance
static Manager * getInstance(void)
Definition: settings.cpp:534
Settings::Object::Object
Object(void)
Definition: settings.cpp:45
Settings::Object::deferred
void deferred(const State &)
Definition: settings.cpp:207
Settings::Object::State::loadState
State loadState(const std::string &name) const
Definition: settings.cpp:124
Settings::Manager::getObject
Object * getObject(Object::ID) const
Definition: settings.cpp:212
Settings::Object::State::loadDouble
double loadDouble(const std::string &name) const
Definition: settings.cpp:61
Settings::Manager
Definition: settings.h:173
Settings::Object::State::~State
~State(void)
Definition: settings.cpp:59
Settings::Object::State::saveDouble
void saveDouble(const std::string &name, double)
Definition: settings.cpp:105
Settings::Object::State::loadString
std::string loadString(const std::string &name) const
Definition: settings.cpp:93
Settings::Object::save
State save(void) const
Definition: settings.cpp:188
Settings::Object::ID
unsigned long ID
Definition: settings.h:53
Mutex
Definition: mutex.h:28
Settings::Object::State::saveString
void saveString(const std::string &name, const std::string &value)
Definition: settings.cpp:119
Settings::Manager::foreachObject
void foreachObject(void(*callback)(Object *, void *), void *param)
Definition: settings.cpp:223
Settings::Object::INVALID
const static ID INVALID
Definition: settings.h:57
Settings::Object::doLoad
virtual void doLoad(const State &)
Definition: settings.h:154
Settings::Object::State::loadInteger
int loadInteger(const std::string &name) const
Definition: settings.cpp:77
Settings::Object::~Object
virtual ~Object(void)
Definition: settings.cpp:50
mutex.h
Settings::Manager::load
int load(const std::string &)
Definition: settings.cpp:230
Settings::Object
Definition: settings.h:43
Settings::Object::State
Definition: settings.h:62
Settings::Object::State::saveInteger
void saveInteger(const std::string &name, int)
Definition: settings.cpp:112
Settings::Manager::save
int save(const std::string &)
Definition: settings.cpp:358
Settings::Object::doDeferred
virtual void doDeferred(const State &)
Definition: settings.h:158
Settings
Objects for saving/loading setting information between sessions.
Definition: settings.h:37
Settings::Object::State::State
State(void)
Definition: settings.cpp:55
Settings::Object::State::saveState
void saveState(const std::string &name, const State &value)
Definition: settings.cpp:136
Settings::Object::getID
ID getID(void) const
Definition: settings.h:131
Settings::Object::doSave
virtual void doSave(State &) const
Definition: settings.h:162
Settings::Manager::Object
friend class Object
Definition: settings.h:176
debug.h
Settings::Object::load
void load(const State &)
Definition: settings.cpp:195