45#include "TreeUnordered.h"
63 typedef UnorderedMultiTree<xml_node_t,false, path_t> xml_tree_t;
140 const std::string &
getTag()
const override {
149 const std::string &
getTag(
const T & type){
166 return static_cast<T
>(type);
176 else if (type == STYLE) {
178 mout.suspicious(
"copying STYLE from node: ", node);
180 drain::MapTools::setValues<map_t>(getAttributes(), node.getAttributes());
191 void set(
const std::string & s){
196 void set(
const char *s){
207 void set(
const std::initializer_list<std::pair<const char *,const Variable> > & args){
211 mout.
deprecating(
"Setting attributes/style of a STYLE element.");
221 for (
const auto & entry: args){
222 getAttributes()[entry.first] = entry.second;
231 void set(
const std::map<std::string, V> & args){
235 mout.deprecating(
"Setting attributes/style of a STYLE element: ");
254 void set(
const std::string & key,
const V & value){
256 if (this->isStyle()){
260 mout.deprecating(
"Setting style as attributes of a STYLE element: ", key,
':', value);
261 setStyle(key, value);
263 else if (key ==
"style"){
265 mout.obsolete(
"Setting style as attribute: \"style\"=", value);
267 else if (key ==
"class"){
271 drain::StringTools::import(value, cls);
293 NodeXML & operator=(
const xml_tag_t & x){
299 NodeXML & operator=(
const Castable &c){
306 NodeXML & operator=(
const std::string &s){
312 NodeXML & operator=(
const char *s){
318 NodeXML & operator=(
const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
330 std::ostream &
nodeToStream(std::ostream & ostr, tag_display_mode mode=EMPTY_TAG)
const override;
335 std::ostream & docToStream(std::ostream & ostr,
const V & tree){
336 V::node_data_t::xml_node_t::docTypeToStream(ostr);
337 V::node_data_t::xml_node_t::toStream(ostr, tree);
360 for (
const auto & entry: xmldoc_attribs){
389#define DRAIN_XML_TREE(N) drain::UnorderedMultiTree<N,false, NodeXML<>::path_t>
392typedef DRAIN_XML_TREE(
NodeXML<>) TreeXML;
398template <
class E,
bool EX,
class P>
401 static const std::string &
str(){
416 if (mode != CLOSING_TAG){
421 else if (isComment()){
423 if (mode != CLOSING_TAG){
427 else if (isScopeJS()){
428 if (mode != CLOSING_TAG){
429 ostr << ctext <<
"{\n";
451 if (isUndefined() || getTag().empty()){
452 drain::Logger(__FILE__, __FUNCTION__).
warn(
"Undefined TAG type for ", getName(),
" ID=", getId(),
" attr=", drain::sprinter(getAttributes()));
454 ostr <<
"<!-- " << getTag() <<
" tag? " << ctext <<
" /-->";
459 if (mode==CLOSING_TAG){
473 if (mode != CLOSING_TAG){
480 specificAttributesToStream(ostr);
495 for (
const auto & entry: getMap()){
497 std::string v = getAttribute(entry.first,
"");
500 xmlAttribToStream(ostr, entry.first, v);
526 if (mode != OPENING_TAG){
532 else if (isUndefined() || getTag().empty()){
541 else if (mode==EMPTY_TAG){
561std::ostream & operator<<(std::ostream &ostr,
const NodeXML<N> & node){
573DRAIN_ENUM_DICT2(
int,XML);
577template <
class E,
bool EX,
class P>
578std::ostream & operator<<(std::ostream &ostr,
const UnorderedMultiTree<NodeXML<E>,EX,P> & tree){
611#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
615#define DRAIN_GETKEY_ENUM(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); }
A wrapper marking string an CSS effect.
Definition ClassXML.h:57
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:326
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:440
Logger & deprecating(const TT &... args)
Feature will be removed. Special type of Logger::note().
Definition Log.h:531
A "handle" for specialized element classes, i.e. with members like width , height or radius .
Definition TreeXML.h:92
static std::ostream & docTypeToStream(std::ostream &ostr)
Write the XML definition beginning any XML document.
Definition TreeXML.h:358
std::list< std::pair< std::string, std::string > > xmldoc_attrib_map_t
Control constant variables of (note: templated, through Node<T>::)
Definition TreeXML.h:372
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:412
virtual const std::string & getTag() const override
Default implementation of tag name retrieval based on drain::Enum<t>.
Definition TreeXML.h:140
static const std::string & getTag(const T &type)
Definition TreeXML.h:149
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:103
NodeXML()
Default constructor.
Definition TreeXML.h:112
T getNativeType() const
Change attributes, styles and classes of a node.
Definition TreeXML.h:165
void set(const std::initializer_list< std::pair< const char *, const Variable > > &args)
Definition TreeXML.h:207
NodeXML(const NodeXML &node)
Copy constructor.
Definition TreeXML.h:125
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:324
Definition StringBuilder.h:58
Base class for XML "nodes", to be data elements T for drain::Tree<T>
Definition XML.h:69
int intval_t
Definition XML.h:81
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:853
virtual void setAttribute(const std::string &key, const std::string &value)
Default implementation. Needed for handling units in strings, like "50%" or "640px".
Definition XML.h:556
static std::ostream & toStream(std::ostream &ostr, const UnorderedMultiTree< N > &tree, int indent=0)
Definition XML.h:1065
void setType(const T &t)
Definition XML.h:200
static N & xmlAssignNode(N &dst, const N &src)
Assign tree node (data) to another.
Definition XML.h:887
virtual void setText(const std::string &s)
Assign the text content of this node. If the node type is undefined, set it to CTEXT.
Definition XML.cpp:204
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
Default implementation.
Definition TypeName.h:54
static const std::string & str()
Default implementation: name returned by std::type_info::name()
Definition TypeName.h:68