tbx  0.7.3
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tbx::TagDoc Class Reference

Document that stores Tags with optional attributes in a hierarchy. More...

#include <tag.h>

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

Public Member Functions

 TagDoc ()
 Constructor for a new empty tag document.
 
 ~TagDoc ()
 Destructor.
 
int tag_id (const std::string &name)
 Returns the tag id for a name or allocates a new one if the name has not already been used. More...
 
const std::string & tag_name (int id) const
 Get the name of the tag given its id. More...
 
int tag_id_if_exists (const std::string &name) const
 Gets a tag id if it has already been defined. More...
 
int attribute_id (const std::string &name)
 Returns the attribute id for a name or allocates a new one if the name has not already been used. More...
 
int attribute_id_if_exists (const std::string &name) const
 Gets a attribute id if it has already been defined. More...
 
const std::string & attribute_name (int id) const
 Get the name of the attribute given its id. More...
 
void write_tag (std::ostream &os, Tag *tag, int indent=0)
 Write a tag and all its children to an output stream. More...
 
void read_tag (std::istream &is)
 Reads a tag and all its children from a stream. More...
 
- Public Member Functions inherited from tbx::Tag
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

void write_string (std::ostream &os, const std::string &text)
 Write a string to the output stream converting characters used in the syntax to special entities. More...
 
char read_string (std::istream &is, std::string &text)
 Read a string from an input stream converting entities used back to characters. More...
 
char read_name (std::istream &is, std::string &name)
 Read a name from and input stream. More...
 
- Protected Member Functions inherited from tbx::Tag
 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

std::vector< std::string > _tag_names
 List of all tag names known to this document.
 
std::vector< std::string > _attribute_names
 List of all attribute names known to this document.
 
- Protected Attributes inherited from tbx::Tag
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

Document that stores Tags with optional attributes in a hierarchy.

The document is the root of the tree and allocates the ids used for the tag and attribute names.

It also allows loading and saving of the tags using a simple XML like text file format.

Member Function Documentation

int TagDoc::attribute_id ( const std::string &  name)

Returns the attribute id for a name or allocates a new one if the name has not already been used.

Parameters
namename for the attribute
int TagDoc::attribute_id_if_exists ( const std::string &  name) const

Gets a attribute id if it has already been defined.

Parameters
nameattribute name to get id for
Returns
id for name or -1 if attribute is not in this document.
const std::string & TagDoc::attribute_name ( int  id) const

Get the name of the attribute given its id.

Parameters
idattribute id to get name for
char TagDoc::read_name ( std::istream &  is,
std::string &  name 
)
protected

Read a name from and input stream.

Parameters
isinput string to read from
namename to read
Returns
char that finished string read
Exceptions
TagExceptionif an invalid entity is found in the string
char TagDoc::read_string ( std::istream &  is,
std::string &  text 
)
protected

Read a string from an input stream converting entities used back to characters.

Parameters
isinput string to read from
texttext to read
Returns
char that finished string read
Exceptions
TagExceptionif an invalid entity is found in the string
void TagDoc::read_tag ( std::istream &  is)

Reads a tag and all its children from a stream.

Parameters
isinput stream to read data from
Exceptions
TagExceptionif read fails or there is a syntax error
int TagDoc::tag_id ( const std::string &  name)

Returns the tag id for a name or allocates a new one if the name has not already been used.

Parameters
namename for the tag
int TagDoc::tag_id_if_exists ( const std::string &  name) const

Gets a tag id if it has already been defined.

Parameters
nametag name to get id for
Returns
id for name or -1 if tag is not in this document.
const std::string & TagDoc::tag_name ( int  id) const

Get the name of the tag given its id.

Parameters
idtag id to get name for
void TagDoc::write_string ( std::ostream &  os,
const std::string &  text 
)
protected

Write a string to the output stream converting characters used in the syntax to special entities.

Parameters
osstream to write to
texttext to write.
void TagDoc::write_tag ( std::ostream &  os,
Tag tag,
int  indent = 0 
)

Write a tag and all its children to an output stream.

Parameters
osstream to write to
tagto write
indentnumber of spaces to indent the tag (default to 0)

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