VAPoR  3.0.0
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 namespace VAPoR{
35 
36 class Params;
37 
38 
39 //
84 
85 class XmlNode;
86 class ParamNode;
87 class ParamsBase;
88 class DataMgrV3_0;
89 
90 class PARAMS_API ParamsBase : public ParsedXml {
91 
92 
93 typedef ParamsBase* (*BaseCreateFcn)();
94 
95 public:
97  XmlNode *parent, const string &name
98  );
99 typedef int ParamsBaseType;
101 ParamsBase(const string& name) {
102  _currentParamNode = _rootParamNode = 0;
103  _parseDepth = 0;
104  _paramsBaseName = name;
105 }
107 ParamsBase(const ParamsBase &pbase);
109 virtual ~ParamsBase();
110 
111 
112 
116 
126  //
127  void SetParent(XmlNode *parent);
128 
129 
142  //
143  virtual bool elementStartHandler(
144  ExpatParseMgr* pm, int depth, string& tag, const char ** attribs
145  );
146 
158  //
159  virtual bool elementEndHandler(ExpatParseMgr* pm, int depth, string& tag);
160 
167 
168 virtual ParamNode* buildNode();
169 
171 
176 
177 ParamNode *GetRootNode() const { return(_rootParamNode); }
178 
179 
183 
184 const string GetName() const {return _paramsBaseName;}
193 virtual long GetValueLong(const string& tag, const vector<long>& defaultVal = _emptyLongVec)
194  {
195  return GetRootNode()->GetElementLong(tag, defaultVal)[0];
196  }
205 virtual double GetValueDouble(const string& tag,const vector<double>& defaultVal = _emptyDoubleVec)
206  {return GetRootNode()->GetElementDouble(tag,defaultVal)[0];}
215 virtual const string GetValueString(const string& tag, const string& defaultVal = _emptyString)
216  {return GetRootNode()->GetElementString(tag, defaultVal);}
225 virtual const vector<long> GetValueLongVec(const string& tag,const vector<long>& defaultVal = _emptyLongVec)
226  {return GetRootNode()->GetElementLong(tag, defaultVal);}
235 virtual const vector<double> GetValueDoubleVec(const string& tag, const vector<double>& defaultVal = _emptyDoubleVec)
236  {return GetRootNode()->GetElementDouble(tag, defaultVal);}
245 virtual void GetValueStringVec(const string& tag, vector<string>& vec, const vector<string>& defaultVal = _emptyStringVec)
246  {GetRootNode()->GetElementStringVec(tag, vec, defaultVal);}
247 
248 
260  virtual int SetValueLong(string tag, const char* description, long value, Params* p);
261 
273  virtual int SetValueLong(string tag, const char* description, const vector<long>& value, Params* p);
274 
286  virtual int SetValueDouble(string tag, const char* description, double value, Params* p);
287 
299  virtual int SetValueDouble(string tag, const char* description, const vector<double>& value, Params* p);
300 
312  virtual int SetValueString(string tag, const char* description, const string& value, Params* p);
313 
325  virtual int SetValueStringVec(string tag, const char* description, const vector<string>& value, Params* p);
326 
331 
332 ParamsBaseType GetParamsBaseTypeId() {return GetTypeFromTag(_paramsBaseName);}
333 
338 static ParamsBaseType GetTypeFromTag(const string&tag);
339 
344 static const string GetTagFromType(ParamsBaseType t);
345 
353  ParamsBase *p = (createDefaultFcnMap[pType])();
354  return p;
355 }
362 static ParamsBase* CreateDefaultParamsBase(const string&tag);
363 
364 //Methods for registration and tabulation of existing Params instances
365 
366 
375  static int RegisterParamsBaseClass(const string& tag, BaseCreateFcn fcn, bool isParams);
385  static int ReregisterParamsBaseClass(const string& tag, const string& newtag, bool isParams);
390  virtual void SetRootParamNode(ParamNode* pn){_rootParamNode = pn;}
395  static int GetNumParamsClasses() {return _numParamsClasses;}
401  static int GetNumBasicParamsClasses() {return _numBasicParamsClasses;}
407  static bool IsParamsTag(const string&tag) {return (GetTypeFromTag(tag) > 0);}
408 
414  ParamsBase* GetParamsBase(const vector<string>& path) const;
415 
430  int SetParamsBase(const vector<string>& path, ParamsBase* pbase);
431 
442  int RemoveParamsBase(const vector<string>& path, ParamsBase* pbase);
443 
444 #ifndef DOXYGEN_SKIP_THIS
445 
446  static ParamsBase* CreateDummyParamsBase(std::string tag);
447 
448  static void addDummyParamsBaseInstance(ParamsBase*const & pb ) {dummyParamsBaseInstances.push_back(pb);}
449 
450  static void clearDummyParamsBaseInstances();
456  ParamsBase* deepCopy(ParamNode* newRoot = 0);
457 
460  static void setDataMgr(DataMgrV3_0* dataMgr){ _dataMgr = dataMgr;}
461 
462 private:
463  static DataMgrV3_0* _dataMgr;
464  //These should be accessed by subclasses through get() and set() methods
465  ParamNode *_currentParamNode;
466  ParamNode *_rootParamNode;
467 
468 
469 protected:
470  static DataMgrV3_0* GetDataMgr() {return _dataMgr;}
471  static vector<ParamsBase*> dummyParamsBaseInstances;
472  static const string _emptyString;
473  static const vector<string> _emptyStringVec;
474  static const vector<double> _emptyDoubleVec;
475  static const vector<long> _emptyLongVec;
476  virtual ParamNode *getCurrentParamNode() {return _currentParamNode;}
477 
478  virtual void setCurrentParamNode(ParamNode* pn){ _currentParamNode=pn;}
479 
480 
481 
482  static map<string,int> classIdFromTagMap;
483  static map<int,string> tagFromClassIdMap;
484  static map<int,BaseCreateFcn> createDefaultFcnMap;
485 
486  string _paramsBaseName;
487  int _parseDepth;
488  static int _numParamsClasses;
489  static int _numBasicParamsClasses;
490  static int _numEmbedClasses;
491 
492 #endif //DOXYGEN_SKIP_THIS
493 
497 
504  ParamNode *GetCurrentNode() { return(_currentParamNode); }
505 
522  //
523  ParamNode *Push(
524  string& tag,
525  ParamsBase* pBase = 0
526  );
527 
528 
538  //
539  ParamNode *Pop();
540 
549  //
550  void Remove(const string &name);
551 
555  //
556  const map <string, string> &GetAttributes();
557 
558 
563  //
564  void Clear();
565 
567 };
568 
569 #ifndef DOXYGEN_SKIP_THIS
570 
571 //The DummyParamsBase is simply holding the parse information for
572 //A paramsBase extension class that is not present. This can only occur
573 //as a ParamsBase node inside a DummyParams node
574 class DummyParamsBase : public ParamsBase {
575  public:
576  DummyParamsBase(XmlNode *parent, const string &name) :
577  ParamsBase(parent, name) {}
578 
579  virtual ~DummyParamsBase(){}
580 };
581 #endif //DOXYGEN_SKIP_THIS
582 }; //End namespace VAPoR
583 #endif //ParamsBase_H
virtual long GetValueLong(const string &tag, const vector< long > &defaultVal=_emptyLongVec)
Definition: ParamsBase.h:193
ParamNode * GetRootNode() const
Definition: ParamsBase.h:177
A pure virtual class for managing parameters used in visualization.
Definition: params.h:129
ParamNode * GetCurrentNode()
Definition: ParamsBase.h:504
virtual void SetRootParamNode(ParamNode *pn)
Definition: ParamsBase.h:390
virtual const vector< long > GetValueLongVec(const string &tag, const vector< long > &defaultVal=_emptyLongVec)
Definition: ParamsBase.h:225
ParamsBaseType GetParamsBaseTypeId()
Definition: ParamsBase.h:332
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:90
static ParamsBase * CreateDefaultParamsBase(int pType)
Definition: ParamsBase.h:352
static int GetNumParamsClasses()
Definition: ParamsBase.h:395
virtual void GetValueStringVec(const string &tag, vector< string > &vec, const vector< string > &defaultVal=_emptyStringVec)
Definition: ParamsBase.h:245
static int GetNumBasicParamsClasses()
Definition: ParamsBase.h:401
virtual const string GetValueString(const string &tag, const string &defaultVal=_emptyString)
Definition: ParamsBase.h:215
virtual double GetValueDouble(const string &tag, const vector< double > &defaultVal=_emptyDoubleVec)
Definition: ParamsBase.h:205
ParamsBase(const string &name)
Default constructor.
Definition: ParamsBase.h:101
#define PARAMS_API
Definition: DC.h:10
static bool IsParamsTag(const string &tag)
Definition: ParamsBase.h:407
An Xml tree.
Definition: ParamNode.h:30
virtual const vector< double > GetValueDoubleVec(const string &tag, const vector< double > &defaultVal=_emptyDoubleVec)
Definition: ParamsBase.h:235
const string GetName() const
Definition: ParamsBase.h:184