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 
00047   class XMLObject
00048     {
00049     public:
00052 
00054       XMLObject() : ptr_() {;}
00055 
00057       XMLObject(const string& tag);
00058 
00065       XMLObject(XMLObjectImplem* ptr);
00067 
00070 
00072       XMLObject deepCopy() const ;
00074 
00077 
00079       const string& getTag() const {return ptr_->getTag();}
00080 
00082       bool hasAttribute(const string& name) const 
00083         {return ptr_->hasAttribute(name);}
00084 
00086       const string& getAttribute(const string& name) const 
00087         {return ptr_->getAttribute(name);}
00088 
00090       const string& getRequired(const string& name) const ;
00091 
00093       double getRequiredDouble(const string& name) const 
00094         {return atof(getRequired(name).c_str());}
00095 
00097       int getRequiredInt(const string& name) const 
00098         {return atoi(getRequired(name).c_str());}
00099 
00101       bool getRequiredBool(const string& name) const ;
00102 
00103 
00106       string getWithDefault(const string& name, 
00107             const string& defaultValue) const ;
00108 
00110       int numChildren() const {return ptr_->numChildren();}
00111 
00113       const XMLObject& getChild(int i) const {return ptr_->getChild(i);}
00114 
00116       int numContentLines() const {return ptr_->numContentLines();}
00117 
00119       const string& getContentLine(int i) const {return ptr_->getContentLine(i);}
00120 
00122       string toString() const {return ptr_->toString();}
00123 
00125       void print(ostream& os, int indent) const
00126       {ptr_->print(os, indent);}
00127 
00128 
00130       string header() const {return ptr_->header();}
00131 
00133       string terminatedHeader() const {return ptr_->terminatedHeader();}
00134 
00136       string footer() const {return ptr_->footer();}
00137 
00139       bool isEmpty() const {return ptr_.get()==0;}
00140 
00142       void checkTag(const string& expected) const ;
00144   
00147 
00149       void addAttribute(const string& name, const string& value)
00150         {ptr_->addAttribute(name, value);}
00151       
00153       void addDouble(const string& name, double val)
00154         {addAttribute(name, Teuchos::toString(val));}
00155 
00157       void addInt(const string& name, int val)
00158         {addAttribute(name, Teuchos::toString(val));}
00159 
00161       void addBool(const string& name, bool val)
00162         {addAttribute(name, Teuchos::toString(val));}
00163       
00165       void addChild(const XMLObject& child)
00166         {ptr_->addChild(child);}
00167 
00169       void addContent(const string& contentLine)
00170         {ptr_->addContent(contentLine);}
00172   
00173     private:
00174       RefCountPtr<XMLObjectImplem> ptr_;
00175     };
00176 
00180   inline ostream& operator<<(ostream& os, const XMLObject& xml)
00181     {
00182       xml.print(os, 0);
00183       return os;
00184     }
00185 
00189   inline string toString(const XMLObject& xml)
00190     {
00191       return xml.toString();
00192     }
00193 
00194 }
00195 #endif
00196 

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