tbx  0.7.5
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tbx::Tag Class Reference

Class to represent a some data tagged with an id. More...

#include <tag.h>

Inheritance diagram for tbx::Tag:
tbx::TagDoc

Public Member Functions

int id () const
 Return the tag id. More...
 
const std::string & name () const
 Return the name of this type of tag.
 
TagDocdoc () const
 Return the document this tag belongs to.
 
Tagparent () const
 Get the parent for this tag. More...
 
Tagfirst_child () const
 Get the first child tag. More...
 
Taglast_child () const
 Get the last child tag. More...
 
Tagnext () const
 Get the next sibling tag. More...
 
TagAttributefirst_attribute () const
 Get the first attribute of this tag. More...
 
Tagadd_child (int id)
 Add a new tag as a child of this tag. More...
 
Tagadd_child (const std::string &name)
 Add a new tag with the given name as a child of this tag. More...
 
void delete_child (Tag *tag)
 Deletes at child tag. More...
 
Tagfind_child (int id, Tag *after=NULL) const
 Find the a child tag with the given id. More...
 
Tagfind_child (const std::string &name, Tag *after=NULL) const
 Find the a child tag with the given name. More...
 
Tagfind_child (int id, int attId, Tag *after=NULL) const
 Find a child tag with the given attribute. More...
 
Tagfind_child (const std::string &name, const std::string &attName, Tag *after=NULL) const
 Find a child tag with the given attribute. More...
 
Tagfind_child (int id, int attId, const std::string &value, Tag *after=NULL) const
 Find a child tag with the given attribute value. More...
 
Tagfind_child (const std::string &name, const std::string &attName, const std::string &value, Tag *after=NULL) const
 Find a child tag with the given attribute value. More...
 
const std::string & text () const
 Get the text from the tag. More...
 
void text (const std::string &text)
 Set the text for this tag. More...
 
TagDatadata () const
 Get the user data for this tag. More...
 
void data (TagData *data)
 Set the data for this tag. More...
 
void attribute (int att_id)
 Sets attribute with given id on the tag with no value. More...
 
void attribute (int att_id, const std::string &value)
 Sets attribute with given id on the tag with the given value. More...
 
void delete_attribute (int attId)
 Delete the attribute with the given id. More...
 
void attribute (const std::string &name)
 Sets attribute with given name on the tag with no value. More...
 
void attribute (const std::string &name, const std::string &value)
 Sets attribute with given name on the tag with the given value. More...
 
void delete_attribute (const std::string &name)
 Delete the named attribute. More...
 
TagAttributefind_attribute (int att_id) const
 Find the attribute with the given id. More...
 
TagAttributefind_attribute (const std::string &name) const
 Find the attribute with the given id. More...
 
std::string attribute_value (int att_id) const
 Get the value of an attribute. More...
 
std::string attribute_value (const std::string &name) const
 Get the value of an attribute. More...
 

Protected Member Functions

 Tag (Tag *parent, int id)
 Construct a tag with the given parent and id. More...
 
 ~Tag ()
 Destructor for tag deletes assosiated tag data.
 

Protected Attributes

Tag_parent
 parent tag or 0 for no parent
 
Tag_first_child
 first child tag or 0 for no children
 
Tag_last_child
 last child tag or 0 for no children
 
Tag_next
 next sibling tag or 0 if no more siblings
 
TagAttribute_first_attribute
 first attribute or 0 if no attributes
 
int _id
 ID for this type of tag.
 
std::string _text
 text for this type of tag or "" if not set
 
TagData_data
 user data or 0 if none
 

Detailed Description

Class to represent a some data tagged with an id.

The tag can optionally have: text a pointer to some data derived from TagData one or more attributes.

Tags are created by adding them to their parent. Initially this will be a TagDoc.

Constructor & Destructor Documentation

◆ Tag()

Tag::Tag ( Tag parent,
int  id 
)
protected

Construct a tag with the given parent and id.

Parameters
parentparent of the tag
idID of name of this type of tag

Member Function Documentation

◆ add_child() [1/2]

Tag * Tag::add_child ( int  id)

Add a new tag as a child of this tag.

Parameters
id- tag id - must have been returned from TagDoc::tag_id
Returns
Tag pointer of new tag created

◆ add_child() [2/2]

Tag * Tag::add_child ( const std::string &  name)

Add a new tag with the given name as a child of this tag.

Parameters
name- name for the tag. If it the name does not exists in the document it is added to it.
Returns
Tag pointer of new tag created

◆ attribute() [1/4]

void Tag::attribute ( int  att_id)

Sets attribute with given id on the tag with no value.

i.e. TagAttribute::has_value() == false Creates the attribute if it doesn't already exists

Parameters
att_idattribute id, must have been allocated with TagDoc::attribute_id

◆ attribute() [2/4]

void Tag::attribute ( int  att_id,
const std::string &  value 
)

Sets attribute with given id on the tag with the given value.

Creates the attribute if it doesn't already exists

Parameters
att_idattribute id, must have been allocated with TagDoc::attribute_id
valuestring value for the attribute

◆ attribute() [3/4]

void Tag::attribute ( const std::string &  name)

Sets attribute with given name on the tag with no value.

i.e. TagAttribute::has_value() == false

Adds the attribute name to the list of attribute names if it doesn't already exists Creates the attribute if it doesn't already exists

Parameters
nameattribute name

◆ attribute() [4/4]

void Tag::attribute ( const std::string &  name,
const std::string &  value 
)

Sets attribute with given name on the tag with the given value.

Adds the attribute name to the list of attribute names if it doesn't already exists Creates the attribute if it doesn't already exists

Parameters
nameattribute name
valuestring value for attribute

◆ attribute_value() [1/2]

std::string Tag::attribute_value ( int  att_id) const

Get the value of an attribute.

Parameters
att_idid of the attribute
Returns
attribute value or empty string if attribute doesn't exist on this tag

◆ attribute_value() [2/2]

std::string Tag::attribute_value ( const std::string &  name) const

Get the value of an attribute.

Parameters
namename of the attribute
Returns
attribute value or empty string if attribute doesn't exist on this tag

◆ data() [1/2]

TagData* tbx::Tag::data ( ) const
inline

Get the user data for this tag.

Returns
data for this tag or 0 if there is none

◆ data() [2/2]

void tbx::Tag::data ( TagData data)
inline

Set the data for this tag.

Parameters
datanew data for the tag

◆ delete_attribute() [1/2]

void Tag::delete_attribute ( int  att_id)

Delete the attribute with the given id.

Parameters
att_idattribute id, must have been allocated with TagDoc::attribute_id

◆ delete_attribute() [2/2]

void Tag::delete_attribute ( const std::string &  name)

Delete the named attribute.

Parameters
nameattribute name

◆ delete_child()

void Tag::delete_child ( Tag tag)

Deletes at child tag.

Parameters
tagtag to delete.

◆ find_attribute() [1/2]

TagAttribute * Tag::find_attribute ( int  att_id) const

Find the attribute with the given id.

Parameters
att_idattribute id, must have been allocated with TagDoc::attribute_id
Returns
TagAttribute pointer or 0 if not found

◆ find_attribute() [2/2]

TagAttribute * Tag::find_attribute ( const std::string &  name) const

Find the attribute with the given id.

Parameters
nameattribute name
Returns
TagAttribute pointer or 0 if not found

◆ find_child() [1/6]

Tag * Tag::find_child ( int  id,
Tag after = NULL 
) const

Find the a child tag with the given id.

Parameters
idtag id to search for
aftertag to start search after or 0 to start from the beginning
Returns
pointer to tag if found or 0

◆ find_child() [2/6]

Tag * Tag::find_child ( const std::string &  name,
Tag after = NULL 
) const

Find the a child tag with the given name.

Parameters
nametag name to search for
aftertag to start search after or 0 to start from the beginning
Returns
pointer to tag if found or 0

◆ find_child() [3/6]

Tag * Tag::find_child ( int  id,
int  att_id,
Tag after = NULL 
) const

Find a child tag with the given attribute.

Parameters
idtag id to search for
att_idattribute id for attribute tag must have
aftertag to start search after or 0 to start from the beginning
Returns
pointer to tag if found or 0

◆ find_child() [4/6]

Tag * Tag::find_child ( const std::string &  name,
const std::string &  att_name,
Tag after = NULL 
) const

Find a child tag with the given attribute.

Parameters
nametag name to search for
att_nameattribute name for attribute tag must have
aftertag to start search after or 0 to start from the beginning
Returns
pointer to tag if found or 0

◆ find_child() [5/6]

Tag * Tag::find_child ( int  id,
int  att_id,
const std::string &  value,
Tag after = NULL 
) const

Find a child tag with the given attribute value.

Parameters
idtag id to search for
att_idattribute id for attribute tag must have
valuevalue to search for
aftertag to start search after or 0 to start from the beginning
Returns
pointer to tag if found or 0

◆ find_child() [6/6]

Tag * Tag::find_child ( const std::string &  name,
const std::string &  att_name,
const std::string &  value,
Tag after = NULL 
) const

Find a child tag with the given attribute value.

Parameters
nametag name to search for
att_nameattribute name for attribute tag must have
valuevalue to search for
aftertag to start search after or 0 to start from the beginning
Returns
pointer to tag if found or 0

◆ first_attribute()

TagAttribute* tbx::Tag::first_attribute ( ) const
inline

Get the first attribute of this tag.

Returns
first tag attribute or 0 if this tag has no attributes

◆ first_child()

Tag* tbx::Tag::first_child ( ) const
inline

Get the first child tag.

Returns
first child tag or 0 if this tag has no children

◆ id()

int tbx::Tag::id ( ) const
inline

Return the tag id.

Returns
the ID for this type of tag

◆ last_child()

Tag* tbx::Tag::last_child ( ) const
inline

Get the last child tag.

Returns
last child tag or 0 if this tag has no children

◆ next()

Tag* tbx::Tag::next ( ) const
inline

Get the next sibling tag.

Returns
the next sibling tag or 0 if there are no more

◆ parent()

Tag* tbx::Tag::parent ( ) const
inline

Get the parent for this tag.

Returns
parent or 0 if it is the root of the tag tree

◆ text() [1/2]

const std::string& tbx::Tag::text ( ) const
inline

Get the text from the tag.

Returns
text for this tag or "" if none

◆ text() [2/2]

void tbx::Tag::text ( const std::string &  text)
inline

Set the text for this tag.

Parameters
textnew text for the tag

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