Teuchos_XMLObject.hpp

Go to the documentation of this file.
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 XMLObject
00051 {
00052 public:
00053 
00055 
00056 
00058   XMLObject() : ptr_() {;}
00059 
00061   XMLObject(const string& tag);
00062 
00069   XMLObject(XMLObjectImplem* ptr);
00071 
00073 
00074 
00076   XMLObject deepCopy() const ;
00078 
00080 
00081 
00083   const string& getTag() const {return ptr_->getTag();}
00084 
00086   bool hasAttribute(const string& name) const 
00087     {return ptr_->hasAttribute(name);}
00088 
00090   const string& getAttribute(const string& name) const 
00091     {return ptr_->getAttribute(name);}
00092 
00094   const string& getRequired(const string& name) const ;
00095 
00097   double getRequiredDouble(const string& name) const 
00098     {return atof(getRequired(name).c_str());}
00099 
00101   int getRequiredInt(const string& name) const 
00102     {return atoi(getRequired(name).c_str());}
00103 
00105   bool getRequiredBool(const string& name) const ;
00106 
00107 
00110   string getWithDefault(const string& name, 
00111                         const string& defaultValue) const ;
00112 
00114   int numChildren() const {return ptr_->numChildren();}
00115 
00117   const XMLObject& getChild(int i) const {return ptr_->getChild(i);}
00118 
00120   int numContentLines() const {return ptr_->numContentLines();}
00121 
00123   const string& getContentLine(int i) const {return ptr_->getContentLine(i);}
00124 
00126   string toString() const {return ptr_->toString();}
00127 
00129   void print(ostream& os, int indent) const
00130     {ptr_->print(os, indent);}
00131 
00132 
00134   string header() const {return ptr_->header();}
00135 
00137   string terminatedHeader() const {return ptr_->terminatedHeader();}
00138 
00140   string footer() const {return ptr_->footer();}
00141 
00143   bool isEmpty() const { return ptr_.get()==0;}
00144 
00146   void checkTag(const string& expected) const ;
00148   
00150 
00151 
00153   void addAttribute(const string& name, const string& value)
00154     {ptr_->addAttribute(name, value);}
00155       
00157   void addDouble(const string& name, double val)
00158     {addAttribute(name, Teuchos::toString(val));}
00159 
00161   void addInt(const string& name, int val)
00162     {addAttribute(name, Teuchos::toString(val));}
00163 
00165   void addBool(const string& name, bool val)
00166     {addAttribute(name, Teuchos::toString(val));}
00167       
00169   void addChild(const XMLObject& child)
00170     {ptr_->addChild(child);}
00171 
00173   void addContent(const string& contentLine)
00174     {ptr_->addContent(contentLine);}
00176   
00177 private:
00178   RefCountPtr<XMLObjectImplem> ptr_;
00179 };
00180 
00184 inline ostream& operator<<(ostream& os, const XMLObject& xml)
00185 {
00186   xml.print(os, 0);
00187   return os;
00188 }
00189 
00193 inline string toString(const XMLObject& xml)
00194 {
00195   return xml.toString();
00196 }
00197 
00198 } // namespace Teuchos
00199 
00200 #endif
00201 

Generated on Thu Sep 18 12:30:31 2008 for Teuchos - Trilinos Tools Package by doxygen 1.3.9.1