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: ");
221 void set(
const std::string & key,
const V & value){
225 mout.deprecating(
"Setting style as attributes of a STYLE element: ", key,
':', value);
226 setStyle(key, value);
228 else if (key ==
"style"){
230 mout.obsolete(
"Setting style as attribute: \"style\"=", value);
232 else if (key ==
"class"){
235 drain::StringTools::import(value, cls);
258 const std::string &
getTag(
const T & type){
272 NodeXML & operator=(
const xml_tag_t & x){
279 NodeXML & operator=(
const Castable &c){
286 NodeXML & operator=(
const std::string &s){
292 NodeXML & operator=(
const char *s){
298 NodeXML & operator=(
const std::initializer_list<std::pair<const char *,const drain::Variable> > &l){
310 std::ostream &
nodeToStream(std::ostream & ostr, tag_display_mode mode=EMPTY_TAG)
const override;
315 std::ostream &
docToStream(std::ostream & ostr,
const V & tree){
316 V::node_data_t::xml_node_t::docTypeToStream(ostr);
317 V::node_data_t::xml_node_t::toStream(ostr, tree);
340 for (
const auto & entry: xmldoc_attribs){
365 static xmldoc_attrib_map_t xmldoc_attribs;
376 this->classList.swap(node.classList);
394const std::string & NodeXML<int>::getTag()
const {
398typedef NodeXML<>::xml_tree_t TreeXML;
402template <
class E,
bool EX,
class P>
403struct TypeName<
drain::UnorderedMultiTree<NodeXML<E>,EX,P> > {
405 static const std::string & str(){
420 if (mode != CLOSING_TAG){
425 else if (isComment()){
427 if (mode != CLOSING_TAG){
431 else if (isScopeJS()){
432 if (mode != CLOSING_TAG){
454 if (isUndefined() || getTag().empty()){
455 drain::Logger(__FILE__, __FUNCTION__).
warn(
"Undefined TAG type for ", getName(),
" ID=", getId(),
" attr=", drain::sprinter(getAttributes()));
457 ostr <<
"<!-- " << getTag() <<
" tag? " << ctext <<
" /-->";
462 if (mode==CLOSING_TAG){
476 if (mode != CLOSING_TAG){
483 specificAttributesToStream(ostr);
498 for (
const auto & entry: getMap()){
500 std::string v = get(entry.first,
"");
503 xmlAttribToStream(ostr, entry.first, v);
529 if (mode != OPENING_TAG){
535 else if (isUndefined() || getTag().empty()){
544 else if (mode==EMPTY_TAG){
559std::ostream & operator<<(std::ostream &ostr,
const NodeXML<N> & node){
560 return node.nodeToStream(ostr);
575DRAIN_ENUM_DICT2(
int,XML);
579template <
class E,
bool EX,
class P>
580std::ostream & operator<<(std::ostream &ostr,
const UnorderedMultiTree<NodeXML<E>,EX,P> & tree){
613#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
633#define DRAIN_XML_DEFAULT_INIT(xml_tree) template <> inline void xml_tree::initChild(xml_tree & child) const { UtilsXML::initChildWithDefaultType(*this, child); }
650#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); }
653#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:338
virtual const std::string & getTag() const
Definition TreeXML.h:249
std::list< std::pair< std::string, std::string > > xmldoc_attrib_map_t
Internal function called after setType()
Definition TreeXML.h:364
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:416
static const std::string & getTag(const T &type)
Definition TreeXML.h:258
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:349
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
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:630
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:664
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
static const std::string name
Default implementation: name returned by std::type_info::name()
Definition Type.h:549