Rally X
ELEN3009 Project by Justin Wernick and David Schneider
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
Config Class Reference

Object for handling user settings loaded from a file. More...

#include <Config.h>

List of all members.

Public Member Functions

 Config (const string &filename)
 Constructs a Config object from a file with the given path.
unsigned int screenWidth () const
 Function for accessing the screen width setting in pixels.
unsigned int screenHeight () const
 Function for accessing the screen height setting in pixels.
bool fullscreen () const
 Function for accessing whether the game should be displayed in fullscreen or windowed mode.

Private Member Functions

void readFile (ifstream &file, map< string, string > &map)
 Reads all of the settings defined in a file into a map.
void fillValues (const map< string, string > &readValues, map< string, string > &unfoundValues)
 Initialises the Config option's parameters to those in the readValues map.
string extractValue (const map< string, string > &readValues, map< string, string > &unfoundValues, const string &key, const string &defaultValue)
 Helper function for fillValues. Finds the value for a single key.
void writeUnfoundValues (ofstream &file, const map< string, string > &unfoundValues)
 Writes settings that were not found in the file to the file with default values.
void setScreenWidth (const string &screenWidthStr)
 Initializes the screen width in pixels from a given string.
void setScreenHeight (const string &screenHeightStr)
 Initializes the screen height in pixels from a given string.
void setFullscreen (const string &fullscreenStr)
 Initializes the fullscreen setting from a given string.

Private Attributes

unsigned int _screenWidth
 The desired width of the screen in pixels.
unsigned int _screenHeight
 The desired height of the screen in pixels.
bool _fullscreen
 The desired fullscreen or windowed setting.

Static Private Attributes

static const string SCREEN_WIDTH_KEY
 The key for the screen width setting, initialized to "screen_width".
static const string SCREEN_HEIGHT_KEY
 The key for the screen height setting, initialized to "screen_height".
static const string FULLSCREEN_KEY
 The key for the fullscreen setting, initialized to "fullscreen".
static const string SCREEN_WIDTH_DEFAULT
 The default value for the screen width setting, initialized to 800.
static const string SCREEN_HEIGHT_DEFAULT
 The default value for the screen height setting, initialized to 600.
static const string FULLSCREEN_DEFAULT
 The default value for the fullscreen setting, initialized to false.

Detailed Description

Object for handling user settings loaded from a file.

These settings are currently all related to the screen (resolution and windowed or fullscreen). If custom controls are implemented in a later release, they will be loaded here. If a setting exists but is not found in the config file, it is set to a default value and written to the file.

Author:
Justin Wernick
David Schneider

Definition at line 20 of file Config.h.


Constructor & Destructor Documentation

Config::Config ( const string &  filename)

Constructs a Config object from a file with the given path.

Opens the file and reads all of the settings in the file. The read settings are bound to the settings that have keys defined in the class. And settings missing from the file are set to default values, and the default values are written to the file.

Parameters:
[in]filenameThe path of the file in which the settings are stored.

Definition at line 12 of file Config.cpp.


Member Function Documentation

string Config::extractValue ( const map< string, string > &  readValues,
map< string, string > &  unfoundValues,
const string &  key,
const string &  defaultValue 
) [private]

Helper function for fillValues. Finds the value for a single key.

If the given key does not appear, it is added to the unfoundValues map with the given default

Parameters:
[in]readValuesA map containing all of the settings read in from a config file.
[out]unfoundValuesA map that is populated with and settings not found in readValues.
[in]keyThe key of the setting to be found in readValues.
[in]defaultValueThe value to return and add to unfoundValues if the setting is not found in readValues.
Returns:
The value corresponding to the requested key.

Definition at line 72 of file Config.cpp.

void Config::fillValues ( const map< string, string > &  readValues,
map< string, string > &  unfoundValues 
) [private]

Initialises the Config option's parameters to those in the readValues map.

Parameters with a key that does not appear in readValues are initialised to a default value. The default value, and its key, are then added to the unfoundValues map.

Parameters:
[in]readValuesA map containing all of the settings read in from a config file.
[out]unfoundValuesA map that is populated with and settings not found in readValues.

Definition at line 65 of file Config.cpp.

bool Config::fullscreen ( ) const

Function for accessing whether the game should be displayed in fullscreen or windowed mode.

Returns:
The desired fullscreen setting. A result of true means fullscreen mode, while a result of false means windowed mode.

Definition at line 40 of file Config.cpp.

void Config::readFile ( ifstream &  file,
map< string, string > &  map 
) [private]

Reads all of the settings defined in a file into a map.

Reads each line that is in the format "key=value" in a file into a map. Lines that do not contain a '=' are ignored.

Parameters:
[in]fileAn opened filestream object at the beginning of the file to be read. After the function call, file will be at the end of the file.
[out]mapThe map that is populated with settings.

Definition at line 45 of file Config.cpp.

unsigned int Config::screenHeight ( ) const

Function for accessing the screen height setting in pixels.

Returns:
The desired height of the screen in pixels.

Definition at line 36 of file Config.cpp.

unsigned int Config::screenWidth ( ) const

Function for accessing the screen width setting in pixels.

Returns:
The desired width of the screen in pixels.

Definition at line 32 of file Config.cpp.

void Config::setFullscreen ( const string &  fullscreenStr) [private]

Initializes the fullscreen setting from a given string.

Parameters:
[in]fullscreenStrA string representing whether the screen should be in fullscreen mode ("true") or windowed mode (anything else).

Definition at line 102 of file Config.cpp.

void Config::setScreenHeight ( const string &  screenHeightStr) [private]

Initializes the screen height in pixels from a given string.

Parameters:
[in]screenHeightStrA string representing the desired screen height, read from a file.

Definition at line 98 of file Config.cpp.

void Config::setScreenWidth ( const string &  screenWidthStr) [private]

Initializes the screen width in pixels from a given string.

Parameters:
[in]screenWidthStrA string representing the desired screen width, read from a file.

Definition at line 94 of file Config.cpp.

void Config::writeUnfoundValues ( ofstream &  file,
const map< string, string > &  unfoundValues 
) [private]

Writes settings that were not found in the file to the file with default values.

Parameters:
[in]fileThe opened filestream to which the key=value pairs are written.
[in]unfoundValuesThe map of key value pairs to be written to the file.

Definition at line 86 of file Config.cpp.


Member Data Documentation

bool Config::_fullscreen [private]

The desired fullscreen or windowed setting.

Definition at line 125 of file Config.h.

unsigned int Config::_screenHeight [private]

The desired height of the screen in pixels.

Definition at line 124 of file Config.h.

unsigned int Config::_screenWidth [private]

The desired width of the screen in pixels.

Definition at line 123 of file Config.h.

const string Config::FULLSCREEN_DEFAULT [static, private]

The default value for the fullscreen setting, initialized to false.

Definition at line 133 of file Config.h.

const string Config::FULLSCREEN_KEY [static, private]

The key for the fullscreen setting, initialized to "fullscreen".

Definition at line 129 of file Config.h.

const string Config::SCREEN_HEIGHT_DEFAULT [static, private]

The default value for the screen height setting, initialized to 600.

Definition at line 132 of file Config.h.

const string Config::SCREEN_HEIGHT_KEY [static, private]

The key for the screen height setting, initialized to "screen_height".

Definition at line 128 of file Config.h.

const string Config::SCREEN_WIDTH_DEFAULT [static, private]

The default value for the screen width setting, initialized to 800.

Definition at line 131 of file Config.h.

const string Config::SCREEN_WIDTH_KEY [static, private]

The key for the screen width setting, initialized to "screen_width".

Definition at line 127 of file Config.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator