|
|
@ -525,6 +525,63 @@ namespace xml { |
|
|
|
const Node& Factory::operator*() const throw() { |
|
|
|
const Node& Factory::operator*() const throw() { |
|
|
|
return _template[0]; |
|
|
|
return _template[0]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Factory& factory) throw() { |
|
|
|
|
|
|
|
return factory.print(os, *factory); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::ostream& Factory::print(std::ostream& os, const Node& node, |
|
|
|
|
|
|
|
unsigned int level) throw() { |
|
|
|
|
|
|
|
if (node.children()) { |
|
|
|
|
|
|
|
os<<std::string(level, '\t')<<'<'<<node.name(); |
|
|
|
|
|
|
|
for (Attributes::const_iterator it(node.attributes().begin()); |
|
|
|
|
|
|
|
it!=node.attributes().end(); ++it) |
|
|
|
|
|
|
|
os<<' '<<it->first<<"=\""<<it->second<<'"'; |
|
|
|
|
|
|
|
os<<'>'; |
|
|
|
|
|
|
|
if (dynamic_cast<const UnsignedInteger*>(&node)) |
|
|
|
|
|
|
|
os<<" (Unsigned Integer"; |
|
|
|
|
|
|
|
else if (dynamic_cast<const String*>(&node)) |
|
|
|
|
|
|
|
os<<" (String"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
os<<" (Node"; |
|
|
|
|
|
|
|
if (node.min()==1 && node.max()==1) |
|
|
|
|
|
|
|
os<<", required exactly once)"; |
|
|
|
|
|
|
|
else if (node.min()==1 && node.max()==0) |
|
|
|
|
|
|
|
os<<", required at least once)"; |
|
|
|
|
|
|
|
else if (node.min()==0 && node.max()==0) |
|
|
|
|
|
|
|
os<<", 0..n)"; |
|
|
|
|
|
|
|
else if (node.min()==0 && node.max()==1) |
|
|
|
|
|
|
|
os<<", optional)"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
os<<", "<<node.min()<<".."<<node.max()<<")"; |
|
|
|
|
|
|
|
os<<std::endl; |
|
|
|
|
|
|
|
for (Node::size_type i(0); i<node.children(); ++i) |
|
|
|
|
|
|
|
print(os, node[i], level+1); |
|
|
|
|
|
|
|
os<<std::string(level, '\t')<<"</"<<node.name()<<'>'; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
os<<std::string(level, '\t')<<'<'<<node.name(); |
|
|
|
|
|
|
|
for (Attributes::const_iterator it(node.attributes().begin()); |
|
|
|
|
|
|
|
it!=node.attributes().end(); ++it) |
|
|
|
|
|
|
|
os<<' '<<it->first<<"=\""<<it->second<<'"'; |
|
|
|
|
|
|
|
os<<"/>"; |
|
|
|
|
|
|
|
if (dynamic_cast<const UnsignedInteger*>(&node)) |
|
|
|
|
|
|
|
os<<" (Unsigned Integer"; |
|
|
|
|
|
|
|
else if (dynamic_cast<const String*>(&node)) |
|
|
|
|
|
|
|
os<<" (String"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
os<<" (Node"; |
|
|
|
|
|
|
|
if (node.min()==1 && node.max()==1) |
|
|
|
|
|
|
|
os<<", required exactly once)"; |
|
|
|
|
|
|
|
else if (node.min()==1 && node.max()==0) |
|
|
|
|
|
|
|
os<<", required at least once)"; |
|
|
|
|
|
|
|
else if (node.min()==0 && node.max()==0) |
|
|
|
|
|
|
|
os<<", 0..n)"; |
|
|
|
|
|
|
|
else if (node.min()==0 && node.max()==1) |
|
|
|
|
|
|
|
os<<", optional)"; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
os<<", "<<node.min()<<".."<<node.max()<<")"; |
|
|
|
|
|
|
|
os<<std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return os; |
|
|
|
|
|
|
|
} |
|
|
|
std::auto_ptr<Node> Factory::read(std::istream& is) |
|
|
|
std::auto_ptr<Node> Factory::read(std::istream& is) |
|
|
|
throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, |
|
|
|
throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, |
|
|
|
second_slash_in_tag, |
|
|
|
second_slash_in_tag, |
|
|
|