45#include "TreeUnordered.h"
55class NodeXML :
public XML {
60 typedef NodeXML<T> xml_node_t;
62 typedef UnorderedMultiTree<xml_node_t,false, path_t> xml_tree_t;
104 drain::StringTools::import(++nextID,
id);
117 drain::StringTools::import(++nextID,
id);
126 void swap(NodeXML<T> & node);
130 T getNativeType()
const {
131 return static_cast<T
>(type);
137 void set(
const NodeXML & node){
140 setType(node.getType());
142 else if (type == STYLE) {
144 mout.suspicious(
"copying STYLE from node: ", node);
146 drain::MapTools::setValues<map_t>(getAttributes(), node.getAttributes());
151 void set(
const intval_t & type){
157 void set(
const std::string & s){
162 void set(
const char *s){
174 void set(
const std::initializer_list<std::pair<const char *,const Variable> > & args){
178 mout.
deprecating(
"Setting attributes/style of a STYLE element.");
188 for (
const auto & entry: args){
189 getAttributes()[entry.first] = entry.second;
198 void set(
const std::map<std::string, V> & args){
202 mout.deprecating(
"Setting attributes/style of a STYLE element: ", args);
212 drain::SmartMapTools::setValues<map_t,true>(getAttributes(), args);
220 void set(
const std::string & key,
const V & value){
224 mout.deprecating(
"Setting style as attributes of a STYLE element: ", key,
':', value);
225 setStyle(key, value);
227 else if (key ==
"style"){
229 mout.obsolete(
"Setting style as attribute: \"style\"=", value);
231 else if (key ==
"class"){
234 drain::StringTools::import(value, cls);
257 const std::string &
getTag(
const T & type){
271 NodeXML & operator=(
const xml_tag_t & x){
278 NodeXML & operator=(
const Castable &c){
285 NodeXML & operator=(
const std::string &s){
291 NodeXML & operator=(
const char *s){
297 NodeXML & operator=(
const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
309 std::ostream &
nodeToStream(std::ostream & ostr, tag_display_mode mode=EMPTY_TAG)
const override;
314 std::ostream &
docToStream(std::ostream & ostr,
const V & tree){
315 V::node_data_t::xml_node_t::docTypeToStream(ostr);
316 V::node_data_t::xml_node_t::toStream(ostr, tree);
339 for (
const auto & entry: xmldoc_attribs){
364 static xmldoc_attrib_map_t xmldoc_attribs;
374 this->classList.swap(node.classList);
392const std::string & NodeXML<int>::getTag()
const {
396typedef NodeXML<>::xml_tree_t TreeXML;
400template <
class E,
bool EX,
class P>
401struct TypeName<
drain::UnorderedMultiTree<NodeXML<E>,EX,P> > {
403 static const std::string & str(){
418 if (mode != CLOSING_TAG){
423 else if (isComment()){
425 if (mode != CLOSING_TAG){
432 drain::Logger(__FILE__, __FUNCTION__).
warn(
"Undefined TAG type for ", getName(),
" ID=", getId(),
" attr=", getAttributes());
435 if (mode==CLOSING_TAG){
442 if (getTag().empty()){
443 drain::Logger(__FILE__, __FUNCTION__).
unimplemented<LOG_ERR>(
"defaultTag for type=", getType(),
" requested by ID=", getId(),
" attr=", getAttributes());
445 ostr <<
"defaultTag";
455 if (mode != CLOSING_TAG){
462 specificAttributesToStream(ostr);
467 for (
const auto & key: getAttributes().getKeyList()){
468 std::string v = get(key,
"");
471 xmlAttribToStream(ostr, key, v);
497 if (mode != OPENING_TAG){
503 else if (mode==EMPTY_TAG){
518std::ostream & operator<<(std::ostream &ostr,
const NodeXML<N> & node){
519 return node.nodeToStream(ostr);
534DRAIN_ENUM_DICT2(
int,XML);
538template <
class E,
bool EX,
class P>
539std::ostream & operator<<(std::ostream &ostr,
const UnorderedMultiTree<NodeXML<E>,EX,P> & tree){
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:512
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition Log.h:522
A "handle" for specialized element classes, i.e. with members like width , height or radius .
Definition TreeXML.h:91
static std::ostream & docTypeToStream(std::ostream &ostr)
Write the XML definition beginning any XML document.
Definition TreeXML.h:337
virtual const std::string & getTag() const
Definition TreeXML.h:248
std::list< std::pair< std::string, std::string > > xmldoc_attrib_map_t
Internal function called after setType()
Definition TreeXML.h:363
virtual std::ostream & nodeToStream(std::ostream &ostr, tag_display_mode mode=EMPTY_TAG) const override
Dumps info. Future option: outputs leading and ending tag.
Definition TreeXML.h:414
static const std::string & getTag(const T &type)
Definition TreeXML.h:257
static std::ostream & docToStream(std::ostream &ostr, const V &tree)
Definition TreeXML.h:733
NodeXML & setText(const S &value)
Assign the text content of this node. If the node type is undefined, set it to CTEXT.
Definition TreeXML.h:619
std::map< xml_tag_t, xml_tag_t > xml_default_elem_map_t
Helps creating child elements. Like children of HTML element UL should be LI.
Definition TreeXML.h:348
NodeXML()
Default constructor.
Definition TreeXML.h:103
static std::ostream & toStream(std::ostream &ostr, const V &t, const std::string &defaultTag="", int indent=0)
"Forward definition" of Tree::toOstream
void set(const std::initializer_list< std::pair< const char *, const Variable > > &args)
Definition TreeXML.h:174
NodeXML(const NodeXML &node)
Copy constructor.
Definition TreeXML.h:116
A map of references to base type scalars, arrays or std::string; changing values in either are equiva...
Definition ReferenceMap.h:69
static std::ostream & sequenceToStream(std::ostream &ostr, const T &x, const SprinterLayout &layout)
Convenience: if sequence type (array, list, set, map) not given, assume array.
Definition Sprinter.h:325
Definition StringBuilder.h:58
void addClass(const TT &... args)
Style class.
Definition TreeXML.h:220
static void xmlAttribToStream(std::ostream &ostr, const std::string &key, const V &value)
Handy map for converting characters to XML entities. Example: '&' -> "&".
Definition XML.h:589
virtual void setAttribute(const std::string &key, const std::string &value)
Default implementation. Needed for handling units in strings, like "50%" or "640px".
Definition TreeXML.h:166
static N & xmlAssignNode(N &dst, const N &src)
Assign tree node (data) to another.
Definition XML.h:623
Definition DataSelector.cpp:1277
A container for a static dictionary of enumeration values.
Definition EnumUtils.h:52
static const std::string & getKey(const std::string &s, bool lenient=true)
Convenience for object.set(...) like commands.
Definition EnumUtils.h:145
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:549