Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

ConfigurationDatabase Class Reference

List of all members.

Detailed Description

Creates a configuration database that can both read and write a values to a file.
These configuration files must be in the format of:
#comment
[header]
key value

Author:
John Schneiderman

Definition at line 46 of file configurationdatabase.h.

Public Types

typedef map< string, KeyValuePairConfigurationDatabaseType
typedef vector< string > Headers
typedef vector< string > Keys
typedef map< string, string > KeyValuePair

Public Member Functions

void addHeaderKeyValuePair (const string &header, const string &key, const string &value)
void addKeyValuePair (const string &header, const string &key, const string &value)
 ConfigurationDatabase (const string &filename)
 ConfigurationDatabase ()
double doubleValue (const string &header, const string &key) const
Headers headers () const
int intValue (const string &header, const string &key) const
Keys keys (const string &header) const
string stringValue (const string &header, const string &key) const

Private Attributes

map< int, string > m_comments
ConfigurationDatabaseType m_configurations

Static Private Attributes

static const char BEGIN_COMMENT = '#'
static const char BEGIN_HEADER = '['
static const char END_HEADER = ']'

Friends

ostream & operator<< (ostream &out, const ConfigurationDatabase &database)
istream & operator>> (istream &in, ConfigurationDatabase &database)


Member Typedef Documentation

typedef map<string, KeyValuePair> ConfigurationDatabase::ConfigurationDatabaseType
 

Parameters:
ConfigurationDatabaseType is a quick type to use for configuration headers and key-value pairs.
The string is the header name, keyValuePair is the key-value pair.

Definition at line 58 of file configurationdatabase.h.

typedef vector<string> ConfigurationDatabase::Headers
 

Parameters:
Headers is a definition for the headers.

Definition at line 62 of file configurationdatabase.h.

typedef vector<string> ConfigurationDatabase::Keys
 

Parameters:
Keys is a definition for the keys.

Definition at line 60 of file configurationdatabase.h.

typedef map<string, string> ConfigurationDatabase::KeyValuePair
 

Parameters:
KeyValuePair is a quick type to use for key-values pairs.
The first string is the key, and the second string is the value.

Definition at line 53 of file configurationdatabase.h.


Constructor & Destructor Documentation

ConfigurationDatabase::ConfigurationDatabase  ) 
 

A general constructor to build a configuration with.

Definition at line 28 of file configurationdatabase.cpp.

ConfigurationDatabase::ConfigurationDatabase const string &  filename  ) 
 

A single argument constructor.

Parameters:
filename is the configuration file to parse.
Exceptions:
string if the configuration file cannot be found.

Definition at line 32 of file configurationdatabase.cpp.


Member Function Documentation

void ConfigurationDatabase::addHeaderKeyValuePair const string &  header,
const string &  key,
const string &  value
 

This will add a new header, and new key-value pairs to the database.

Parameters:
header is the new header to add to the database.
key is the new key to add to the database.
value is the value associated with the key.

Definition at line 112 of file configurationdatabase.cpp.

References m_configurations.

void ConfigurationDatabase::addKeyValuePair const string &  header,
const string &  key,
const string &  value
 

This will add a new key-value pair to the database.

Parameters:
header is the header to insert the key-value pair under.
key is the key to add to the database.
value is the value associated with the key.
Exceptions:
string if the header is not already in the database.

Definition at line 117 of file configurationdatabase.cpp.

References m_configurations.

double ConfigurationDatabase::doubleValue const string &  header,
const string &  key
const
 

Gets the value that is matched with the key in the database.

Parameters:
header is the header the key-value pair is located inside.
key is the key that is associated with the value in the key-value pair.
Returns:
the contents retrieved as a double.
Exceptions:
string if either the header or the key cannot be found.

Definition at line 57 of file configurationdatabase.cpp.

References m_configurations.

Referenced by createCluster(), nonInteractiveRun(), RadialDensityHistogram::RadialDensityHistogram(), RadialDistributionFunction::RadialDistributionFunction(), and selectSimulation().

ConfigurationDatabase::Headers ConfigurationDatabase::headers  )  const
 

Retrieves all the headers in the database.

Returns:
the headers found.

Definition at line 85 of file configurationdatabase.cpp.

References m_configurations.

Referenced by nonInteractiveRun().

int ConfigurationDatabase::intValue const string &  header,
const string &  key
const
 

Gets the value that is matched with the key in the database.

Parameters:
header is the header the key-value pair is located inside.
key is the key that is associated with the value in the key-value pair.
Returns:
the contents retrieved as an int.
Exceptions:
string if either the header or the key cannot be found.

Definition at line 43 of file configurationdatabase.cpp.

References m_configurations.

Referenced by createCluster(), KineticEnergyHistogram::KineticEnergyHistogram(), nonInteractiveRun(), PotentialEnergyHistogram::PotentialEnergyHistogram(), RadialDensityHistogram::RadialDensityHistogram(), RadialDistributionFunction::RadialDistributionFunction(), and selectSimulation().

ConfigurationDatabase::Keys ConfigurationDatabase::keys const string &  header  )  const
 

Retrieves all the keys in the database for a specified header.

Parameters:
header is the name of the header to retrieve the keys from within the database.
Returns:
all the keys found for the header.

Definition at line 98 of file configurationdatabase.cpp.

References m_configurations.

string ConfigurationDatabase::stringValue const string &  header,
const string &  key
const
 

Gets the value that is matched with the key in the database.

Parameters:
header is the header the key-value pair is located inside.
key is the key that is associated with the value in the key-value pair.
Returns:
the contents retrieved as a string.
Exceptions:
string if either the header or the key cannot be found.

Definition at line 71 of file configurationdatabase.cpp.

References m_configurations.

Referenced by nonInteractiveRun().


Friends And Related Function Documentation

ostream& operator<< ostream &  out,
const ConfigurationDatabase database
[friend]
 

Writes out a configuration database.

Parameters:
out is the output source, in the format of:
[headers]
key value
database holds the configurations to be written.
Returns:
the output source.

Definition at line 167 of file configurationdatabase.cpp.

istream& operator>> istream &  in,
ConfigurationDatabase database
[friend]
 

Reads in a configuration database from a stream.

Parameters:
in is the input source, in the format of:
#comments
[headers]
key value
database is where to store the configurations.
Returns:
the input source.
Exceptions:
string if in the stream the header is missing for a key-value pair or if a key is missing it's value.

Definition at line 125 of file configurationdatabase.cpp.


Member Data Documentation

const char ConfigurationDatabase::BEGIN_COMMENT = '#' [static, private]
 

Parameters:
BEGIN_COMMENT is the character that is the beginning of a comment in a configuration file.

Definition at line 155 of file configurationdatabase.h.

Referenced by operator<<(), and operator>>().

const char ConfigurationDatabase::BEGIN_HEADER = '[' [static, private]
 

Parameters:
BEGIN_HEADER is the character that is the beginning of a header in a configuration file.

Definition at line 157 of file configurationdatabase.h.

Referenced by operator<<(), and operator>>().

const char ConfigurationDatabase::END_HEADER = ']' [static, private]
 

Parameters:
END_HEADER is the character that is the ending of a header in a configuration file.

Definition at line 159 of file configurationdatabase.h.

Referenced by operator<<().

map<int, string> ConfigurationDatabase::m_comments [private]
 

Parameters:
m_comments holds all the comments in a configuration file.
Note:
The comments are stored by the line number they appear. If the configuration file is not already sorted, comments may be lost.
Todo:
fix so that comments will never be lost when written out.

Definition at line 153 of file configurationdatabase.h.

Referenced by operator<<(), and operator>>().

ConfigurationDatabaseType ConfigurationDatabase::m_configurations [private]
 

Parameters:
m_configurations holds all of the configuration information.

Definition at line 147 of file configurationdatabase.h.

Referenced by addHeaderKeyValuePair(), addKeyValuePair(), doubleValue(), headers(), intValue(), keys(), operator<<(), operator>>(), and stringValue().


The documentation for this class was generated from the following files:
Generated on Tue Mar 28 23:28:49 2006 for ClusterSim by  doxygen 1.4.4