Parameter.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef BASE__PARAMETER_H
00027 #define BASE__PARAMETER_H
00028
00029
00030 #if defined (_POSIX_C_SOURCE)
00031 # undef _POSIX_C_SOURCE
00032 #endif
00033 #if defined (_XOPEN_SOURCE)
00034 # undef _XOPEN_SOURCE
00035 #endif
00036
00037
00038 #include <Python.h>
00039 #ifdef FC_OS_LINUX
00040 #include <sstream>
00041 #endif
00042 #include <map>
00043 #include <vector>
00044 #include <xercesc/util/XercesDefs.hpp>
00045
00046
00047 #include "Handle.h"
00048 #include "Observer.h"
00049
00050 #ifdef _MSC_VER
00051 # pragma warning( disable : 4251 )
00052 # pragma warning( disable : 4503 )
00053 # pragma warning( disable : 4786 ) // specifier longer then 255 chars
00054 # pragma warning( disable : 4290 ) // not implemented throw specification
00055 # pragma warning( disable : 4275 )
00056 #endif
00057
00058
00059 XERCES_CPP_NAMESPACE_BEGIN
00060 class DOMNode;
00061 class DOMElement;
00062 class DOMDocument;
00063 XERCES_CPP_NAMESPACE_END
00064
00065 class ParameterManager;
00066
00067
00082 class BaseExport ParameterGrp : public Base::Handled,public Base::Subject <const char*>
00083 {
00084
00085
00086 public:
00089
00090 void copyTo(Base::Reference<ParameterGrp>);
00092 void insertTo(Base::Reference<ParameterGrp>);
00094 void exportTo(const char* FileName);
00096 void importFrom(const char* FileName);
00098 void insert(const char* FileName);
00100
00103
00104 Base::Reference<ParameterGrp> GetGroup(const char* Name);
00106 std::vector<Base::Reference<ParameterGrp> > GetGroups(void);
00108 bool IsEmpty(void) const;
00110 bool HasGroup(const char* Name) const;
00112 typedef Base::Reference<ParameterGrp> handle;
00114 void RemoveGrp(const char* Name);
00116 void Clear(void);
00118
00121
00122 bool GetBool(const char* Name, bool bPreset=false) const;
00124 void SetBool(const char* Name, bool bValue);
00126 std::vector<bool> GetBools(const char * sFilter = NULL) const;
00128 std::vector<std::pair<std::string,bool> > GetBoolMap(const char * sFilter = NULL) const;
00130 void RemoveBool(const char* Name);
00132
00135
00136 long GetInt(const char* Name, long lPreset=0) const;
00138 void SetInt(const char* Name, long lValue);
00140 std::vector<long> GetInts(const char * sFilter = NULL) const;
00142 std::vector<std::pair<std::string,long> > GetIntMap(const char * sFilter = NULL) const;
00144 void RemoveInt(const char* Name);
00146
00149
00150 unsigned long GetUnsigned(const char* Name, unsigned long lPreset=0) const;
00152 void SetUnsigned(const char* Name, unsigned long lValue);
00154 std::vector<unsigned long> GetUnsigneds(const char * sFilter = NULL) const;
00156 std::vector<std::pair<std::string,unsigned long> > GetUnsignedMap(const char * sFilter = NULL) const;
00158 void RemoveUnsigned(const char* Name);
00160
00161
00164
00165 double GetFloat(const char* Name, double dPreset=0.0) const;
00167 void SetFloat(const char* Name, double dValue);
00169 std::vector<double> GetFloats(const char * sFilter = NULL) const;
00171 std::vector<std::pair<std::string,double> > GetFloatMap(const char * sFilter = NULL) const;
00173 void RemoveFloat(const char* Name);
00175
00176
00179
00180 void SetBlob(const char* Name, void *pValue, long lLength);
00182 void GetBlob(const char* Name, void * pBuf, long lMaxLength, void* pPreset=NULL) const;
00184 void RemoveBlob(const char* Name);
00186
00187
00188
00191
00192 void SetASCII(const char* Name, const char *sValue);
00194 std::string GetASCII(const char* Name, const char * pPreset=NULL) const;
00196 void RemoveASCII(const char* Name);
00202 std::vector<std::string> GetASCIIs(const char * sFilter = NULL) const;
00204 std::vector<std::pair<std::string,std::string> > GetASCIIMap(const char * sFilter = NULL) const;
00206
00207 static void Init(void);
00208
00209 friend class ParameterManager;
00210
00212 const char* GetGroupName(void) const {
00213 return _cName.c_str();
00214 }
00215
00218 void NotifyAll();
00219
00220 protected:
00222 ParameterGrp(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *GroupNode=0L,const char* sName=0L);
00224 ~ParameterGrp();
00226 Base::Reference<ParameterGrp> _GetGroup(const char* Name);
00227
00228 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindNextElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *Prev, const char* Type) const;
00229
00236 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *Start, const char* Type, const char* Name=0L) const;
00237
00243 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *FindOrCreateElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *Start, const char* Type, const char* Name) const;
00244
00245
00247 XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *_pGroupNode;
00249 std::string _cName;
00251 std::map <std::string ,Base::Reference<ParameterGrp> > _GroupMap;
00252
00253 };
00254
00255
00261 class BaseExport ParameterManager : public ParameterGrp
00262 {
00263 public:
00264 ParameterManager();
00265 ~ParameterManager();
00266 static void Init(void);
00267
00268 int LoadDocument(const char* sFileName);
00269
00270 bool LoadOrCreateDocument(const char* sFileName);
00271
00272 void SaveDocument(const char* sFileName) const;
00273
00274 void CreateDocument(void);
00275
00276 void CheckDocument() const;
00277
00278 private:
00279
00280 XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *_pDocument;
00281
00282 bool gDoNamespaces ;
00283 bool gDoSchema ;
00284 bool gSchemaFullChecking ;
00285 bool gDoCreate ;
00286
00287
00288 const XMLCh* gOutputEncoding ;
00289 const XMLCh* gMyEOLSequence ;
00290
00291 bool gSplitCdataSections ;
00292 bool gDiscardDefaultContent;
00293 bool gUseFilter ;
00294 bool gFormatPrettyPrint ;
00295
00296 };
00297
00300 BaseExport PyObject* GetPyObject( const Base::Reference<ParameterGrp> &hcParamGrp);
00301
00302
00303 #endif // BASE__PARAMETER_H