136 const std::string &
name()
const;
180 Tag *
find_child(
int id,
int attId,
const std::string &value,
Tag *after = NULL)
const;
181 Tag *
find_child(
const std::string &
name,
const std::string &attName,
const std::string &value,
Tag *after = NULL)
const;
210 void attribute(
int att_id,
const std::string &value);
214 void attribute(
const std::string &
name,
const std::string &value);
251 const std::string &
tag_name(
int id)
const;
258 void write_tag(std::ostream &os,
Tag *tag,
int indent = 0);
264 char read_string(std::istream &is, std::string &text);
265 char read_name(std::istream &is, std::string &name);
288 enum Cause {None, EmptyFile, ErrorReading, EndTagNotMatch,
289 InvalidTagStartChar, InvalidTagEndChar,
290 InvalidNameEnd, MissingTagName,
291 InvalidStringStart, InvalidStringEnd, InvalidEntityEnd, InvalidEntity
305 const std::string &
item()
const {
return _item;}
317 std::istream &operator>>(std::istream &is,
tbx::TagDoc &doc);
318 std::ostream &operator<<(std::ostream &os,
tbx::TagDoc &doc);
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...
Definition: tag.cc:774
TagData * _data
user data or 0 if none
Definition: tag.h:232
Exception thrown when reading a saved tag fails.
Definition: tag.h:282
~Tag()
Destructor for tag deletes assosiated tag data.
Definition: tag.cc:109
Tag * find_child(int id, Tag *after=NULL) const
Find the a child tag with the given id.
Definition: tag.cc:195
void attribute(int att_id)
Sets attribute with given id on the tag with no value.
Definition: tag.cc:320
Tag * parent() const
Get the parent for this tag.
Definition: tag.h:144
Cause cause() const
Return enumeration value specifying the cause of the exception.
Definition: tag.h:300
char read_name(std::istream &is, std::string &name)
Read a name from and input stream.
Definition: tag.cc:855
Document that stores Tags with optional attributes in a hierarchy.
Definition: tag.h:244
void data(TagData *data)
Set the data for this tag.
Definition: tag.h:207
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...
Definition: tag.cc:484
char read_string(std::istream &is, std::string &text)
Read a string from an input stream converting entities used back to characters.
Definition: tag.cc:807
const std::string & attribute_name(int id) const
Get the name of the attribute given its id.
Definition: tag.cc:581
void text(const std::string &text)
Set the text for this tag.
Definition: tag.h:194
bool _has_value
true if attribute has a value
Definition: tag.h:96
std::string _text
text for this type of tag or "" if not set
Definition: tag.h:231
TagAttribute * next()
Get the next attribute for the same tag.
Definition: tag.h:91
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...
Definition: tag.cc:538
Base class used for adding data to a tag.
Definition: tag.h:106
const std::string & tag_name(int id) const
Get the name of the tag given its id.
Definition: tag.cc:527
TagAttribute(int id)
Construct an attribute without a value.
Definition: tag.cc:62
TagData * data() const
Get the user data for this tag.
Definition: tag.h:201
TagAttribute * first_attribute() const
Get the first attribute of this tag.
Definition: tag.h:170
TagAttribute * _next
Next attribute for the same tag.
Definition: tag.h:97
const std::string & name() const
Return the name of this type of tag.
Definition: tag.cc:118
Tag * _parent
parent tag or 0 for no parent
Definition: tag.h:224
int _id
ID for this type of tag.
Definition: tag.h:230
const std::string & value()
Get the current string value for the attribute.
Definition: tag.h:59
TagAttribute * find_attribute(int att_id) const
Find the attribute with the given id.
Definition: tag.cc:421
Cause
Enumeration describing the reason for a tag exception.
Definition: tag.h:288
void delete_attribute(int attId)
Delete the attribute with the given id.
Definition: tag.cc:357
Tag * _first_child
first child tag or 0 for no children
Definition: tag.h:225
TagAttribute * _first_attribute
first attribute or 0 if no attributes
Definition: tag.h:228
int id() const
Return the tag id.
Definition: tag.h:135
TagException(Cause cause, const std::string &item)
Constructor for error with an item name.
Definition: tag.cc:878
void write_tag(std::ostream &os, Tag *tag, int indent=0)
Write a tag and all its children to an output stream.
Definition: tag.cc:721
int integer() const
Return the current value as an integer.
Definition: tag.h:65
Class to represent a some data tagged with an id.
Definition: tag.h:123
bool has_value() const
Check if the attribute has a value.
Definition: tag.h:84
TagDoc * doc() const
Return the document this tag belongs to.
Definition: tag.cc:126
Tag * _last_child
last child tag or 0 for no children
Definition: tag.h:226
void read_tag(std::istream &is)
Reads a tag and all its children from a stream.
Definition: tag.cc:611
int _id
Id of attribute.
Definition: tag.h:94
Tag(Tag *parent, int id)
Construct a tag with the given parent and id.
Definition: tag.cc:94
void delete_child(Tag *tag)
Deletes at child tag.
Definition: tag.cc:171
TagDoc()
Constructor for a new empty tag document.
Definition: tag.cc:467
std::vector< std::string > _attribute_names
List of all attribute names known to this document.
Definition: tag.h:275
std::vector< std::string > _tag_names
List of all tag names known to this document.
Definition: tag.h:271
int attribute_id_if_exists(const std::string &name) const
Gets a attribute id if it has already been defined.
Definition: tag.cc:563
Tag * next() const
Get the next sibling tag.
Definition: tag.h:163
int tag_id_if_exists(const std::string &name) const
Gets a tag id if it has already been defined.
Definition: tag.cc:509
void has_value(bool has)
Set if the attribute has a value associated with it.
Definition: tag.h:78
int id() const
Attribute Id.
Definition: tag.h:54
const std::string & text() const
Get the text from the tag.
Definition: tag.h:188
Tag * add_child(int id)
Add a new tag as a child of this tag.
Definition: tag.cc:139
Tag * last_child() const
Get the last child tag.
Definition: tag.h:157
~TagDoc()
Destructor.
Definition: tag.cc:474
void value(const std::string &value)
Set the value of the attribute.
Definition: tag.h:71
Class to represent a single attribute.
Definition: tag.h:43
Tag * _next
next sibling tag or 0 if no more siblings
Definition: tag.h:227
Tag * first_child() const
Get the first child tag.
Definition: tag.h:151
std::string _value
Value of attribute (if any)
Definition: tag.h:95
std::string attribute_value(int att_id) const
Get the value of an attribute.
Definition: tag.cc:446
const std::string & item() const
Return the item or character the exception happened on.
Definition: tag.h:305