VAPoR  0.1
ParamsBase.h
Go to the documentation of this file.
1 //************************************************************************
2 // *
3 // Copyright (C) 2008 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: ParamsBase.h
10 //
11 // Author: John Clyne, modified by Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: March 2008
16 //
17 // Description:
18 // Defines the ParamsBase class
19 // This is an abstract class for classes that rely on
20 // accessing an XML node for get/set
21 //
22 
23 #ifndef ParamsBase_H
24 #define ParamsBase_H
25 
26 #include <vapor/XmlNode.h>
27 #include <vapor/ParamNode.h>
28 #include <vapor/ExpatParseMgr.h>
29 #include "assert.h"
30 #include <vapor/common.h>
31 
32 
33 using namespace VetsUtil;
34 
35 namespace VAPoR{
36 
37 //
52 
53 class XmlNode;
54 class ParamNode;
55 class ParamsBase;
56 
58 
59 
60 typedef ParamsBase* (*BaseCreateFcn)();
61 
62 public:
64  XmlNode *parent, const string &name
65  );
66 typedef int ParamsBaseType;
68 ParamsBase(const string& name) {
69  _currentParamNode = _rootParamNode = 0;
70  _parseDepth = 0;
71  _paramsBaseName = name;
72 }
74 ParamsBase(const ParamsBase &pbase);
75 
76 virtual ~ParamsBase();
77 
86  //
87  virtual ParamsBase* deepCopy(ParamNode* newRoot = 0);
88 
98  //
99  void SetParent(XmlNode *parent);
100 
101 
114  //
115  virtual bool elementStartHandler(
116  ExpatParseMgr* pm, int depth, string& tag, const char ** attribs
117  );
118 
130  //
131  virtual bool elementEndHandler(ExpatParseMgr* pm, int depth, string& tag);
132 
137 
138 ParamNode *GetRootNode() { return(_rootParamNode); }
139 
146 
147 virtual ParamNode* buildNode();
148 
152 
153 void SetFlagDirty(const string& flag);
157 
158 const string& GetName() {return _paramsBaseName;}
163 
164 ParamsBaseType GetParamsBaseTypeId() {return GetTypeFromTag(_paramsBaseName);}
165 
170 static ParamsBaseType GetTypeFromTag(const string&tag);
171 
176 static const string& GetTagFromType(ParamsBaseType t);
177 
185  ParamsBase *p = (createDefaultFcnMap[pType])();
186  return p;
187 }
194 static ParamsBase* CreateDefaultParamsBase(const string&tag);
195 
196 //Methods for registration and tabulation of existing Params instances
197 
198 
207  static int RegisterParamsBaseClass(const string& tag, BaseCreateFcn fcn, bool isParams);
217  static int ReregisterParamsBaseClass(const string& tag, const string& newtag, bool isParams);
222  virtual void SetRootParamNode(ParamNode* pn){_rootParamNode = pn;}
227  static int GetNumParamsClasses() {return numParamsClasses;}
233  static bool IsParamsTag(const string&tag) {return (GetTypeFromTag(tag) > 0);}
234 #ifndef DOXYGEN_SKIP_THIS
235  static ParamsBase* CreateDummyParamsBase(std::string tag);
236 
237  static void addDummyParamsBaseInstance(ParamsBase*const & pb ) {dummyParamsBaseInstances.push_back(pb);}
238 
239  static void clearDummyParamsBaseInstances();
240 #endif
241 private:
242  //These should be accessed by subclasses through get() and set() methods
243  ParamNode *_currentParamNode;
244  ParamNode *_rootParamNode;
245 
246 
247 protected:
248  static vector<ParamsBase*> dummyParamsBaseInstances;
249  static const string _emptyString;
250  virtual ParamNode *getCurrentParamNode() {return _currentParamNode;}
251 
252  virtual void setCurrentParamNode(ParamNode* pn){ _currentParamNode=pn;}
253 
254 
255 
256  static map<string,int> classIdFromTagMap;
257  static map<int,string> tagFromClassIdMap;
258  static map<int,BaseCreateFcn> createDefaultFcnMap;
259 
262  static int numParamsClasses;
263  static int numEmbedClasses;
264 
265 
266 protected:
267 
274  ParamNode *GetCurrentNode() { return(_currentParamNode); }
275 
292  //
293  ParamNode *Push(
294  string& tag,
295  ParamsBase* pBase = 0
296  );
297 
298 
308  //
309  ParamNode *Pop();
310 
319  //
320  void Remove(const string &name);
321 
325  //
326  const map <string, string> &GetAttributes();
327 
328 
333  //
334  void Clear();
335 };
336 #ifndef DOXYGEN_SKIP_THIS
337 //The DummyParamsBase is simply holding the parse information for
338 //A paramsBase extension class that is not present. This can only occur
339 //as a ParamsBase node inside a DummyParams node
340 class DummyParamsBase : public ParamsBase {
341  public:
342  DummyParamsBase(XmlNode *parent, const string &name) :
343  ParamsBase(parent, name) {}
344  virtual ~DummyParamsBase(){}
345 };
346 #endif //DOXYGEN_SKIP_THIS
347 }; //End namespace VAPoR
348 #endif //ParamsBase_H
#define PARAMS_API
Definition: common.h:63
static vector< ParamsBase * > dummyParamsBaseInstances
Definition: ParamsBase.h:248
ParamNode * GetCurrentNode()
Definition: ParamsBase.h:274
virtual void SetRootParamNode(ParamNode *pn)
Definition: ParamsBase.h:222
static const string _emptyString
Definition: ParamsBase.h:249
static map< int, string > tagFromClassIdMap
Definition: ParamsBase.h:257
ParamNode * GetRootNode()
Definition: ParamsBase.h:138
virtual void setCurrentParamNode(ParamNode *pn)
Definition: ParamsBase.h:252
ParamsBaseType GetParamsBaseTypeId()
Definition: ParamsBase.h:164
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:57
An Xml tree.
Definition: XmlNode.h:47
const string & GetName()
Definition: ParamsBase.h:158
static ParamsBase * CreateDefaultParamsBase(int pType)
Definition: ParamsBase.h:184
static int numEmbedClasses
Definition: ParamsBase.h:263
static int GetNumParamsClasses()
Definition: ParamsBase.h:227
virtual ParamNode * getCurrentParamNode()
Definition: ParamsBase.h:250
string _paramsBaseName
Definition: ParamsBase.h:260
ParamsBase(const string &name)
Default constructor.
Definition: ParamsBase.h:68
static map< int, BaseCreateFcn > createDefaultFcnMap
Definition: ParamsBase.h:258
static int numParamsClasses
Definition: ParamsBase.h:262
static map< string, int > classIdFromTagMap
Definition: ParamsBase.h:256
static bool IsParamsTag(const string &tag)
Definition: ParamsBase.h:233
An Xml tree.
Definition: ParamNode.h:30