45#include "TreeUnordered.h"
57class NodeXML :
public XML {
62 typedef NodeXML<T> xml_node_t;
64 typedef UnorderedMultiTree<xml_node_t,false, path_t> xml_tree_t;
67 NodeXML(
const intval_t & t = intval_t(0)){
69 drain::StringTools::import(++nextID,
id);
74 NodeXML(
const NodeXML & node){
76 drain::StringTools::import(++nextID,
id);
84 void setType(
const T2 &t){
85 type =
static_cast<intval_t
>(t);
97 const intval_t & getType()
const {
102 T getNativeType()
const {
103 return static_cast<T
>(type);
124 const std::string &
getTag(
const T & type){
131 void set(
const NodeXML & node){
134 setType(node.getType());
136 else if (type == STYLE) {
138 mout.suspicious(
"copying STYLE from node: ", node);
140 drain::SmartMapTools::setValues<map_t>(getAttributes(), node.getAttributes());
144 void set(
const intval_t & type){
149 void set(
const std::string & s){
154 void set(
const char *s){
179 void set(
const std::initializer_list<std::pair<const char *,const Variable> > & args){
183 mout.
deprecating(
"Setting attributes/style of a STYLE element.");
193 for (
const auto & entry: args){
194 getAttributes()[entry.first] = entry.second;
203 void set(
const std::map<std::string, V> & args){
207 mout.deprecating(
"Setting attributes/style of a STYLE element: ", args);
217 drain::SmartMapTools::setValues<map_t,true>(getAttributes(), args);
225 void set(
const std::string & key,
const V & value){
229 mout.deprecating(
"Setting style as attributes of a STYLE element: ", key,
':', value);
230 setStyle(key, value);
232 else if (key ==
"style"){
234 mout.obsolete(
"Setting style as attribute: \"style\"=", value);
236 else if (key ==
"class"){
239 drain::StringTools::import(value, cls);
249 NodeXML & operator=(
const NodeXML & node){
255 NodeXML & operator=(
const xml_tag_t & x){
262 NodeXML & operator=(
const Castable &c){
269 NodeXML & operator=(
const std::string &s){
275 NodeXML & operator=(
const char *s){
281 NodeXML & operator=(
const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
293 std::ostream &
nodeToStream(std::ostream & ostr, tag_display_mode mode=EMPTY_TAG)
const;
299 std::ostream &
docToStream(std::ostream & ostr,
const V & tree){
300 V::node_data_t::xml_node_t::docTypeToStream(ostr);
301 V::node_data_t::xml_node_t::toStream(ostr, tree);
324 for (
const auto & entry: xmldoc_attribs){
325 xmlAttribToStream(ostr, entry.first, entry.second);
345 typedef std::map<xml_tag_t,xml_tag_t> xml_default_elem_map_t;
346 static const xml_default_elem_map_t xml_default_elems;
357 drain::Logger(__FILE__, __FUNCTION__).
reject(
"handleType( ", (
int)type,
" ) - this is available only as specialized, by inherited classed like SVG, HTML?");
368 static xmldoc_attrib_map_t xmldoc_attribs;
390typedef NodeXML<>::xml_tree_t TreeXML;
394template <
class E,
bool EX,
class P>
395struct TypeName<
drain::UnorderedMultiTree<NodeXML<E>,EX,P> > {
397 static const std::string & str(){
435 if (mode != CLOSING_TAG){
440 else if (isComment()){
442 if (mode != CLOSING_TAG){
448 if (mode==CLOSING_TAG){
455 if (getTag().empty()){
456 drain::Logger(__FILE__, __FUNCTION__).
unimplemented<LOG_ERR>(
"defaultTag for type=", getType(),
" requested by for ID=", getId(),
" attr=", getAttributes());
458 ostr <<
"defaultTag";
468 if (mode != CLOSING_TAG){
475 specificAttributesToStream(ostr);
480 for (
const auto & key: getAttributes().getKeyList()){
481 std::string v = get(key,
"");
484 xmlAttribToStream(ostr, key, v);
510 if (mode != OPENING_TAG){
516 else if (mode==EMPTY_TAG){
531std::ostream & operator<<(std::ostream &ostr,
const NodeXML<N> & node){
532 return node.nodeToStream(ostr);
547template <
class E,
bool EX,
class P>
548std::ostream & operator<<(std::ostream &ostr,
const UnorderedMultiTree<
NodeXML<E>,EX,P> & tree){
Two-way mapping between strings and objects of template class T.
Definition Dictionary.h:63
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition Log.h:610
Logger & unimplemented(const TT &... args)
Feature to be done. Special type of Logger::note().
Definition Log.h:511
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition Log.h:521
static std::ostream & docTypeToStream(std::ostream &ostr)
Write the XML definition beginning any XML document.
Definition TreeXML.h:322
virtual const std::string & getTag() const
Definition TreeXML.h:115
std::list< std::pair< std::string, std::string > > xmldoc_attrib_map_t
NOTE: these could/should be templated, in TreeXML<...> right?
Definition TreeXML.h:367
virtual void handleType(const T &type)
Internal function called after setType()
Definition TreeXML.h:355
virtual std::ostream & nodeToStream(std::ostream &ostr, tag_display_mode mode=EMPTY_TAG) const
Dumps info. Future option: outputs leading and ending tag.
Definition TreeXML.h:431
static const std::string & getTag(const T &type)
Definition TreeXML.h:124
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
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:179
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:321
Definition StringBuilder.h:58
void addClass(const TT &... args)
Style class.
Definition TreeXML.h:220
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 X & xmlAssignNode(X &dst, const X &src)
Assign another tree structure to another.
Definition XML.h:554
Definition DataSelector.cpp:1277
Wrapper for unique (static) dictionary of enum values.
Definition EnumFlags.h:66
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:558