37#ifndef DRAIN_UTILS_XML
38#define DRAIN_UTILS_XML
42#include "SelectorXML.h"
66 assignNode(dst.data, src);
76 template <
typename TX>
78 TX &
assign(TX & dst,
const typename TX::xml_node_t & src){
79 assignNode(dst.data, src);
88 template <
typename T,
typename V>
102 T &
assign(T & tree, std::initializer_list<std::pair<const char *,const Variable> > l){
105 switch (tree->getType()){
107 for (
const auto & entry: l){
108 T & elem = tree[entry.first];
109 elem->setType(XML::STYLE_SELECT);
114 tree->setType(XML::STYLE_SELECT);
116 case XML::STYLE_SELECT:
132 template <
typename TX>
135 if (tree->isUndefined()){
136 tree->setType(XML::CTEXT);
142 template <
typename TX>
144 TX & appendString(TX & tree,
const std::string & s){
145 if (tree->isCText()){
149 else if (tree->isUndefined()){
150 tree->setType(XML::CTEXT);
157 TX & child = tree.addChild();
158 child->setType(XML::CTEXT);
170 template <
typename TX>
172 TX &
setType(TX & tree,
const typename TX::node_data_t::xml_tag_t & type){
182 template <
typename N>
185 typedef typename N::xml_default_elem_map_t map_t;
186 const typename map_t::const_iterator it = N::xml_default_elems.find(parentNode.getNativeType());
187 if (it != N::xml_default_elems.end()){
191 return static_cast<typename N::xml_tag_t
>(0);
195 template <
typename T>
197 bool initChildWithDefaultType(
const T & tree, T & child){
199 if (
static_cast<int>(type) != 0){
200 child->setType(type);
208 template <
typename T>
210 T & getHeaderObject(T & root,
typename T::node_data_t::xml_tag_t tag,
const typename T::path_elem_t & key =
typename T::path_elem_t()){
214 if (!root.hasChild(finalKey)){
215 T & child = root.prependChild(finalKey);
220 return root[finalKey];
224 template <
typename T>
226 T & ensureStyle(T & root,
const SelectXML<typename T::node_data_t::xml_tag_t> & selector,
const std::initializer_list<std::pair<const char *,const Variable> > & styleDef){
228 T & style = getHeaderObject(root, T::node_data_t::xml_tag_t::STYLE);
230 T & styleEntry = style[selector];
231 if (styleEntry.empty()){
232 styleEntry = styleDef;
241 template <
typename N,
typename ...TT>
243 UnorderedMultiTree<N> & ensureJavaScriptFunction(UnorderedMultiTree<N> & root,
const std::string & name,
const TT & ...args){
245 typedef UnorderedMultiTree<N> T;
246 T & jsFunction = getHeaderObject(root, T::node_data_t::xml_tag_t::SCRIPT, name);
248 if (jsFunction.empty()){
249 jsFunction->setText(
"function ", name,
'(', args...,
')');
258 template <
typename N>
264 typedef UnorderedMultiTree<N> T;
269 if (c == T::path_t::separator.character){
273 mout.
note(
"mapped id:",
id);
275 T & treeJS = getHeaderObject(root, T::node_data_t::xml_tag_t::SCRIPT,
id);
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & note(const TT &... args)
For top-level information.
Definition Log.h:490
Base class for XML "nodes", to be data elements T for drain::Tree<T>
Definition UtilsXML.h:49
static T & assign(T &tree, std::initializer_list< std::pair< const char *, const Variable > > l)
Tree.
Definition UtilsXML.h:102
static T & assign(T &tree, const V &arg)
Assign property to a XML tree node.
Definition UtilsXML.h:90
static T & assign(T &dst, const T &src)
Assign another tree structure to another.
Definition UtilsXML.h:60
static N::xml_tag_t retrieveDefaultType(const N &parentNode)
Find node type (tag id) from a predefined list of default types for (some) parent types.
Definition UtilsXML.h:184
static TX & setType(TX &tree, const typename TX::node_data_t::xml_tag_t &type)
Definition UtilsXML.h:172
static TX & assign(TX &dst, const typename TX::xml_node_t &src)
Copy node data to tree.
Definition UtilsXML.h:78
static TX & assignString(TX &tree, const std::string &s)
When assigning a string, create new element unless the element itself is of type CTEXT.
Definition UtilsXML.h:134
static UnorderedMultiTree< N > & ensureJavaScriptUrl(UnorderedMultiTree< N > &root, const std::string &url)
Definition UtilsXML.h:260
Definition DataSelector.cpp:1277
static const std::string & getKey(const std::string &s, bool lenient=true)
Convenience for object.set(...) like commands.
Definition Enum.h:144