45 #include <drain/Sprinter.h>
46 #include <drain/FlexibleVariable.h>
51 #include "ReferenceMap.h"
60 class StyleXML :
public ReferenceMap2<FlexibleVariable> {
67 static const SprinterLayout styleLineLayout;
68 static const SprinterLayout styleRecordLayout;
69 static const SprinterLayout styleRecordLayoutActual;
76 std::ostream & operator<<(std::ostream &ostr,
const StyleXML & style){
83 class XML :
protected ReferenceMap2<FlexibleVariable> {
92 static const intval_t UNDEFINED = 0;
93 static const intval_t COMMENT = 1;
94 static const intval_t CTEXT = 2;
95 static const intval_t SCRIPT = 3;
96 static const intval_t STYLE = 4;
97 static const intval_t STYLE_SELECT = 5;
100 intval_t type = XML::UNDEFINED;
102 typedef ReferenceMap2<FlexibleVariable> map_t;
118 static int getCount(){
157 template <
char C=
'\0',
typename ...TT>
175 template <
class ...T>
190 void setText(
const std::string & s);
192 template <
class ...T>
193 void setText(
const T & ...args) {
198 void setUrl(
const std::string & s){
202 template <
class ...T>
204 void setName(
const T & ...args){
213 return map_t::empty();
217 const map_t & getAttributes()
const {
223 map_t & getAttributes(){
243 V get(
const std::string & key,
const V & defaultValue)
const {
248 std::string get(
const std::string & key,
const char * defaultValue)
const {
256 (*this)[key] = value;
263 (*this)[key] = value;
270 (*this)[key] = value;
275 void removeAttribute(
const std::string & s){
277 if (it != this->end()){
292 const StyleXML & getStyle()
const {
297 void setStyle(
const StyleXML & s){
302 void setStyle(
const std::string & value){
304 if (type == UNDEFINED){
305 mout.reject<LOG_WARNING>(
"setting style for UNDEFINED elem: ", value);
306 mout.unimplemented<LOG_WARNING>(
"future option: set type to STYLE_SELECT");
308 else if (type == STYLE){
309 mout.reject<LOG_WARNING>(
"not setting style for STYLE elem: ", value);
317 void setStyle(
const char *value){
318 setStyle(std::string(value));
322 void setStyle(
const std::string & key,
const std::string & value){
324 if (type == UNDEFINED){
325 mout.reject<LOG_WARNING>(
"setting style for UNDEFINED elem: ", key,
'=', value);
326 mout.unimplemented<LOG_WARNING>(
"future option: set type to STYLE_SELECT");
328 else if (type == STYLE){
329 mout.reject<LOG_WARNING>(
"not setting style for STYLE elem: ", value);
332 this->style[key] = value;
346 void setStyle(
const std::string & key,
const std::initializer_list<V> &l){
352 this->style[key] = l;
362 void setStyle(
const std::string & key,
const V & value){
365 drain::Logger(__FILE__, __FUNCTION__).
reject<LOG_WARNING>(
"Setting style of STYLE: ", key,
"=", value);
368 this->style[key] = value;
381 void setStyle(
const std::initializer_list<std::pair<const char *,const drain::Variable> > &args){
406 ClassListXML classList;
410 const ClassListXML & getClasses()
const {
414 template <
typename ... TT>
417 classList.add(args...);
426 return classList.has(cls);
430 void removeClass(
const std::string & s) {
441 void specificAttributesToStream(std::ostream & ostr)
const;
448 void xmlAttribToStream(std::ostream &ostr,
const std::string & key,
const V &value){
449 ostr <<
' ' << key <<
'=' <<
'"' << value <<
'"';
456 template <
typename TX>
463 dst->setType(src->getType());
464 dst->ctext = src->ctext;
465 dst->getAttributes() = src->getAttributes();
475 template <
typename TX>
477 TX &
xmlAssign(TX & dst,
const typename TX::xml_node_t & src){
479 if (&src != &dst.data){
481 dst->getAttributes().importMap(src.getAttributes());
482 dst->setStyle(src.getStyle());
483 dst->setText(src.ctext);
495 template <
typename X>
502 dst.setType(src.getType());
503 dst.getAttributes().importMap(src.getAttributes());
504 dst.setStyle(src.getStyle());
505 dst.ctext = src.ctext;
515 template <
typename TX,
typename V>
526 template <
typename TX>
529 TX &
xmlAssign(TX & tree, std::initializer_list<std::pair<const char *,const Variable> > l){
531 switch (
static_cast<intval_t
>(tree->getType())){
533 for (
const auto & entry: l){
534 TX & elem = tree[entry.first];
535 elem->setType(STYLE_SELECT);
540 tree->setType(STYLE_SELECT);
557 template <
typename TX>
559 TX &
xmlSetType(TX & tree,
const typename TX::node_data_t::xml_tag_t & type){
571 template <
typename T>
574 typename T::node_data_t::xml_tag_t type = xmlRetrieveDefaultType(tree.data);
577 return tree[key](type);
580 std::stringstream k(
"elem");
583 k << tree.getChildren().size();
584 return tree[k.str()](type);
600 template <
typename N>
602 typename N::xml_tag_t xmlRetrieveDefaultType(
const N & parentNode){
603 typedef typename N::xml_default_elem_map_t map_t;
604 const typename map_t::const_iterator it = N::xml_default_elems.find(parentNode.getNativeType());
605 if (it != N::xml_default_elems.end()){
609 return static_cast<typename N::xml_tag_t
>(0);
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:310
Logger & reject(const TT &... args)
Some input has been rejected, for example by a syntax.
Definition: Log.h:608
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:428
ref_t & link(const std::string &key, F &x)
Associates a map entry with a variable.
Definition: ReferenceMap.h:84
map_t::iterator iterator
Needed?
Definition: SmartMap.h:80
std::string get(const std::string &key, const std::string &defaultValue) const
Retrieves a value, or default value if value is unset.
Definition: SmartMap.h:127
static const SprinterLayout xmlAttributeLayout
Like attributes in XML (HTML, SVG, ...) tags.
Definition: Sprinter.h:227
static std::ostream & toStream(std::ostream &ostr, const std::initializer_list< T > &x, const SprinterLayout &layout=defaultLayout)
New (experimental)
Definition: Sprinter.h:420
Definition: StringBuilder.h:58
VariableT is a final class applied through typedefs Variable, Reference and FlexibleVariable.
Definition: VariableT.h:87
void addClass(const TT &... args)
Style class.
Definition: TreeXML.h:220
void setId()
Makes ID a visible attribute.
Definition: XML.h:146
static X & xmlAssignNode(X &dst, const X &src)
Assign another tree structure to another.
Definition: XML.h:497
static TX & xmlSetType(TX &tree, const typename TX::node_data_t::xml_tag_t &type)
Definition: XML.h:559
static T & xmlAddChild(T &tree, const std::string &key)
Definition: XML.h:573
void setStyle(const std::string &key, const std::initializer_list< V > &l)
Set style of an element.
Definition: XML.h:346
virtual void setAttribute(const std::string &key, const char *value)
Default implementation. Needed for handling units in strings, like "50%" or "640px".
Definition: XML.h:262
static TX & xmlAssign(TX &tree, std::initializer_list< std::pair< const char *, const Variable > > l)
Tree.
Definition: XML.h:529
void setId(const TT &...args)
Concatenates arguments to an id.
Definition: XML.h:159
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
const std::string & getId() const
Returns ID of this element. Hopefully a unique ID...
Definition: XML.h:165
static TX & xmlAssign(TX &dst, const TX &src)
Assign another tree structure to another.
Definition: XML.h:458
static TX & xmlAssign(TX &dst, const typename TX::xml_node_t &src)
Assign another tree structure to another.
Definition: XML.h:477
virtual void clear()
Clear style, class and string data but keep the element type.
Definition: XML.cpp:66
static TX & xmlAssign(TX &tree, const V &arg)
Assign another tree structure to another.
Definition: XML.h:517
void reset()
Clear style, class and string data as well as the element type.
Definition: XML.h:136
void setStyle(const std::string &key, const V &value)
For element/class/id, assign ...
Definition: XML.h:362
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:72
void setComment(const T &...args)
Make this node a comment. Contained tree will not be deleted. In current version, attributes WILL be ...
Definition: XML.h:177
void setAttribute(const std::string &key, const V &value)
"Final" implementation.
Definition: XML.h:269
bool hasClass(const V &cls) const
Definition: XML.h:425
std::string id
Some general-purpose.
Definition: TreeXML.h:95
void setId(const std::string &s)
Makes ID a visible attribute, with a given value.
Definition: XML.h:152
Definition: DataSelector.cpp:1277