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;
118 drain::StringTools::import(++nextID,
id);
127 void swap(NodeXML<T> & node);
131 T getNativeType()
const {
132 return static_cast<T
>(type);
138 void set(
const NodeXML & node){
141 setType(node.getType());
143 else if (type == STYLE) {
145 mout.suspicious(
"copying STYLE from node: ", node);
147 drain::MapTools::setValues<map_t>(getAttributes(), node.getAttributes());
152 void set(
const intval_t & type){
158 void set(
const std::string & s){
163 void set(
const char *s){
175 void set(
const std::initializer_list<std::pair<const char *,const Variable> > & args){
179 mout.
deprecating(
"Setting attributes/style of a STYLE element.");
189 for (
const auto & entry: args){
190 getAttributes()[entry.first] = entry.second;
199 void set(
const std::map<std::string, V> & args){
203 mout.deprecating(
"Setting attributes/style of a STYLE element: ");
222 void set(
const std::string & key,
const V & value){
225 if (this->isStyle()){
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);
262 const std::string &
getTag(
const T & type){
276 NodeXML & operator=(
const xml_tag_t & x){
283 NodeXML & operator=(
const Castable &c){
290 NodeXML & operator=(
const std::string &s){
296 NodeXML & operator=(
const char *s){
302 NodeXML & operator=(
const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
314 std::ostream &
nodeToStream(std::ostream & ostr, tag_display_mode mode=EMPTY_TAG)
const override;
319 std::ostream &
docToStream(std::ostream & ostr,
const V & tree){
320 V::node_data_t::xml_node_t::docTypeToStream(ostr);
321 V::node_data_t::xml_node_t::toStream(ostr, tree);
344 for (
const auto & entry: xmldoc_attribs){
369 static xmldoc_attrib_map_t xmldoc_attribs;
380 this->classList.swap(node.classList);
398const std::string & NodeXML<int>::getTag()
const {
402typedef NodeXML<>::xml_tree_t TreeXML;
406template <
class E,
bool EX,
class P>
407struct TypeName<
drain::UnorderedMultiTree<NodeXML<E>,EX,P> > {
409 static const std::string & str(){
424 if (mode != CLOSING_TAG){
429 else if (isComment()){
431 if (mode != CLOSING_TAG){
435 else if (isScopeJS()){
436 if (mode != CLOSING_TAG){
459 if (isUndefined() || getTag().empty()){
460 drain::Logger(__FILE__, __FUNCTION__).
warn(
"Undefined TAG type for ", getName(),
" ID=", getId(),
" attr=", drain::sprinter(getAttributes()));
462 ostr <<
"<!-- " << getTag() <<
" tag? " << ctext <<
" /-->";
467 if (mode==CLOSING_TAG){
481 if (mode != CLOSING_TAG){
488 specificAttributesToStream(ostr);
503 for (
const auto & entry: getMap()){
505 std::string v = get(entry.first,
"");
508 xmlAttribToStream(ostr, entry.first, v);
534 if (mode != OPENING_TAG){
540 else if (isUndefined() || getTag().empty()){
549 else if (mode==EMPTY_TAG){
564std::ostream & operator<<(std::ostream &ostr,
const NodeXML<N> & node){
565 return node.nodeToStream(ostr);
580DRAIN_ENUM_DICT2(
int,XML);
584template <
class E,
bool EX,
class P>
585std::ostream & operator<<(std::ostream &ostr,
const UnorderedMultiTree<NodeXML<E>,EX,P> & tree){
618#define DRAIN_XML_DEFAULT_ELEMS(xml_tree) template <> const NodeXML<xml_tree::node_data_t::tag_t>::xml_default_elem_map_t NodeXML<xml_tree::node_data_t::tag_t>::xml_default_elems
638#define DRAIN_XML_DEFAULT_INIT(xml_tree) template <> inline void xml_tree::initChild(xml_tree & child) const { UtilsXML::initChildWithDefaultType(*this, child); }
655#define DRAIN_XML_EASY_TYPE(xml_tree) template <> template <> inline xml_tree & xml_tree::operator()(const xml_tree::node_data_t::tag_t & type){ return UtilsXML::setType(*this, type); }
658#define DRAIN_XML_ENUM_KEY(xml_tree, enum_type) template <> template <> inline const xml_tree::key_t & xml_tree::getKey(const enum_type & type){ return Enum<enum_type>::dict.getKey(type, false); }
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 & 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:342
virtual const std::string & getTag() const
Definition TreeXML.h:253
std::list< std::pair< std::string, std::string > > xmldoc_attrib_map_t
Internal function called after setType()
Definition TreeXML.h:368
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:420
static const std::string & getTag(const T &type)
Definition TreeXML.h:262
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:353
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:175
NodeXML(const NodeXML &node)
Copy constructor.
Definition TreeXML.h:117
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:672
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:706
Definition DataSelector.cpp:1277
A container for a static dictionary of enumeration values.
Definition Enum.h:51
static const std::string & getKey(const std::string &s, bool lenient=true)
Convenience for object.set(...) like commands.
Definition Enum.h:144