Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | List of all members
XML Class Reference
Inheritance diagram for XML:
Inheritance graph
[legend]
Collaboration diagram for XML:
Collaboration graph
[legend]

Public Types

typedef ReferenceMap2< FlexibleVariablemap_t
 
typedef drain::Path< std::string,'/'> path_t
 Tree path type.
 
typedef path_t::elem_t path_elem_t
 
typedef std::list< path_tpath_list_t
 
typedef int intval_t
 
typedef ReferenceMap2< FlexibleVariablemap_t
 

Public Member Functions

void setId ()
 Makes ID a visible attribute. More...
 
void setId (const std::string &s)
 Makes ID a visible attribute, with a given value.
 
template<char C = '\0', typename ... TT>
void setId (const TT &...args)
 
const std::string & getId () const
 Returns ID of this element. Hopefully a unique ID...
 
bool empty () const
 
const map_tgetAttributes () const
 
map_tgetAttributes ()
 
virtual void setAttribute (const std::string &key, const std::string &value)
 Default implementation. Needed for handling units in strings, like "50%" or "640px".
 
virtual void setAttribute (const std::string &key, const char *value)
 Default implementation. Needed for handling units in strings, like "50%" or "640px".
 
template<class V >
void setAttribute (const std::string &key, const V &value)
 "Final" implementation.
 
void remove (const std::string &s)
 
const drain::FlexibleVariableget (const std::string &key) const
 
drain::FlexibleVariableget (const std::string &key)
 
template<class V >
get (const std::string &key, const V &defaultValue) const
 
std::string get (const std::string &key, const char *defaultValue) const
 
template<typename ... TT>
void addClass (const TT &... args)
 Style class.
 
template<class V >
bool hasClass (const V &cls) const
 
void removeClass (const std::string &s)
 
void clearClasses ()
 
virtual void clear ()
 Clear style, class and string data but keep the element type. More...
 
void reset ()
 Clear style, class and string data as well as the element type. More...
 
void setId ()
 Makes ID a visible attribute. More...
 
void setId (const std::string &s)
 Makes ID a visible attribute, with a given value.
 
template<char C = '\0', typename ... TT>
void setId (const TT &...args)
 Concatenates arguments to an id.
 
const std::string & getId () const
 Returns ID of this element. Hopefully a unique ID...
 
template<class ... T>
void setComment (const T &...args)
 Make this node a comment. Contained tree will not be deleted. In current version, attributes WILL be rendered. More...
 
void setText (const std::string &s)
 Assign the text content of this node. If the node type is undefined, set it to CTEXT. More...
 
template<class ... T>
void setText (const T &...args)
 
void setUrl (const std::string &s)
 
template<class ... T>
void setName (const T &...args)
 
virtual bool empty () const
 
const map_tgetAttributes () const
 
map_tgetAttributes ()
 
const drain::FlexibleVariableget (const std::string &key) const
 
drain::FlexibleVariableget (const std::string &key)
 
template<class V >
get (const std::string &key, const V &defaultValue) const
 
std::string get (const std::string &key, const char *defaultValue) const
 
virtual void setAttribute (const std::string &key, const std::string &value)
 Default implementation. Needed for handling units in strings, like "50%" or "640px".
 
virtual void setAttribute (const std::string &key, const char *value)
 Default implementation. Needed for handling units in strings, like "50%" or "640px".
 
template<class V >
void setAttribute (const std::string &key, const V &value)
 "Final" implementation.
 
void removeAttribute (const std::string &s)
 
const StyleXMLgetStyle () const
 
void setStyle (const StyleXML &s)
 
void setStyle (const std::string &value)
 
void setStyle (const char *value)
 
void setStyle (const std::string &key, const std::string &value)
 
template<class V >
void setStyle (const std::string &key, const std::initializer_list< V > &l)
 Set style of an element. More...
 
template<class V >
void setStyle (const std::string &key, const V &value)
 For element/class/id, assign ...
 
void setStyle (const std::initializer_list< std::pair< const char *, const drain::Variable > > &args)
 
const ClassListXMLgetClasses () const
 
template<typename ... TT>
void addClass (const TT &... args)
 
template<class V >
bool hasClass (const V &cls) const
 
void removeClass (const std::string &s)
 
void clearClasses ()
 
virtual void specificAttributesToStream (std::ostream &ostr) const
 
template<class T >
bool findById (const T &t, const std::string &id, typename T::path_t &result, const typename T::path_t &path)
 
template<class T >
bool findById (const T &t, const std::string &id, NodeXML<>::path_list_t &result, const path_t &path)
 
template<class T , class N >
bool findByTag (const T &t, const N &tag, NodeXML<>::path_list_t &result, const path_t &path)
 
template<class T , class N >
bool findByTags (const T &t, const std::set< N > &tags, NodeXML<>::path_list_t &result, const path_t &path)
 
template<class T2 , class C >
bool findByClass (const T2 &t, const C &cls, XML::path_list_t &result, const path_t &path)
 

Static Public Member Functions

template<class V >
static void attribToStream (std::ostream &ostr, const std::string &key, const V &value)
 
static int getCount ()
 
template<class V >
static bool findById (const V &tree, const std::string &tag, typename V::path_t &result, const typename V::path_t &path=path_t())
 Find the first occurrence of given id using recursive breath-first search. More...
 
template<class V >
static bool findById (const V &tree, const std::string &tag, path_list_t &result, const path_t &path=path_t())
 Find the occurrence(s) of given ID using recursive breath-first search. More...
 
template<class V , class T >
static bool findByTag (const V &tree, const T &tag, path_list_t &result, const path_t &path=path_t())
 
template<class V , class T >
static bool findByTags (const V &tree, const std::set< T > &tags, path_list_t &result, const path_t &path=path_t())
 "Forward definition" More...
 
template<class T2 , class C >
static bool findByClass (const T2 &t, const C &cls, std::list< path_elem_t > &result)
 Finds child elements in an XML structure by class name. More...
 
template<class V , class C >
static bool findByClass (const V &t, const C &cls, path_list_t &result, const path_t &path=path_t())
 Finds elements recursively in an XML structure by class name supplied as an enumeration type. More...
 
static int getCount ()
 
template<class V >
static void xmlAttribToStream (std::ostream &ostr, const std::string &key, const V &value)
 
template<typename TX >
static TX & xmlAssign (TX &dst, const TX &src)
 Assign another tree structure to another. More...
 
template<typename TX >
static TX & xmlAssign (TX &dst, const typename TX::xml_node_t &src)
 Assign another tree structure to another. More...
 
template<typename X >
static X & xmlAssignNode (X &dst, const X &src)
 Assign another tree structure to another. More...
 
template<typename TX , typename V >
static TX & xmlAssign (TX &tree, const V &arg)
 Assign another tree structure to another. More...
 
template<typename TX >
static TX & xmlAssign (TX &tree, std::initializer_list< std::pair< const char *, const Variable > > l)
 Tree. More...
 
template<typename TX >
static TX & xmlSetType (TX &tree, const typename TX::node_data_t::xml_tag_t &type)
 
template<typename T >
static T & xmlAddChild (T &tree, const std::string &key)
 
template<typename N >
static N::xml_tag_t xmlRetrieveDefaultType (const N &parentNode)
 

Public Attributes

std::string id
 Some general-purpose. More...
 
std::string ctext
 
std::string url
 
ClassListXML classList
 
StyleXML style
 
intval_t type = XML::UNDEFINED
 

Static Public Attributes

static const int UNDEFINED = 0
 
static const int COMMENT = 1
 
static const int CTEXT = 2
 
static const int STYLE = 3
 
static const int SCRIPT = 4
 
static int nextID = 0
 
static const intval_t UNDEFINED = 0
 
static const intval_t COMMENT = 1
 
static const intval_t CTEXT = 2
 
static const intval_t SCRIPT = 3
 
static const intval_t STYLE = 4
 
static const intval_t STYLE_SELECT = 5
 

Additional Inherited Members

- Protected Types inherited from ReferenceMap2< FlexibleVariable >
enum  extLinkPolicy
 
typedef FlexibleVariable ref_t
 
typedef SmartMap< FlexibleVariablemap_t
 
- Protected Types inherited from SmartMap< FlexibleVariable >
typedef SmartMap< FlexibleVariablesmap_t
 
typedef std::map< std::string, FlexibleVariablemap_t
 
typedef map_t::key_type key_t
 
typedef map_t::mapped_type value_t
 
typedef map_t::value_type entry_t
 
typedef std::list< std::string > keylist_t
 
typedef map_t::iterator iterator
 Needed?
 
typedef map_t::const_iterator const_iterator
 
- Protected Member Functions inherited from ReferenceMap2< FlexibleVariable >
ref_tlink (const std::string &key, F &x)
 Associates a map entry with a variable. More...
 
ref_tlink (const std::string &key, void *ptr, const std::type_info &type, size_t count=1)
 Create a reference to a basic type or std::string. (Also for basetype arrays.)
 
void unlink (const std::string &key)
 
void copyStruct (const ReferenceMap2< FlexibleVariable > &m, const T2 &src, T2 &dst, extLinkPolicy policy=RESERVE)
 Experimental. Copies references and values of a structure to another. More...
 
- Protected Member Functions inherited from SmartMap< FlexibleVariable >
 SmartMap (char separator='\0', char arraySeparator=':')
 
 SmartMap (const SmartMap &smap)
 
bool hasKey (const std::string &key) const
 
std::string get (const std::string &key, const std::string &defaultValue) const
 Retrieves a value, or default value if value is unset. More...
 
std::string get (const std::string &key, const char *defaultValue) const
 
T2 get (const std::string &key, const T2 &defaultValue) const
 Retrieves a value, if set, else returns the given default value. More...
 
virtual FlexibleVariableoperator[] (const std::string &key)
 Returns an element. Creates one, conditionally. More...
 
virtual const FlexibleVariableoperator[] (const std::string &key) const
 Unlike with std::map, operator[] const is defined, returning reference to a static empty instance.
 
virtual const keylist_t & getKeyList () const
 Derived versions may produce an ordered set of keys.
 
const map_t & getMap () const
 
void exportMap (std::map< std::string, T2 > &m) const
 Copies the contents to another map.
 
void importEntries (const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
 Assigns a value to given key; if the entry does not exist, tries to create it with directly with operator[]. More...
 
void importEntries (const std::list< std::string > &entries, char assignmentSymbol='=')
 
void importMap (const std::map< std::string, S > &m)
 Assign values from a map, overriding existing entries. More...
 
void importCastableMap (const drain::SmartMap< T2 > &m)
 Assign values from a map, possibly extending the map. More...
 
void updateFromMap (const std::map< std::string, T2 > &m)
 Assign values from a map. Updates existing entries only. More...
 
void updateFromCastableMap (const drain::SmartMap< T2 > &m)
 Convenience.
 
void setValues (const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
 Sets values. If strictness==STRICTLY_CLOSED, throws exception if tries to assign a non-existing entry.
 
void setValues (const char *entries, char assignmentSymbol='=', char separatorSymbol=0)
 
void setValuesSEQ (const S &sequence)
 
void updateValues (const std::string &entries, char assignmentSymbol='=', char separatorSymbol=0)
 Sets applicable values ie. modifies existing entries only. In ordered maps, skips extra entries silently.
 
void getKeys (std::ostream &ostr) const
 
std::string getKeys () const
 Convenience function for std::string output.
 
void getValues (std::ostream &ostr) const
 Dumps the values.
 
std::string getValues () const
 Convenience function for std::string output.
 
std::ostream & toStream (std::ostream &ostr, char equal='=', char startChar='{', char endChar='}', char separatorChar=',') const
 Note: parameters discarded.
 
std::string toStr (char equal='=', char start=0, char end=0, char separator=0) const
 
void dump (std::ostream &ostr=std::cout) const
 Write map as a JSON code. More...
 
- Protected Attributes inherited from SmartMap< FlexibleVariable >
std::list< std::string > keyList
 Assigns values from std::string of type "value,value2,...valueN". More...
 
char separator
 Default character used for splitting input and output. See setValues.
 
char arraySeparator
 Default separator character for array elements (std::vector's)
 

Member Function Documentation

◆ clear()

void clear ( )
virtual

Clear style, class and string data but keep the element type.

Clears style, classList, cdata.

Reimplemented from SmartMap< FlexibleVariable >.

◆ findByClass() [1/2]

bool findByClass ( const T2 &  t,
const C &  cls,
std::list< path_elem_t > &  result 
)
static

Finds child elements in an XML structure by class name.

Template Parameters
V- XML tree

In a way, this is a forward definition – this could also be in TreeXMLutilities.

◆ findByClass() [2/2]

static bool findByClass ( const V &  t,
const C &  cls,
path_list_t &  result,
const path_t path = path_t() 
)
inlinestatic

Finds elements recursively in an XML structure by class name supplied as an enumeration type.

Template Parameters
V- XML tree
C- enum type, for which a unique (static) EnumDict has been detected.
Parameters
path- starting point

◆ findById() [1/2]

static bool findById ( const V &  tree,
const std::string &  tag,
path_list_t &  result,
const path_t path = path_t() 
)
static

Find the occurrence(s) of given ID using recursive breath-first search.

By definition, id attributes should be unique. This function nevertheless returns a list if user wants to handle more than one elements found.

Parameters
tree- source element,
id- id attribute to be searched for
result- path of pointing to
path- start path for the search.
Returns
- true, if an element was found.

◆ findById() [2/2]

static bool findById ( const V &  tree,
const std::string &  tag,
typename V::path_t &  result,
const typename V::path_t &  path = path_t() 
)
static

Find the first occurrence of given id using recursive breath-first search.

By definition, id attributes should be unique.

Parameters
tree- source element,
id- id attribute to be searched for
result- path of the element with required ID, if found.
path- start path for the search.
Returns
- true, if an element was found.

◆ findByTag() [1/2]

bool findByTag ( const T &  t,
const N &  tag,
NodeXML<>::path_list_t &  result,
const path_t path 
)
Template Parameters
Tree

◆ findByTag() [2/2]

static bool findByTag ( const V &  tree,
const T &  tag,
path_list_t &  result,
const path_t path = path_t() 
)
static

Find all the occurrences of given tag type using recursive breath-first search. This is a "forward definition" – this could also be in TreeXMLutilities.

◆ findByTags() [1/2]

bool findByTags ( const T &  t,
const std::set< N > &  tags,
NodeXML<>::path_list_t &  result,
const path_t path 
)
Template Parameters
Tree

◆ findByTags() [2/2]

static bool findByTags ( const V &  tree,
const std::set< T > &  tags,
path_list_t &  result,
const path_t path = path_t() 
)
static

"Forward definition"

Template Parameters
V- XML tree

◆ hasClass() [1/2]

bool hasClass ( const V &  cls) const
inline
Template Parameters
V– string or enum type

◆ hasClass() [2/2]

bool hasClass ( const V &  cls) const
inline
Template Parameters
V– string or enum type

◆ reset()

void reset ( )
inline

Clear style, class and string data as well as the element type.

Clears style, classList, cdata.

◆ setComment()

void setComment ( const T &...  args)
inline

Make this node a comment. Contained tree will not be deleted. In current version, attributes WILL be rendered.

Parameters
text- if given, replaces current CTEXT.

◆ setId() [1/2]

void setId ( )
inline

Makes ID a visible attribute.

Also a terminal function for

◆ setId() [2/2]

void setId ( )
inline

Makes ID a visible attribute.

Also a terminal function for

◆ setStyle()

void setStyle ( const std::string &  key,
const std::initializer_list< V > &  l 
)
inline

Set style of an element.

rect.setStyle("dash-array",{2,5,3});

◆ setText()

void setText ( const std::string &  s)

Assign the text content of this node. If the node type is undefined, set it to CTEXT.

Parameters
text- assigned to text content.

TODO: strict/exclusive, i.e. non-element behavior

◆ xmlAddChild()

static T& xmlAddChild ( T &  tree,
const std::string &  key 
)
inlinestatic

TODO: add default type based on parent group? defaultChildMap TR->TD

◆ xmlAssign() [1/4]

static TX& xmlAssign ( TX &  dst,
const TX &  src 
)
inlinestatic

Assign another tree structure to another.

Template Parameters
XML- xml tree structure (TreeXML, TreeSVG, TreeHTML)

◆ xmlAssign() [2/4]

static TX& xmlAssign ( TX &  dst,
const typename TX::xml_node_t &  src 
)
inlinestatic

Assign another tree structure to another.

Template Parameters
XML- xml tree structure (TreeXML, TreeSVG, TreeHTML)

◆ xmlAssign() [3/4]

static TX& xmlAssign ( TX &  tree,
const V &  arg 
)
inlinestatic

Assign another tree structure to another.

Template Parameters
T- XML tree

◆ xmlAssign() [4/4]

static TX& xmlAssign ( TX &  tree,
std::initializer_list< std::pair< const char *, const Variable > >  l 
)
inlinestatic

Tree.

Template Parameters
TX- xml tree

◆ xmlAssignNode()

static X& xmlAssignNode ( X &  dst,
const X &  src 
)
inlinestatic

Assign another tree structure to another.

Template Parameters
XML- xml tree structure (TreeXML, TreeSVG, TreeHTML)
See also
clear()

◆ xmlSetType()

static TX& xmlSetType ( TX &  tree,
const typename TX::node_data_t::xml_tag_t &  type 
)
inlinestatic

Forward definition – type can be set only upon construction of a complete

Member Data Documentation

◆ id

std::string id

Some general-purpose.

Some general-purpose variables.


The documentation for this class was generated from the following files: