Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
NodeXML< T > Class Template Reference

#include <TreeXML.h>

Inheritance diagram for NodeXML< T >:
Inheritance graph
[legend]
Collaboration diagram for NodeXML< T >:
Collaboration graph
[legend]

Public Types

typedef T elem_t
 Tag type, CTEXT or COMMENT.
 
typedef NodeXML< T > xml_node_t
 
typedef drain::Path< std::string,'/'> path_t
 Tree path type.
 
typedef UnorderedMultiTree< NodeXML< T >, false, path_txml_tree_t
 
typedef ReferenceMap2< FlexibleVariablemap_t
 
typedef std::map< T, std::string > tag_map_t
 
typedef std::list< path_tpath_list_t
 

Public Member Functions

 NodeXML (const elem_t &t=elem_t(0))
 
 NodeXML (const NodeXML &node)
 
bool empty () const
 
virtual void setType (const elem_t &t)
 
const elem_tgetType () const
 
bool typeIs (const elem_t &t) const
 
bool isComment () const
 
bool isCText () const
 
bool isUndefined () const
 
bool isSelfClosing () const
 
const std::string & getTag () const
 
const map_tgetAttributes () const
 
map_tgetAttributes ()
 
void set (const NodeXML &node)
 
void set (const elem_t &type)
 
void set (const std::string &s)
 
void set (const char *s)
 
void set (const drain::Castable &s)
 
void set (const std::initializer_list< Variable::init_pair_t > &l)
 
template<class X >
void set (const std::map< std::string, X > &args)
 
template<class V >
void set (const std::string &key, const V &value)
 
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.
 
bool hasClass (const std::string &cls) const
 
void removeClass (const std::string &s)
 
void clearClasses ()
 
NodeXMLoperator= (const T &x)
 
NodeXMLoperator= (const Castable &c)
 
NodeXMLoperator= (const std::string &s)
 
NodeXMLoperator= (const char *s)
 
NodeXMLoperator= (const std::initializer_list< std::pair< const char *, const drain::Variable > > &l)
 
NodeXMLsetComment (const std::string &text="")
 Make this node a comment. Contained tree will not be delete. In current version, attributes will be rendered. More...
 
template<class S >
NodeXMLsetText (const S &value)
 Assign the text content of this node. If the node type is undefined, set it to CTEXT. More...
 
NodeXMLsetText (const char *value)
 
template<class S >
void setStyle (const S &value)
 
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 V &value)
 
void setStyle (const std::initializer_list< std::pair< const char *, const drain::Variable > > &l)
 
void setId ()
 Makes ID a visible attribute.
 
void setId (const std::string &s)
 Makes ID a visible attribute, with a given value.
 
const std::string & getId () const
 Returns ID of this element. Hopefully a unique ID...
 
bool isSelfClosing () const
 
bool isSelfClosing () const
 
std::map< int, std::string > tags
 
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 >
bool findByTag (const T &t, const N &tag, NodeXML<>::path_list_t &result, const path_t &path)
 
template<class T >
bool findByTags (const T &t, const std::set< N > &tags, NodeXML<>::path_list_t &result, const path_t &path)
 
template<class T >
bool findByClass (const T &t, const std::string &cls, NodeXML<>::path_list_t &result, const path_t &path)
 
template<class T >
std::ostream & toStream (std::ostream &ostr, const T &tree, const std::string &defaultTag, int indent)
 XML output function shared for all XML documents, ie versions defined in subclasses. More...
 

Static Public Member Functions

static const std::string & getTag (unsigned int index)
 
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 all the occurrence of given ID using recursive breath-first search. More...
 
template<class V >
static bool findByTag (const V &tree, const T &tag, path_list_t &result, const path_t &path=path_t())
 "Forward definition"
 
template<class V >
static bool findByTags (const V &tree, const std::set< T > &tags, path_list_t &result, const path_t &path=path_t())
 "Forward definition"
 
template<class V >
static bool findByClass (const V &t, const std::string &tag, path_list_t &result, const path_t &path=path_t())
 "Forward definition"
 
template<class V >
static std::ostream & docToStream (std::ostream &ostr, const V &tree)
 
template<class V >
static std::ostream & toStream (std::ostream &ostr, const V &t, const std::string &defaultTag="", int indent=0)
 "Forward definition" of Tree::toOstream
 
static std::ostream & docTypeToStream (std::ostream &ostr)
 Write the XML definition beginning any XML document. More...
 
template<int E>
static const std::pair< key_t, NodeXML< T > > & entry ()
 
static int getCount ()
 

Public Attributes

elem_t type
 
std::string ctext
 Some general-purpose.
 
std::string url
 
StyleXML style
 
ClassListXML classList
 

Static Public Attributes

static const int UNDEFINED
 
static const int COMMENT
 
static const int CTEXT
 
static const int STYLE
 
static const int SCRIPT
 
static tag_map_t tags
 

Protected Types

typedef std::map< std::string, std::string > xmldoc_attrib_map_t
 
- 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

NodeXML< int >::xmldoc_attrib_map_t xmldoc_attribs
 
- 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 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)
 
virtual void clear ()
 
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...
 

Static Protected Member Functions

template<class V >
static void attribToStream (std::ostream &ostr, const std::string &key, const V &value)
 

Protected Attributes

std::string id
 
- 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)
 

Static Protected Attributes

static xmldoc_attrib_map_t xmldoc_attribs
 
static int nextID = 0
 

Detailed Description

template<class T = int>
class drain::NodeXML< T >

Template Parameters
T- index type; may be enum.

Member Function Documentation

◆ docTypeToStream()

static std::ostream& docTypeToStream ( std::ostream &  ostr)
inlinestatic

Write the XML definition beginning any XML document.

Each derived class should have a definition compatible with the structure generated by the class.

◆ 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 all the occurrence 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.

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()

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

◆ findByTags()

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

◆ isSelfClosing()

bool isSelfClosing ( ) const

Set of NOT self.closing tags.

Inclusive solution...

◆ setComment()

NodeXML& setComment ( const std::string &  text = "")
inline

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

Parameters
text- if given, replaces current CTEXT.

◆ setText()

NodeXML& setText ( const S &  value)
inline

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

Parameters
text- assigned to text content.

◆ toStream()

std::ostream& toStream ( std::ostream &  ostr,
const T &  tree,
const std::string &  defaultTag,
int  indent 
)

XML output function shared for all XML documents, ie versions defined in subclasses.

TODO: preamble/prologToStream()

Parameters
defaultTag- important for

iterate children - note the use of default tag


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