/home/bes3soft/bes3soft/Boss/7.0.2/dist/7.0.2/Calibration/xmlBase/xmlBase-00-00-03/xmlBase/IFile.h

Go to the documentation of this file.
00001 // $Header: /bes/bes/BossCvs/Calibration/xmlBase/xmlBase/IFile.h,v 1.1.1.1 2005/10/17 06:10:27 maqm Exp $
00002 // adapted from Bonn, originally written by Ruediger Gross-Hardt
00003 // hardy@servax.iskp.uni-bonn.de
00004 
00005 // converted to use STL map
00006 
00007 // User: Suson      Date: 6/29/98
00008 // Added getIntVector, getDoubleVector
00009 
00010 #ifndef xmlBase_IFile_h
00011 #define xmlBase_IFile_h
00012 
00013 #include <cstdio>
00014 #include <iostream>
00015 
00016 #include <string>
00017 #include <map>
00018 #include <vector>
00019 
00020 #include <xercesc/util/XercesDefs.hpp>
00021 
00022 XERCES_CPP_NAMESPACE_BEGIN
00023 class DOMElement;
00024 class DOMDocument;
00025 XERCES_CPP_NAMESPACE_END
00026 
00027 // typedef XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DomElement;
00028 // typedef XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument DomDocument;
00029 
00030 namespace xmlBase {
00031   XERCES_CPP_NAMESPACE_USE
00032   class IFileException {
00033   public:
00034     IFileException(std::string err) : msg(err) {}
00035     std::string msg;
00036   };
00037   class IFile_Item 
00038     {
00039       // basic item, should be private to IFile
00040       friend class IFile_Section;
00041       friend class IFile;
00042     public:
00043       IFile_Item(){};
00044       //  IFile_Item(const char *line, int lineNumber);
00045       IFile_Item(std::string name, std::string value):itemname(name), 
00046         itemstring(value){}
00047       std::string& title()  { return itemname;    };
00048       std::string& comment(){ return itemcomment; };
00049       std::string& mystring() { return itemstring;  };
00050       
00051     private:
00052       std::string itemname;
00053       std::string itemstring;
00054       std::string itemcomment;
00055     };
00056   
00057   
00058   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00059   class IFile_Section : 
00060     public std::map<std::string, IFile_Item*, std::less<std::string> > {
00061     // section, a map of items
00062     friend class IFile;
00063     public:
00064     IFile_Section(){};
00065     IFile_Section( std::string name):sectionname(name){}
00066     ~IFile_Section();
00067     std::string& title() { return sectionname; };
00068     private:
00069     
00070     bool contains(std::string name){ return find(name)!= end(); }
00071     
00072     IFile_Item* lookUp(std::string name){
00073       iterator it = find(name);
00074       return (it==end())? 0 : (*it).second;
00075     }
00076     std::string sectionname;
00077   };
00078   
00079   //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00080   
00081   class IFile : 
00082     protected std::map<std::string, IFile_Section*, std::less<std::string> > 
00083     {
00084       // IFile is a map of sections
00085       
00086     public:
00087       IFile (const char *filename);
00088       IFile (const DOMDocument* instrument); 
00089       // or do we want document element rather than DomDocument as arg?
00090       IFile (const DOMElement* instrument);
00091       
00092       virtual ~IFile ();
00093       
00094       typedef std::vector<int> intVector;
00095       typedef std::vector<double> doubleVector;
00096       
00097       virtual bool   contains   (const char *section, const char *item);
00098       // check, whether section and item is contained in IFile
00099       
00100       virtual int           getInt        (const char *section, const char *item);
00101       virtual double  getDouble  (const char *section, const char *item);
00102       virtual int           getBool       (const char *section, const char *item);
00103       virtual const char *getString  (const char *section, const char *item);
00104       virtual intVector getIntVector  (const char *section, const char *item);
00105       virtual doubleVector getDoubleVector (const char *section, 
00106                                             const char *item);
00107       // get data from [section]item
00108       
00109       virtual int        getInt  (const char *section, const char *item, 
00110                               int defValue);
00111       virtual double getDouble (const char *section, const char *item, 
00112                                 double defValue);
00113       virtual int    getBool (const char *section, const char *item, 
00114                               int defValue);
00115       virtual const char *getString  (const char *section, const char *item, 
00116                                       const char *defValue);
00117       virtual intVector getIntVector (const char *section, const char *item, 
00118                                       intVector defValues);
00119       virtual doubleVector getDoubleVector (const char *section, 
00120                                             const char *item,
00121                                             doubleVector defValues);
00122       // get data from [section]item, providing a default value, if not present
00123       
00124       void setString(const char *section, const char *item, 
00125                      const char* newString);
00126       
00127       void print(); // print contents to cout
00128       //   virtual void  printOn    (HOStream& out = herr);
00129       virtual void        printOn         (std::ostream& out = std::cout );
00130       // print IFile on stream
00131 
00134       //      static void       extractEnvVar(std::string *fileStr);
00135       
00136     protected:
00137       friend class IFile_Section;
00138       friend class IFile_Item;
00139       
00140       static void       stripBlanks  (char *str1, const char *str2, int flags);
00141       static int        stricmp      (const char *str1, const char *str2);
00142 
00143 
00144       // helper functions (some should be private/protected)
00145       
00146       IFile() {};
00147     private:
00148       // May want to change & to *, to be more in line with the way
00149       // Xerces has implemented the DOM interface
00150       void       addSection(const DOMElement* elt);
00151       void       domToIni(const DOMDocument* doc);
00152       void       domToIni(const DOMElement* doc);
00153       virtual const char *_getstring  (const char *section, const char *item,
00154                                        int failIfNotFoundFlag=1);
00155       // internal function, that does the work
00156     };
00157 }  // end namespace xml 
00158 #endif
00159 

Generated on Tue Nov 29 22:57:58 2016 for BOSS_7.0.2 by  doxygen 1.4.7