42 #ifndef Teuchos_XMLOBJECT_H
43 #define Teuchos_XMLOBJECT_H
56 {
public:
EmptyXMLError(
const std::string& what_arg) : std::runtime_error(what_arg) {}};
62 class TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
XMLObject{
93 const std::string& getTag()
const;
96 bool hasAttribute(
const std::string& name)
const;
99 const std::string& getAttribute(
const std::string& name)
const;
102 const std::string& getRequired(
const std::string& name)
const;
106 {
return std::atof(getRequired(name).c_str());}
110 {
return std::atoi(getRequired(name).c_str());}
116 std::istringstream iss(getRequired(name));
122 bool getRequiredBool(
const std::string& name)
const ;
128 if (hasAttribute(name)){
129 return getRequired<T>(name);
137 int numChildren()
const;
145 int findFirstChild(std::string tagName)
const;
148 int numContentLines()
const;
151 const std::string& getContentLine(
int i)
const;
154 std::string toString()
const;
157 void print(std::ostream& os,
int indent)
const;
160 std::string header()
const;
163 std::string terminatedHeader()
const;
166 std::string footer()
const;
172 void checkTag(
const std::string& expected)
const ;
180 {addAttribute(name, Teuchos::toString(val));}
183 void addInt(
const std::string& name,
int val)
184 {addAttribute(name, Teuchos::toString(val));}
187 void addBool(
const std::string& name,
bool val)
188 {addAttribute(name, Teuchos::toString(val));}
195 "XMLObject::addAttribute: XMLObject is empty");
196 ptr_->addAttribute(name, Teuchos::toString(value));
204 void addContent(
const std::string& contentLine);
207 void appendContentLine(
const size_t& i,
const std::string &str) {
208 ptr_->appendContentLine(i, str);
211 void removeContentLine(
const size_t& i) {
212 ptr_->removeContentLine(i);
219 #pragma warning(push)
220 #pragma warning(disable:4251)
222 RCP<XMLObjectImplem> ptr_;
231 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
bool XMLObject::getRequired<bool>(
const std::string& name)
const;
234 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
int XMLObject::getRequired<int>(
const std::string& name)
const;
237 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
double XMLObject::getRequired<double>(
const std::string& name)
const;
240 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT std::string XMLObject::getRequired<std::string>(
const std::string& name)
const;
243 TEUCHOSPARAMETERLIST_LIB_DLL_EXPORT
void XMLObject::addAttribute<const std::string&>(
const std::string& name,
const std::string& value);
void addBool(const std::string &name, bool val)
Add a bool as an attribute.
std::string toString(const XMLObject &xml)
Write XMLObject to std::string.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
int getRequiredInt(const std::string &name) const
Get a required attribute, returning it as an int.
T getRequired(const std::string &name) const
Get a required attribute, returning it as T.
bool isEmpty() const
Find out if a node is empty.
XMLObject()
Empty constructor.
Thrown when attempting to parse an empty XML std::string.
double getRequiredDouble(const std::string &name) const
Get a required attribute, returning it as a double.
Low level implementation of XMLObject.
std::string toString() const
Represent this node and its children as a std::string.
Representation of an XML data tree. XMLObject is a ref-counted handle to a XMLObjectImplem object...
std::ostream & operator<<(std::ostream &os, const XMLObject &xml)
Write XMLObject to os stream.
void addAttribute(const std::string &name, T value)
Lookup whether or not Doubles are allowed.
void print(std::ostream &os, int indent) const
Print this node and its children to stream with the given indentation.
void addInt(const std::string &name, int val)
Add an int as an attribute.
The XMLObjectImplem class takes care of the low-level implementation details of XMLObject.
T getWithDefault(const std::string &name, const T &defaultValue) const
Get an attribute, assigning a default value if the requested attribute does not exist.
A utilities class for Teuchos.
void addDouble(const std::string &name, double val)
Add a double as an attribute.