XFuConfigurationData class Reference

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members Related Pages

# XFuConfigurationData Class Reference

Configured data container. More...

`#include <XFuConfigurationData.h>`

Inheritance diagram for XFuConfigurationData:

[legend]
Collaboration diagram for XFuConfigurationData:

[legend]
List of all members.

## Public Member Functions

virtual | ~XFuConfigurationData ()
| Virtual destructor.
virtual CHAR * | get (const CHAR *aKey)
| Returns the value of a property as a string, or NULL if not found.
virtual XFcGLResourceSurface * | getImage (const CHAR *aKey)
| Returns a configuration data image by key, or NULL if not found.
virtual XFuPrinter * | getPrinter (const CHAR *aKey)
| Returns a configuration data printer by key, or NULL if not found.
virtual XFuConfigurationDataSoundInfo * | getSound (const CHAR *aKey)
| Returns a configuration data sound info by key, or NULL if not found.
virtual XFuConfigurationDataMusicInfo * | getMusic (const CHAR *aKey)
| Returns a configuration data music info by key, or NULL if not found.
virtual INT | getRectangle (XFcRectangle &aDest, const CHAR *aKey)
| Gets a property value by key, and then parses and returns the value as a rectangle.
virtual void | put (const CHAR *aKey, const CHAR *aValue)
| Sets the value of a property.
virtual INT | load (const CHAR *aFilename)
| Loads new configuration file and merges its data to the current set.
virtual INT | load (XFcFile *aFile)
| Loads new configuration file and merges its data to the current set.
void | setDeferredLoadingEnabled (INT aEnabled)
| Sets deferred loading mode status.

## Static Public Member Functions

XFuConfigurationData * | create ()
| Static constructor.
XFuConfigurationData * | create (const CHAR *aFilename)
| Static constructor.
XFuConfigurationData * | create (XFcFile *aFile)
| Static constructor.
XFcRectangle | parseRectangleString (const CHAR *aValue)
| Parses a rectangle value string.

## Protected Types

typedef XFcHashtable< XFuStringKey, XFcGLResourceSurface * > | ImageSet
| Internal image container type.
typedef XFcHashtable< XFuStringKey, XFuPrinter * > | PrinterSet
| Internal printer container type.
typedef XFcHashtable< XFuStringKey, XFuConfigurationDataSoundInfo * > | SoundSet
| Internal sound info container type.
typedef XFcHashtable< XFuStringKey, XFuConfigurationDataMusicInfo * > | MusicSet
| Internal music info container type.

## Protected Member Functions

| XFuConfigurationData ()
| Protected constructor.
INT | init ()
| Initializes a newly constructed object.
void | addImage (const CHAR *aValue)
| Adds and possibly loads a new image to the internal image container.
void | addPrinter (const CHAR *aValue)
| Adds and possibly loads a new printer to the internal printer container.
void | addSound (const CHAR *aValue)
| Adds a new sound to the internal sound container.
void | addMusic (const CHAR *aValue)
| Adds a new music to the internal music container.
void | loadImage (ImageSet::iterator &aIterator)
| Loads a new image to the internal image container.
void | loadPrinter (PrinterSet::iterator &aIterator)
| Loads a new printer to the internal printer container.
CHAR * | makePrefixedKey (const CHAR aPrefix, const CHAR *aKey)
| Allocates and returns a new key with a specified prefix char.

## Protected Attributes

INT | mDeferredLoadingEnabled
| Non-zero if deferred loading is enabled.
ImageSet * | mImages
| Internal image container.
PrinterSet * | mPrinters
| Internal printer container.
SoundSet * | mSounds
| Internal sound container.
MusicSet * | mMusics
| Internal music container.

## Detailed Description

Configured data container.

Reads and parses a set of configuration data keys from a file. The format of the configuration file is such that there is one property on each row in a text file. Each property is a pair of a key and a value, delimited by a '=' char, for example:

     fileName = HelloWorld.xff

Optionally the key can also have a type prefix which is delimited from the rest of the key with a ':' (colon) char, for example:

     image : cursor = arrow.tga

Recognized builtin types are parsed when the configuration file is processed. For some types the data is also loaded at the same time. Note that for recognized types the key is reformatted to use the short form before adding to the data container, which affects only fetching of data with regular get-method instead of a type specific getType-style method. If multiple keys refer to exact same value which results in loading of a resource, the resource is loaded only once so that the same loaded resource is shared between the keys.

Builtin types have getType-style methods which can be used to read the data easily by the key omitting the type prefix. Builtin types also have both long and short forms of the type, so the previous example could be also written:

     i:cursor = arrow.tga

Leading and trailing spaces are trimmed. Lines starting with character '#' are treated as comment lines and are ignored. Optional parts of value strings can be omitted.

Recognized builtin types:

Long Type | Short Type | Value String Format and Description
--- | --- | ---

`image`

`i`

Value string: `filename,type`

- filename - filename of image which is loaded as a XFcGLResourceSurface when the configuration file is processed.
- type - optional image format as a number (see XFCGFXFORMAT).

Example:

       image:menu.cursor = arrow.tga
       i:splash = splash.tga

`printer`

`p`

Value string: `filename,spacing,type,colorkey`

- filename - filename where to load the printer font image from.
- spacing - default spacing for the printer.
- type - 0:standard printer (XFuPrinter), 1:RLE sprite printer (XFuRLESpritePrinter).
- colorkey - optional color key, hex strings can be used with 0x or # prefix.

Example:

       printer:menu.printer = smallfont.tga,0,1,#0000ff
       p:digitprinter = digits.tga,2,0

`sound`

`s`

Value string: `filename,samplingrate,volume,panning,priority,looping,loopstart,loopend`

- filename - filename of a sound sample.
- samplingrate - optional sampling rate as a real number (-1 = default).
- volume - optional volume as a real number (1.0 = original volume, -1 = default).
- panning - optional panning as a real number [0..1] (-1 = default).
- priority - optional priority as an integer [0..65535] (-1 = default).
- looping - optional looping flag, 0:no looping, 1:looping.
- loopstart - optional loop start point as an integer.
- loopend - optional loop end point as an integer.

Example:

       sound:menu.select = menuselect.wav
       s:menu.move = menumove.wav,-1,0.5

`music`

`m`

Value string: `filename,samplingrate,chanmode,bitmode,volume,priority`

- filename - filename of the music data.
- samplingrate - sampling rate for mixing the music as a real number.
- chanmode - channel mode, 0:mono, 1:stereo.
- bitmode - bits to use, 0:8 bits, 1:16 bits.
- volume - optional volume as a real number (1.0 = original volume, -1 = default).
- priority - optional priority as an integer [0..65535].

Example:

       music:menumusic = menu.xm,16000,0,0,0.3,0
       music:gamemusic = game.xm,8000,0,0,0.15,0

Note:
  XFuConfigurationData object owns all objects it has loaded, so you shouldn't delete manually any objects you access via this class.

Todo:
  Type handler registration interface.

See also:
  getImage

  XFcGLResourceSurface

  getPrinter

  XFuPrinter

  XFuRLESpritePrinter

  getRectangle

  XFcRectangle

  getSound

  XFuConfigurationDataSoundInfo

  getMusic

  XFuConfigurationDataMusicInfo

  XFuConfiguration

  XFcAudio

Definition at line 204 of file XFuConfigurationData.h.

## Member Typedef Documentation

typedef XFcHashtable<XFuStringKey, XFcGLResourceSurface *> XFuConfigurationData::ImageSet`[protected]`

| Internal image container type. Definition at line 321 of file XFuConfigurationData.h. Referenced by init().

typedef XFcHashtable<XFuStringKey, XFuConfigurationDataMusicInfo *> XFuConfigurationData::MusicSet`[protected]`

| Internal music info container type. Definition at line 330 of file XFuConfigurationData.h. Referenced by init().

typedef XFcHashtable<XFuStringKey, XFuPrinter *> XFuConfigurationData::PrinterSet`[protected]`

| Internal printer container type. Definition at line 324 of file XFuConfigurationData.h. Referenced by init().

typedef XFcHashtable<XFuStringKey, XFuConfigurationDataSoundInfo *> XFuConfigurationData::SoundSet`[protected]`

| Internal sound info container type. Definition at line 327 of file XFuConfigurationData.h. Referenced by init().

## Constructor & Destructor Documentation

XFuConfigurationData::~XFuConfigurationData | ( |  | ) | `[virtual]`

| Virtual destructor. Definition at line 102 of file XFuConfigurationData.cpp. References XFuConfiguration::clear(), mImages, mMusics, mPrinters, and mSounds.

XFuConfigurationData::XFuConfigurationData | ( |  | ) | `[protected]`

| Protected constructor. Definition at line 33 of file XFuConfigurationData.cpp.

## Member Function Documentation

void XFuConfigurationData::addImage | ( | const CHAR * | aValue | ) | `[protected]`

| Adds and possibly loads a new image to the internal image container. Definition at line 320 of file XFuConfigurationData.cpp. References loadImage(), mDeferredLoadingEnabled, and mImages. Referenced by put().

void XFuConfigurationData::addMusic | ( | const CHAR * | aValue | ) | `[protected]`

Adds a new music to the internal music container.

Definition at line 486 of file XFuConfigurationData.cpp.

References XFuTokenizer::getToken(), XFuTokenizer::getTokenCount(), XFuConfigurationDataMusicInfo::m16Bit, XFuConfigurationDataMusicInfo::mFilename, XFuConfigurationDataMusicInfo::mFlags, mMusics, XFuConfigurationDataMusicInfo::mPriority, XFuConfigurationDataMusicInfo::mSamplingRate, XFuConfigurationDataMusicInfo::mStereo, XFuConfigurationDataMusicInfo::mVolume, XFuTokenizer::tokenize(), XFUCDAIF_PRIORITY, XFUCDAIF_SAMPLING_RATE, and XFUCDAIF_VOLUME.

Referenced by put().

void XFuConfigurationData::addPrinter | ( | const CHAR * | aValue | ) | `[protected]`

| Adds and possibly loads a new printer to the internal printer container. Definition at line 367 of file XFuConfigurationData.cpp. References loadPrinter(), mDeferredLoadingEnabled, and mPrinters. Referenced by put().

void XFuConfigurationData::addSound | ( | const CHAR * | aValue | ) | `[protected]`

Adds a new sound to the internal sound container.

Definition at line 425 of file XFuConfigurationData.cpp.

References XFuTokenizer::getToken(), XFuTokenizer::getTokenCount(), XFuConfigurationDataSoundInfo::mFilename, XFuConfigurationDataSoundInfo::mFlags, XFuConfigurationDataSoundInfo::mLoopEnd, XFuConfigurationDataSoundInfo::mLooping, XFuConfigurationDataSoundInfo::mLoopStart, XFuConfigurationDataSoundInfo::mPanning, XFuConfigurationDataSoundInfo::mPriority, XFuConfigurationDataSoundInfo::mSamplingRate, mSounds, XFuConfigurationDataSoundInfo::mVolume, XFuTokenizer::tokenize(), XFUCDAIF_LOOPEND, XFUCDAIF_LOOPING, XFUCDAIF_LOOPSTART, XFUCDAIF_PANNING, XFUCDAIF_PRIORITY, XFUCDAIF_SAMPLING_RATE, and XFUCDAIF_VOLUME.

Referenced by put().

XFuConfigurationData * XFuConfigurationData::create | ( | XFcFile * | aFile | ) | `[static]`

Static constructor.

Parameters:

  aFile | open file pointing to configuration data to load.

Returns:
  new configuration data object if successful, or NULL if unsuccessful.

Note:
  Configuration data is assumed to continue to end of the file.

Reimplemented from XFuConfiguration.

Definition at line 66 of file XFuConfigurationData.cpp.

References create(), and load().

XFuConfigurationData * XFuConfigurationData::create | ( | const CHAR * | aFilename | ) | `[static]`

Static constructor.

Parameters:

  aFilename | filename of configuration data to load.

Returns:
  new configuration data object if successful, or NULL if unsuccessful.

Reimplemented from XFuConfiguration.

Definition at line 51 of file XFuConfigurationData.cpp.

References create(), and load().

XFuConfigurationData * XFuConfigurationData::create | ( |  | ) | `[static]`

Static constructor.

Returns:
  new configuration data object if successful, or NULL if unsuccessful.

Reimplemented from XFuConfiguration.

Definition at line 39 of file XFuConfigurationData.cpp.

References init().

Referenced by create().

CHAR * XFuConfigurationData::get | ( | const CHAR * | aKey | ) | `[virtual]`

Returns the value of a property as a string, or NULL if not found.

Parameters:

  aKey | key of the property to return.

Reimplemented from XFuConfiguration.

Definition at line 137 of file XFuConfigurationData.cpp.

References XFuConfiguration::get().

Referenced by getImage(), getMusic(), getPrinter(), getRectangle(), and getSound().

XFcGLResourceSurface * XFuConfigurationData::getImage | ( | const CHAR * | aKey | ) | `[virtual]`

Returns a configuration data image by key, or NULL if not found.

Parameters:

  aKey | key of the image omitting the type prefix and delimiter.

Returns:
  pointer to the image surface, or NULL if not found.

Definition at line 152 of file XFuConfigurationData.cpp.

References get(), loadImage(), makePrefixedKey(), and mImages.

XFuConfigurationDataMusicInfo * XFuConfigurationData::getMusic | ( | const CHAR * | aKey | ) | `[virtual]`

Returns a configuration data music info by key, or NULL if not found.

Parameters:

  aKey | key of the music omitting the type prefix and delimiter.

Returns:
  pointer to music info, or NULL if not found.

Definition at line 235 of file XFuConfigurationData.cpp.

References get(), makePrefixedKey(), and mMusics.

XFuPrinter * XFuConfigurationData::getPrinter | ( | const CHAR * | aKey | ) | `[virtual]`

Returns a configuration data printer by key, or NULL if not found.

Parameters:

  aKey | key of the printer omitting the type prefix and delimiter.

Returns:
  pointer to the printer, or NULL if not found.

Definition at line 169 of file XFuConfigurationData.cpp.

References get(), loadPrinter(), makePrefixedKey(), and mPrinters.

INT XFuConfigurationData::getRectangle | ( | XFcRectangle & | aDest,
|  | const CHAR * | aKey
| ) | `[virtual]`

Gets a property value by key, and then parses and returns the value as a rectangle.

Rectangle value string format: `x,y,width,height`.

- x - X-component of the rectangle as an integer.
- y - optional Y-component of the rectangle as an integer.
- width - optional width of the rectangle as an integer.
- height - optional height of the rectangle as an integer.

Example:

       rectangle:laptime.position = 10,10
       r:viewport = 4,4,160,120

Parameters:

  aDest | returned rectangle, if successful.
  aKey | key of the property value to be parsed.

Returns:
  1 if successful (rectangle was found), or 0 if unsuccessful.

Definition at line 208 of file XFuConfigurationData.cpp.

References get(), and parseRectangleString().

XFuConfigurationDataSoundInfo * XFuConfigurationData::getSound | ( | const CHAR * | aKey | ) | `[virtual]`

Returns a configuration data sound info by key, or NULL if not found.

Parameters:

  aKey | key of the sound omitting the type prefix and delimiter.

Returns:
  pointer to sound info, or NULL if not found.

Definition at line 222 of file XFuConfigurationData.cpp.

References get(), makePrefixedKey(), and mSounds.

INT XFuConfigurationData::init | ( |  | ) | `[protected]`

Initializes a newly constructed object.

Returns:
  1 if successful, 0 if unsuccessful.

Definition at line 81 of file XFuConfigurationData.cpp.

References ImageSet, mImages, mMusics, mPrinters, mSounds, MusicSet, PrinterSet, and SoundSet.

Referenced by create().

INT XFuConfigurationData::load | ( | XFcFile * | aFile | ) | `[virtual]`

Loads new configuration file and merges its data to the current set.

Parameters:

  aFile | open file pointing to the configuration data to load.

Returns:
  1 if successful, 0 if unsuccessful (e.g. file not found).

Note:
  Configuration data is assumed to continue to end of the file.

Reimplemented from XFuConfiguration.

Definition at line 255 of file XFuConfigurationData.cpp.

References XFuConfiguration::load().

INT XFuConfigurationData::load | ( | const CHAR * | aFilename | ) | `[virtual]`

Loads new configuration file and merges its data to the current set.

Parameters:

  aFilename | filename of the configuration data file to load.

Returns:
  1 if successful, 0 if unsuccessful (e.g. file not found).

Reimplemented from XFuConfiguration.

Definition at line 248 of file XFuConfigurationData.cpp.

References XFuConfiguration::load().

Referenced by create().

void XFuConfigurationData::loadImage | ( | ImageSet::iterator & | aIterator | ) | `[protected]`

| Loads a new image to the internal image container. Definition at line 338 of file XFuConfigurationData.cpp. References XFuTokenizer::getToken(), XFuTokenizer::getTokenCount(), and XFuTokenizer::tokenize(). Referenced by addImage(), and getImage().

void XFuConfigurationData::loadPrinter | ( | PrinterSet::iterator & | aIterator | ) | `[protected]`

Loads a new printer to the internal printer container.

Definition at line 385 of file XFuConfigurationData.cpp.

References XFuRLESpritePrinter::create(), XFuPrinter::create(), XFuTokenizer::getToken(), XFuTokenizer::getTokenCount(), XFuPrinter::setLetterSpacing(), and XFuTokenizer::tokenize().

Referenced by addPrinter(), and getPrinter().

CHAR * XFuConfigurationData::makePrefixedKey | ( | const CHAR | aPrefix,
|  | const CHAR * | aKey
| ) | `[protected]`

| Allocates and returns a new key with a specified prefix char. Definition at line 144 of file XFuConfigurationData.cpp. Referenced by getImage(), getMusic(), getPrinter(), and getSound().

XFcRectangle XFuConfigurationData::parseRectangleString | ( | const CHAR * | aValue | ) | `[static]`

Parses a rectangle value string.

Returns:
  rectangle filled with available values, or an empty rectangle (0,0,0,0) if unsuccessful.

Definition at line 186 of file XFuConfigurationData.cpp.

References XFuTokenizer::getToken(), XFuTokenizer::getTokenCount(), and XFuTokenizer::tokenize().

Referenced by getRectangle().

void XFuConfigurationData::put | ( | const CHAR * | aKey,
|  | const CHAR * | aValue
| ) | `[virtual]`

Sets the value of a property.

If the key contains a type prefix delimited by ':' character from the rest of the key, and the type is a recognized builtin type, the value is parsed and possibly loaded according to the type. Properties with recognized builtin types can be accessed with type specific getType-style method. If the possible type prefix is unrecognized then the value must be accessed with get-method.

Parameters:

  aKey | full key of the property to set value for.
  aValue | value of the property.

Reimplemented from XFuConfiguration.

Definition at line 262 of file XFuConfigurationData.cpp.

References addImage(), addMusic(), addPrinter(), addSound(), XFuTokenizer::getToken(), XFuTokenizer::getTokenCount(), XFuConfiguration::put(), XFuTokenizer::tokenize(), XFUCD_TYPE_IMAGE_SHORT_CHAR, XFUCD_TYPE_MUSIC_SHORT_CHAR, XFUCD_TYPE_PRINTER_SHORT_CHAR, and XFUCD_TYPE_SOUND_SHORT_CHAR.

void XFuConfigurationData::setDeferredLoadingEnabled | ( | INT | aEnabled | ) |

Sets deferred loading mode status.

When deferred loading mode is enabled, all recognized object types held by this configuration data container are loaded only when an object is requested for the first time. By default deferred loading is disabled and all recognized types are loaded on load of a configuration file. Deferred loading must be enabled before calling load.

Definition at line 521 of file XFuConfigurationData.cpp.

References mDeferredLoadingEnabled.

## Member Data Documentation

INT XFuConfigurationData::mDeferredLoadingEnabled`[protected]`

| Non-zero if deferred loading is enabled. Definition at line 358 of file XFuConfigurationData.h. Referenced by addImage(), addPrinter(), and setDeferredLoadingEnabled().

ImageSet* XFuConfigurationData::mImages`[protected]`

| Internal image container. Definition at line 360 of file XFuConfigurationData.h. Referenced by addImage(), getImage(), init(), and ~XFuConfigurationData().

MusicSet* XFuConfigurationData::mMusics`[protected]`

| Internal music container. Definition at line 363 of file XFuConfigurationData.h. Referenced by addMusic(), getMusic(), init(), and ~XFuConfigurationData().

PrinterSet* XFuConfigurationData::mPrinters`[protected]`

| Internal printer container. Definition at line 361 of file XFuConfigurationData.h. Referenced by addPrinter(), getPrinter(), init(), and ~XFuConfigurationData().

SoundSet* XFuConfigurationData::mSounds`[protected]`

| Internal sound container. Definition at line 362 of file XFuConfigurationData.h. Referenced by addSound(), getSound(), init(), and ~XFuConfigurationData().

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

- XFuConfigurationData.h
- XFuConfigurationData.cpp

|  | X-Forge Documentation Confidential Copyright © 2002-2003 Fathammer |  | Documentation generated with doxygen by Dimitri van Heesch