|
|
|
@ -340,41 +340,43 @@ namespace xml { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
UnsingedInteger::UnsingedInteger(std::string name, const std::string& text) throw(): |
|
|
|
|
Node(name), _text(text) { |
|
|
|
|
} |
|
|
|
|
std::auto_ptr<Node> UnsingedInteger::clone() const throw() { |
|
|
|
|
return std::auto_ptr<Node>(new UnsingedInteger(*this)); |
|
|
|
|
} |
|
|
|
|
std::string UnsingedInteger::text() const throw() { |
|
|
|
|
return _text; |
|
|
|
|
} |
|
|
|
|
UnsingedInteger& UnsingedInteger::text(const std::string& txt) throw(tag_expected, |
|
|
|
|
type_mismatch) { |
|
|
|
|
_text = txt; |
|
|
|
|
UnsignedInteger::UnsignedInteger(std::string name, unsigned long i) throw(): |
|
|
|
|
String(name, |
|
|
|
|
dynamic_cast<std::stringstream&>(std::stringstream()<<i).str()) { |
|
|
|
|
} |
|
|
|
|
std::auto_ptr<Node> UnsignedInteger::clone() const throw() { |
|
|
|
|
return std::auto_ptr<Node>(new UnsignedInteger(*this)); |
|
|
|
|
} |
|
|
|
|
UnsignedInteger& UnsignedInteger::text(const std::string& txt) |
|
|
|
|
throw(tag_expected, type_mismatch) { |
|
|
|
|
std::string::size_type |
|
|
|
|
start(txt.find_first_not_of(" \t\n\r")), |
|
|
|
|
last(txt.find_last_of(" \t\n\r")); |
|
|
|
|
if (start==std::string::npos) { // empty - set to 0
|
|
|
|
|
_text = "0"; |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
std::ostream& UnsingedInteger::out(std::ostream& o, unsigned int level) const throw() { |
|
|
|
|
if (_text.size()) { |
|
|
|
|
o<<std::string(level, '\t')<<'<'<<name(); |
|
|
|
|
for (Attributes::const_iterator it(_attributes.begin()); |
|
|
|
|
it!=_attributes.end(); ++it) |
|
|
|
|
o<<' '<<it->first<<"=\""<<it->second<<'"'; |
|
|
|
|
o<<'>'<<_text<<"</"<<name()<<'>'; |
|
|
|
|
} else { |
|
|
|
|
o<<std::string(level, '\t')<<'<'<<name(); |
|
|
|
|
for (Attributes::const_iterator it(_attributes.begin()); |
|
|
|
|
it!=_attributes.end(); ++it) |
|
|
|
|
o<<' '<<it->first<<"=\""<<it->second<<'"'; |
|
|
|
|
o<<"/>"; |
|
|
|
|
} |
|
|
|
|
return o; |
|
|
|
|
if (txt.find_first_not_of |
|
|
|
|
("0123456789", start, |
|
|
|
|
last!=std::string::npos?last-start+1:txt.size()-start) |
|
|
|
|
!=std::string::npos) |
|
|
|
|
throw type_mismatch(*this, txt, |
|
|
|
|
"unsigned integer may only contain numbers"); |
|
|
|
|
unsigned long i(0); |
|
|
|
|
std::stringstream(txt)>>i; |
|
|
|
|
std::stringstream ss; |
|
|
|
|
ss<<i; |
|
|
|
|
_text = ss.str(); |
|
|
|
|
return *this; |
|
|
|
|
} |
|
|
|
|
UnsingedInteger& UnsingedInteger::append(const Node& o) throw(cannot_have_children) { |
|
|
|
|
throw cannot_have_children(*this, o); |
|
|
|
|
unsigned long UnsignedInteger::number() const throw() { |
|
|
|
|
return number(*this); |
|
|
|
|
} |
|
|
|
|
Node& UnsingedInteger::operator=(const std::string& contents) throw() { |
|
|
|
|
return text(contents); |
|
|
|
|
unsigned long UnsignedInteger::number(const Node& node) throw() { |
|
|
|
|
unsigned long i(0); |
|
|
|
|
std::stringstream ss(node.text()); |
|
|
|
|
ss>>i; |
|
|
|
|
return i; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|