All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Radiant::ChunkT< T > Class Template Reference

A template chunk class. More...

#include <Radiant/ConfigReader.hpp>

Public Types

typedef std::multimap< QString,
T >::const_iterator 
const_iterator
 Constant iterator for traversing all elements.
 
typedef std::multimap< QString,
T >::iterator 
iterator
 Iterator for traversing all elements.
 

Public Member Functions

void addChunk (const QString &id, const ChunkT< T > &v)
 Adds a new child node to this chunk. More...
 
iterator begin ()
 Iterator to the first element. More...
 
const_iterator begin () const
 Iterator to the first element. More...
 
const std::multimap< QString,
ChunkT< T > > * 
chunks () const
 Get the map of chunks. More...
 
 ChunkT ()
 Creates an empty configuration chunk.
 
 ChunkT (const ChunkT &copy)
 Copy constructor. More...
 
void clear ()
 Empties this chunk.
 
bool contains (const QString &id) const
 Check if this chunk contains an element with given id. More...
 
bool containsVariant (const QString &variantName) const
 Check if at least one variant with given name exists. More...
 
void dump (std::ostream &os, int indent=0) const
 Dump chunk into stream May be specialized at each level. More...
 
iterator end ()
 Iterator to the after-the-end element. More...
 
const_iterator end () const
 Iterator to the after-the-end element. More...
 
get (const QString &id) const
 Gets an element from the chunk. More...
 
get (const QString &id, const QString &alternateId) const
 Gets an element from the chunk. More...
 
const ChunkT< T > & getChunk (const QString &id) const
 Gets a child chunk. More...
 
bool isEmpty () const
 Check if the chunk is empty. More...
 
int numberOf (const QString &id) const
 Returns the number of elements with given id/tag. More...
 
ChunkToperator= (const ChunkT &copy)
 Copy a chunk with assignment. More...
 
void override (const QString &id, const T &v)
 Adds an element to the chunk, erasing any elements with identical id After calling this method, the chunk will contain only one element this this id. More...
 
void set (const QString &id, const T &v)
 Adds an element to the chunk. More...
 
void setClearFlag (bool clearF)
 Sets the flag to inform whether an old value should be removed before defining a new. More...
 
size_t size () const
 Number of elements. More...
 
 ~ChunkT ()
 Destructor.
 

Static Public Member Functions

static const QString & getName (iterator &it)
 Gets the name (id) from an iterator. More...
 
static const QString & getName (const_iterator &it)
 Gets the name (id) from a constant iterator. More...
 
static T & getType (iterator &it)
 Gets the data element from an iterator. More...
 
static const T & getType (const_iterator &it)
 Gets the data element from an constant iterator. More...
 

Detailed Description

template<class T>
class Radiant::ChunkT< T >

A template chunk class.

A chunk contains elements that are named with (text string) identifiers. A chunk may contain multiple elements with the same identifier. These classes can be nested easily. Usually the two default levels are enough. A practical example:

// Read in two configuration files:
bool ok = Radiant::readConfig(&config, "first-config");
ok = ok && Radiant::readConfig(&config, "second-config");
// Now retrieve values from the configuration:
Radiant::Chunk chunk = config.get("Scene");
// Now read two variants from the config
// We can provide default values for variables in case the variable
// has not been defined in the configuration.
QString fileName = chunk.get("filename").getString("default-file");
float scale = chunk.get("scale").getFloat(1.0);
Author
Tommi Ilmonen (may contain some original code by Janne Kontkanen)
Deprecated:
This class will be removed. Use Valuable::ConfigDocument
Template Parameters
TType of things contained in Chunk

Constructor & Destructor Documentation

template<class T >
Radiant::ChunkT< T >::ChunkT ( const ChunkT< T > &  copy)
inline

Copy constructor.

Parameters
copyChunk to copy

Member Function Documentation

template<class T >
void Radiant::ChunkT< T >::addChunk ( const QString &  id,
const ChunkT< T > &  v 
)

Adds a new child node to this chunk.

Parameters
idId of the added chunk
vChunk to add
template<class T >
iterator Radiant::ChunkT< T >::begin ( )
inline

Iterator to the first element.

Returns
STL-like iterator to the beginning of this chunk
template<class T >
const_iterator Radiant::ChunkT< T >::begin ( ) const
inline

Iterator to the first element.

Returns
STL-like iterator to the beginning of this chunk
template<class T >
const std::multimap<QString, ChunkT<T> >* Radiant::ChunkT< T >::chunks ( ) const
inline

Get the map of chunks.

Returns
Chunks stored in this chunk
template<class T >
bool Radiant::ChunkT< T >::contains ( const QString &  id) const

Check if this chunk contains an element with given id.

Parameters
idId to check
Returns
True if the chunk contains an element with given id
template<class T >
bool Radiant::ChunkT< T >::containsVariant ( const QString &  variantName) const
inline

Check if at least one variant with given name exists.

Parameters
variantNameName to search
Returns
True if contains variant with the given name
template<class T >
void Radiant::ChunkT< T >::dump ( std::ostream &  os,
int  indent = 0 
) const

Dump chunk into stream May be specialized at each level.

Parameters
osoutput stream
indenttext indent for formatting
template<class T >
iterator Radiant::ChunkT< T >::end ( )
inline

Iterator to the after-the-end element.

Returns
STL-like iterator to the end of this chunk
template<class T >
const_iterator Radiant::ChunkT< T >::end ( ) const
inline

Iterator to the after-the-end element.

Returns
STL-like iterator to the end of this chunk
template<class T >
T Radiant::ChunkT< T >::get ( const QString &  id) const

Gets an element from the chunk.

Parameters
idelement id
Returns
The first element of type T. If there is no element with the given id, then an element will be created with the default constructor.
template<class T >
T Radiant::ChunkT< T >::get ( const QString &  id,
const QString &  alternateId 
) const

Gets an element from the chunk.

Parameters
idthe primary id to search for
alternateIdif the primary id does not match, alternate is used
Returns
matching element
template<class T >
const ChunkT< T > & Radiant::ChunkT< T >::getChunk ( const QString &  id) const

Gets a child chunk.

If child with given id does not exist this returns proxy chunk.

Parameters
idId of the queried chunk
Returns
Reference to chunk queried, or proxy chunk.
template<class T >
static const QString& Radiant::ChunkT< T >::getName ( iterator it)
inlinestatic

Gets the name (id) from an iterator.

Parameters
itIterator to inspect
Returns
Name of the Chunk pointed by iterator
template<class T >
static const QString& Radiant::ChunkT< T >::getName ( const_iterator it)
inlinestatic

Gets the name (id) from a constant iterator.

Parameters
itIterator to inspect
Returns
Name of the Chunk pointed by iterator
template<class T >
static T& Radiant::ChunkT< T >::getType ( iterator it)
inlinestatic

Gets the data element from an iterator.

Parameters
itIterator to inspect
Returns
Contents of Chunk pointed by iterator
template<class T >
static const T& Radiant::ChunkT< T >::getType ( const_iterator it)
inlinestatic

Gets the data element from an constant iterator.

Parameters
itIterator to inspect
Returns
Contents of Chunk pointed by iterator
template<class T >
bool Radiant::ChunkT< T >::isEmpty ( ) const
inline

Check if the chunk is empty.

Returns
True if empty
template<class T >
int Radiant::ChunkT< T >::numberOf ( const QString &  id) const

Returns the number of elements with given id/tag.

Parameters
idId to query
Returns
Number of elements with the given id
template<class T >
ChunkT& Radiant::ChunkT< T >::operator= ( const ChunkT< T > &  copy)
inline

Copy a chunk with assignment.

Parameters
copyChunk to assign to this
Returns
Reference to this
template<class T >
void Radiant::ChunkT< T >::override ( const QString &  id,
const T &  v 
)

Adds an element to the chunk, erasing any elements with identical id After calling this method, the chunk will contain only one element this this id.

Parameters
idid to override
vchunk to override with
template<class T >
void Radiant::ChunkT< T >::set ( const QString &  id,
const T &  v 
)

Adds an element to the chunk.

If there are other elements with the same id before, then

this element is added among those.

Parameters
idelement id
vchunk to add
template<class T >
void Radiant::ChunkT< T >::setClearFlag ( bool  clearF)

Sets the flag to inform whether an old value should be removed before defining a new.

Parameters
clearFAre the old values removed when defining new value with same id
template<class T >
size_t Radiant::ChunkT< T >::size ( ) const
inline

Number of elements.

Returns
Number of elements