Teuchos_XMLObject.hpp
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
00027
00028
00029 #ifndef Teuchos_XMLOBJECT_H
00030 #define Teuchos_XMLOBJECT_H
00031
00036 #include "Teuchos_XMLObjectImplem.hpp"
00037 #include "Teuchos_Utils.hpp"
00038
00039 namespace Teuchos
00040 {
00041
00043 class EmptyXMLError : public std::runtime_error
00044 {public: EmptyXMLError(const std::string& what_arg) : std::runtime_error(what_arg) {}};
00045
00050 class XMLObject
00051 {
00052 public:
00053
00055
00056
00058 XMLObject() : ptr_() {;}
00059
00061 XMLObject(const std::string& tag);
00062
00069 XMLObject(XMLObjectImplem* ptr);
00071
00073
00074
00076 XMLObject deepCopy() const ;
00078
00080
00081
00083 const std::string& getTag() const;
00084
00086 bool hasAttribute(const std::string& name) const;
00087
00089 const std::string& getAttribute(const std::string& name) const;
00090
00092 const std::string& getRequired(const std::string& name) const;
00093
00095 double getRequiredDouble(const std::string& name) const
00096 {return std::atof(getRequired(name).c_str());}
00097
00099 int getRequiredInt(const std::string& name) const
00100 {return std::atoi(getRequired(name).c_str());}
00101
00103 bool getRequiredBool(const std::string& name) const ;
00104
00105
00108 std::string getWithDefault(const std::string& name,
00109 const std::string& defaultValue) const ;
00110
00112 int numChildren() const;
00113
00115 const XMLObject& getChild(int i) const;
00116
00118 int numContentLines() const;
00119
00121 const std::string& getContentLine(int i) const;
00122
00124 std::string toString() const;
00125
00127 void print(std::ostream& os, int indent) const;
00128
00130 std::string header() const;
00131
00133 std::string terminatedHeader() const;
00134
00136 std::string footer() const;
00137
00139 bool isEmpty() const { return ptr_.get()==0;}
00140
00142 void checkTag(const std::string& expected) const ;
00144
00146
00147
00149 void addAttribute(const std::string& name, const std::string& value);
00150
00152 void addDouble(const std::string& name, double val)
00153 {addAttribute(name, Teuchos::toString(val));}
00154
00156 void addInt(const std::string& name, int val)
00157 {addAttribute(name, Teuchos::toString(val));}
00158
00160 void addBool(const std::string& name, bool val)
00161 {addAttribute(name, Teuchos::toString(val));}
00162
00164 void addChild(const XMLObject& child);
00165
00167 void addContent(const std::string& contentLine);
00169
00170 private:
00171 RCP<XMLObjectImplem> ptr_;
00172 };
00173
00177 inline std::ostream& operator<<(std::ostream& os, const XMLObject& xml)
00178 {
00179 xml.print(os, 0);
00180 return os;
00181 }
00182
00186 inline std::string toString(const XMLObject& xml)
00187 {
00188 return xml.toString();
00189 }
00190
00191 }
00192
00193 #endif