ContRap-Core
Data Structures | Public Member Functions | Protected Member Functions | Protected Attributes

crp::XMLDataPool Class Reference

Class XMLDataPool is a query class object for XML-trees. More...

#include <xmldatapool.h>

Inheritance diagram for crp::XMLDataPool:
crp::XMLParser crp::ModuleInfo crp::Options

Data Structures

class  PoolEntry
 Class PoolEntry is an internal structure for nodes in the XML data pool. More...

Public Member Functions

 XMLDataPool (const std::string &text="")
 Creates a new parser.
virtual ~XMLDataPool ()
 Cleans up the memory.
void clear ()
 Clears the contents of the pool.
bool set_value (const std::string &key, const std::string &value)
 Sets a value at the given key.
bool set_bool (const std::string &key, bool value)
 Sets a boolean value at the given key.
bool set_double (const std::string &key, double value)
 Sets a double value at the given key.
bool add_value (const std::string &key, const std::string &tag, const std::string &value)
 Adds a value at the given key.
void set_attribute (const std::string &key, const std::string &attribute, const std::string &value)
 Sets an attribute at the given key.
int get_children (const std::string &key, const std::string &tag)
 Returns the number of children of a given key.
const std::string & get_value (const std::string &key)
 Returns a value.
const std::string & get_string (const std::string &key)
 Returns a string value.
int get_int (const std::string &key)
 Returns an integer value.
double get_double (const std::string &key)
 Returns an double value.
bool get_bool (const std::string &key)
 Returns an boolen value.
const std::string & get_attribute (const std::string &key, const std::string &attribute)
 Returns a value of an attribute.
const std::string & get_string (const std::string &key, const std::string &attribute)
 Returns a string of an attribute.
int get_int (const std::string &key, const std::string &attribute)
 Returns an integer value.
double get_double (const std::string &key, const std::string &attribute)
 Returns an double value.
bool get_bool (const std::string &key, const std::string &attribute)
 Returns an boolen value.
std::vector< std::string > get_values (const std::string &key, const std::string &tag)
 Returns the list of the values of the given key with the given end tag.
std::vector< std::string > get_values (const std::string &key)
 Returns the list of all the values of the given key.
std::map< std::string,
std::string > * 
get_attrubutes (const std::string &key)
 Returns the map of all attributes.
void remove (const std::string &key)
 Removes the data at the position given by the key and all its children.
void clear (const std::string &key)
 Clears the contents inside the given key without removing the key's root.
bool is_set (const std::string &key)
 Returns true if the key has an entry.
int find (const std::string &key, const std::string &tag, const std::string &subtag, const std::string &value)
 Finds the order number of an entry with the given tag set to a specified value.
int find_attribute (const std::string &key, const std::string &tag, const std::string &attribute, const std::string &value)
 Finds the order number of an entry with the given attribute set to a specified value.
void copy (XMLDataPool &source, const std::string &source_key, const std::string &destination_key)
 Copies contents from one XML pool to the current.
void swap (const std::string &first_key, const std::string &second_key)
 Swaps two entries within the current pool.
bool load (const std::string &file_name="")
 Loads the contents of the pool from a file.
bool save (const std::string &file_name="")
 Saves the contents of the pool to a file.

Protected Member Functions

virtual bool start ()
 XML parser event functions.
virtual bool enter (const std::string &tag, std::map< std::string, std::string > &attributes, bool end)
 Event functions are called on entering, parsing and leaving tags.
virtual bool content (const std::string &tag, std::map< std::string, std::string > &attributes, const std::string &value, int count)
virtual bool leave (const std::string &tag, std::map< std::string, std::string > &attributes)
PoolEntryget_entry (const std::string &key, bool add=false)
 Returns the entry for a key.
void save_rec (std::ofstream &stream, PoolEntry *entry, int depth)
 Recursive save procedure.

Protected Attributes

PoolEntry root
 Pool data structure.
std::stack< PoolEntry * > stack
 Currently parsed key.
std::string file_name
 File name.
std::string empty_string
 Empty string.

Detailed Description

Class XMLDataPool is a query class object for XML-trees.


Constructor & Destructor Documentation

crp::XMLDataPool::XMLDataPool ( const std::string &  text = "")

Creates a new parser.

Parameters:
textXML-formatted string
virtual crp::XMLDataPool::~XMLDataPool ( ) [virtual]

Cleans up the memory.


Member Function Documentation

bool crp::XMLDataPool::add_value ( const std::string &  key,
const std::string &  tag,
const std::string &  value 
)

Adds a value at the given key.

Parameters:
keyKey of the entry with tags separated by ':'
tagTag of the value
valuevalue Value to set
Returns:
True if the value was added
void crp::XMLDataPool::clear ( )

Clears the contents of the pool.

void crp::XMLDataPool::clear ( const std::string &  key)

Clears the contents inside the given key without removing the key's root.

Parameters:
keyKey of the entry with tags separated by ':'
virtual bool crp::XMLDataPool::content ( const std::string &  tag,
std::map< std::string, std::string > &  attributes,
const std::string &  value,
int  count 
) [protected, virtual]

Reimplemented from crp::XMLParser.

void crp::XMLDataPool::copy ( XMLDataPool source,
const std::string &  source_key,
const std::string &  destination_key 
)

Copies contents from one XML pool to the current.

Parameters:
sourceSource pool
source_keyKey within the source pool
destination_keyKey within the destination pool
virtual bool crp::XMLDataPool::enter ( const std::string &  tag,
std::map< std::string, std::string > &  attributes,
bool  end 
) [protected, virtual]

Event functions are called on entering, parsing and leaving tags.

A false returned by an event function results in an error break.

Reimplemented from crp::XMLParser.

int crp::XMLDataPool::find ( const std::string &  key,
const std::string &  tag,
const std::string &  subtag,
const std::string &  value 
)

Finds the order number of an entry with the given tag set to a specified value.

Parameters:
keyKey to the root entry
tagBase tag of the child entry
subtagTag of a child check for equality
valueValue of the tag
Returns:
Number of the found tag or zero if no such tag exists.
int crp::XMLDataPool::find_attribute ( const std::string &  key,
const std::string &  tag,
const std::string &  attribute,
const std::string &  value 
)

Finds the order number of an entry with the given attribute set to a specified value.

Parameters:
keyKey to the root entry
tagBase tag of the child entry
subtagTag of a child check for equality
valueValue of the tag
Returns:
Number of the found tag or zero if no such tag exists.
const std::string& crp::XMLDataPool::get_attribute ( const std::string &  key,
const std::string &  attribute 
)

Returns a value of an attribute.

Parameters:
keyKey of the entry with tags separated by ':'
attributeName of the attribute
Returns:
String value of the entry
std::map<std::string, std::string>* crp::XMLDataPool::get_attrubutes ( const std::string &  key)

Returns the map of all attributes.

Parameters:
keyKey to a list of values
Returns:
All values contained by the key
bool crp::XMLDataPool::get_bool ( const std::string &  key,
const std::string &  attribute 
)

Returns an boolen value.

Parameters:
keyKey of the entry with tags separated by ':'
attributeName of the attribute
Returns:
String value of the entry
bool crp::XMLDataPool::get_bool ( const std::string &  key)

Returns an boolen value.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
String value of the entry
int crp::XMLDataPool::get_children ( const std::string &  key,
const std::string &  tag 
)

Returns the number of children of a given key.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
Number of children addressible by adding ':n' to the key
double crp::XMLDataPool::get_double ( const std::string &  key,
const std::string &  attribute 
)

Returns an double value.

Parameters:
keyKey of the entry with tags separated by ':'
attributeName of the attribute
Returns:
String value of the entry
double crp::XMLDataPool::get_double ( const std::string &  key)

Returns an double value.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
String value of the entry
PoolEntry* crp::XMLDataPool::get_entry ( const std::string &  key,
bool  add = false 
) [protected]

Returns the entry for a key.

int crp::XMLDataPool::get_int ( const std::string &  key)

Returns an integer value.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
String value of the entry
int crp::XMLDataPool::get_int ( const std::string &  key,
const std::string &  attribute 
)

Returns an integer value.

Parameters:
keyKey of the entry with tags separated by ':'
attributeName of the attribute
Returns:
String value of the entry
const std::string& crp::XMLDataPool::get_string ( const std::string &  key) [inline]

Returns a string value.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
String value of the entry
const std::string& crp::XMLDataPool::get_string ( const std::string &  key,
const std::string &  attribute 
) [inline]

Returns a string of an attribute.

Parameters:
keyKey of the entry with tags separated by ':'
attributeName of the attribute
Returns:
String value of the entry
const std::string& crp::XMLDataPool::get_value ( const std::string &  key)

Returns a value.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
String value of the entry
std::vector<std::string> crp::XMLDataPool::get_values ( const std::string &  key,
const std::string &  tag 
)

Returns the list of the values of the given key with the given end tag.

Parameters:
keyKey to a list of values
tagEnd tag key:tag
Returns:
All values contained by the key
std::vector<std::string> crp::XMLDataPool::get_values ( const std::string &  key)

Returns the list of all the values of the given key.

Parameters:
keyKey to a list of values
Returns:
All values contained in the key
bool crp::XMLDataPool::is_set ( const std::string &  key)

Returns true if the key has an entry.

Parameters:
keyKey of the entry with tags separated by ':'
Returns:
True if the key is populated
virtual bool crp::XMLDataPool::leave ( const std::string &  tag,
std::map< std::string, std::string > &  attributes 
) [protected, virtual]

Reimplemented from crp::XMLParser.

bool crp::XMLDataPool::load ( const std::string &  file_name = "")

Loads the contents of the pool from a file.

An empty file name leads to a reload.

Parameters:
file_nameName of the file
Returns:
True if the operation was successful
void crp::XMLDataPool::remove ( const std::string &  key)

Removes the data at the position given by the key and all its children.

Parameters:
keyKey of the entry with tags separated by ':'
bool crp::XMLDataPool::save ( const std::string &  file_name = "")

Saves the contents of the pool to a file.

An empty file name leads to overwriting the last saved file.

Parameters:
file_nameName of the file
Returns:
True if the operation was successful
void crp::XMLDataPool::save_rec ( std::ofstream &  stream,
PoolEntry entry,
int  depth 
) [protected]

Recursive save procedure.

void crp::XMLDataPool::set_attribute ( const std::string &  key,
const std::string &  attribute,
const std::string &  value 
)

Sets an attribute at the given key.

Parameters:
keyKey of the entry with tags separated by ':'
attributeAttribute of the key value Value to set
bool crp::XMLDataPool::set_bool ( const std::string &  key,
bool  value 
) [inline]

Sets a boolean value at the given key.

Parameters:
keyKey of the entry with tags separated by ':'
valuevalue Value to set
Returns:
True if the value was added
bool crp::XMLDataPool::set_double ( const std::string &  key,
double  value 
) [inline]

Sets a double value at the given key.

Parameters:
keyKey of the entry with tags separated by ':'
valuevalue Value to set
Returns:
True if the value was added
bool crp::XMLDataPool::set_value ( const std::string &  key,
const std::string &  value 
)

Sets a value at the given key.

Parameters:
keyKey of the entry with tags separated by ':'
valuevalue Value to set
Returns:
True if the value was added
virtual bool crp::XMLDataPool::start ( ) [protected, virtual]

XML parser event functions.

Reimplemented from crp::XMLParser.

void crp::XMLDataPool::swap ( const std::string &  first_key,
const std::string &  second_key 
)

Swaps two entries within the current pool.

Parameters:
first_keyKey of the first entry
second_keyKey of the second entry

Field Documentation

std::string crp::XMLDataPool::empty_string [protected]

Empty string.

std::string crp::XMLDataPool::file_name [protected]

File name.

Pool data structure.

std::stack<PoolEntry*> crp::XMLDataPool::stack [protected]

Currently parsed key.


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