|
Teuchos - Trilinos Tools Package Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Teuchos: Common Tools Package 00005 // Copyright (2004) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // This library is free software; you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as 00012 // published by the Free Software Foundation; either version 2.1 of the 00013 // License, or (at your option) any later version. 00014 // 00015 // This library is distributed in the hope that it will be useful, but 00016 // WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 // Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public 00021 // License along with this library; if not, write to the Free Software 00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00023 // USA 00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 00025 // 00026 // *********************************************************************** 00027 // @HEADER 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 TEUCHOS_LIB_DLL_EXPORT 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 //use pragmas to disable some false-positive warnings for windows sharedlibs export 00172 #ifdef _MSC_VER 00173 #pragma warning(push) 00174 #pragma warning(disable:4251) 00175 #endif 00176 RCP<XMLObjectImplem> ptr_; 00177 #ifdef _MSC_VER 00178 #pragma warning(pop) 00179 #endif 00180 }; 00181 00185 inline std::ostream& operator<<(std::ostream& os, const XMLObject& xml) 00186 { 00187 xml.print(os, 0); 00188 return os; 00189 } 00190 00194 inline std::string toString(const XMLObject& xml) 00195 { 00196 return xml.toString(); 00197 } 00198 00199 } // namespace Teuchos 00200 00201 #endif
1.7.4