BOSS 6.6.4.p03
BESIII Offline Software System
Loading...
Searching...
No Matches
IFile.h
Go to the documentation of this file.
1// $Header: /bes/bes/BossCvs/Calibration/xmlBase/xmlBase/IFile.h,v 1.1.1.1 2005/10/17 06:10:27 maqm Exp $
2// adapted from Bonn, originally written by Ruediger Gross-Hardt
4
5// converted to use STL map
6
7// User: Suson Date: 6/29/98
8// Added getIntVector, getDoubleVector
9
10#ifndef xmlBase_IFile_h
11#define xmlBase_IFile_h
12
13#include <cstdio>
14#include <iostream>
15
16#include <string>
17#include <map>
18#include <vector>
19
20#include <xercesc/util/XercesDefs.hpp>
21
22XERCES_CPP_NAMESPACE_BEGIN
23class DOMElement;
24class DOMDocument;
25XERCES_CPP_NAMESPACE_END
26
27// typedef XERCES_CPP_NAMESPACE_QUALIFIER DOMElement DomElement;
28// typedef XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument DomDocument;
29
30namespace xmlBase {
31 XERCES_CPP_NAMESPACE_USE
33 public:
34 IFileException(std::string err) : msg(err) {}
35 std::string msg;
36 };
38 {
39 // basic item, should be private to IFile
40 friend class IFile_Section;
41 friend class IFile;
42 public:
44 // IFile_Item(const char *line, int lineNumber);
45 IFile_Item(std::string name, std::string value):itemname(name),
46 itemstring(value){}
47 std::string& title() { return itemname; };
48 std::string& comment(){ return itemcomment; };
49 std::string& mystring() { return itemstring; };
50
51 private:
52 std::string itemname;
53 std::string itemstring;
54 std::string itemcomment;
55 };
56
57
58 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
60 public std::map<std::string, IFile_Item*, std::less<std::string> > {
61 // section, a map of items
62 friend class IFile;
63 public:
65 IFile_Section( std::string name):sectionname(name){}
67 std::string& title() { return sectionname; };
68 private:
69
70 bool contains(std::string name){ return find(name)!= end(); }
71
72 IFile_Item* lookUp(std::string name){
73 iterator it = find(name);
74 return (it==end())? 0 : (*it).second;
75 }
76 std::string sectionname;
77 };
78
79 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
80
81 class IFile :
82 protected std::map<std::string, IFile_Section*, std::less<std::string> >
83 {
84 // IFile is a map of sections
85
86 public:
87 IFile (const char *filename);
88 IFile (const DOMDocument* instrument);
89 // or do we want document element rather than DomDocument as arg?
90 IFile (const DOMElement* instrument);
91
92 virtual ~IFile ();
93
94 typedef std::vector<int> intVector;
95 typedef std::vector<double> doubleVector;
96
97 virtual bool contains (const char *section, const char *item);
98 // check, whether section and item is contained in IFile
99
100 virtual int getInt (const char *section, const char *item);
101 virtual double getDouble (const char *section, const char *item);
102 virtual int getBool (const char *section, const char *item);
103 virtual const char *getString (const char *section, const char *item);
104 virtual intVector getIntVector (const char *section, const char *item);
105 virtual doubleVector getDoubleVector (const char *section,
106 const char *item);
107 // get data from [section]item
108
109 virtual int getInt (const char *section, const char *item,
110 int defValue);
111 virtual double getDouble (const char *section, const char *item,
112 double defValue);
113 virtual int getBool (const char *section, const char *item,
114 int defValue);
115 virtual const char *getString (const char *section, const char *item,
116 const char *defValue);
117 virtual intVector getIntVector (const char *section, const char *item,
118 intVector defValues);
119 virtual doubleVector getDoubleVector (const char *section,
120 const char *item,
121 doubleVector defValues);
122 // get data from [section]item, providing a default value, if not present
123
124 void setString(const char *section, const char *item,
125 const char* newString);
126
127 void print(); // print contents to cout
128 // virtual void printOn (HOStream& out = herr);
129 virtual void printOn (std::ostream& out = std::cout );
130 // print IFile on stream
131
132 /// check for and replace an environment variable within a string
133 /// Soon to become obsolete -- maybe is by now
134 // static void extractEnvVar(std::string *fileStr);
135
136 protected:
137 friend class IFile_Section;
138 friend class IFile_Item;
139
140 static void stripBlanks (char *str1, const char *str2, int flags);
141 static int stricmp (const char *str1, const char *str2);
142
143
144 // helper functions (some should be private/protected)
145
146 IFile() {};
147 private:
148 // May want to change & to *, to be more in line with the way
149 // Xerces has implemented the DOM interface
150 void addSection(const DOMElement* elt);
151 void domToIni(const DOMDocument* doc);
152 void domToIni(const DOMElement* doc);
153 virtual const char *_getstring (const char *section, const char *item,
154 int failIfNotFoundFlag=1);
155 // internal function, that does the work
156 };
157} // end namespace xml
158#endif
159
std::string msg
Definition: IFile.h:35
IFileException(std::string err)
Definition: IFile.h:34
std::string & comment()
Definition: IFile.h:48
IFile_Item(std::string name, std::string value)
Definition: IFile.h:45
std::string & title()
Definition: IFile.h:47
std::string & mystring()
Definition: IFile.h:49
IFile_Section(std::string name)
Definition: IFile.h:65
std::string & title()
Definition: IFile.h:67
virtual int getInt(const char *section, const char *item)
Definition: IFile.cxx:334
std::vector< double > doubleVector
Definition: IFile.h:95
void setString(const char *section, const char *item, const char *newString)
Definition: IFile.cxx:293
void print()
Definition: IFile.cxx:43
virtual intVector getIntVector(const char *section, const char *item)
Definition: IFile.cxx:378
std::vector< int > intVector
Definition: IFile.h:94
virtual bool contains(const char *section, const char *item)
Definition: IFile.cxx:231
static void stripBlanks(char *str1, const char *str2, int flags)
Definition: IFile.cxx:58
virtual doubleVector getDoubleVector(const char *section, const char *item)
Definition: IFile.cxx:409
virtual const char * getString(const char *section, const char *item)
Definition: IFile.cxx:286
virtual double getDouble(const char *section, const char *item)
Definition: IFile.cxx:316
virtual ~IFile()
Definition: IFile.cxx:90
virtual void printOn(std::ostream &out=std::cout)
Definition: IFile.cxx:30
static int stricmp(const char *str1, const char *str2)
Definition: IFile.cxx:46
virtual int getBool(const char *section, const char *item)
Definition: IFile.cxx:351