OpenASIP
2.0
|
#include <ConfigurationFile.hh>
Classes | |
struct | Key |
Public Member Functions | |
ConfigurationFile (bool doChecking=false) | |
virtual | ~ConfigurationFile () |
void | load (std::istream &inputStream) |
bool | hasKey (const std::string &key) |
std::string | value (const std::string &key, int index=0) |
int | itemCount (const std::string &key) |
int | intValue (const std::string &key, int index=0) |
float | floatValue (const std::string &key, int index=0) |
std::string | stringValue (const std::string &key, int index=0) |
bool | booleanValue (const std::string &key, int index=0) |
unsigned int | timeStampValue (const std::string &key) |
Protected Types | |
enum | ConfigurationValueType { VT_INTEGER, VT_FLOAT, VT_STRING, VT_BOOLEAN, VT_READABLE_TIME, VT_UNIX_TIMESTAMP } |
enum | ConfigurationFileError { FE_SYNTAX, FE_ILLEGAL_TYPE, FE_UNKNOWN_KEY, FE_MISSING_VALUE } |
Protected Member Functions | |
void | addSupportedKey (const std::string &key, ConfigurationValueType type, bool caseSensitive=false) |
virtual bool | handleError (int lineNumber, ConfigurationFileError error, const std::string &line) |
Private Types | |
typedef std::map< TCEString, std::vector< TCEString > > | ValueContainer |
typedef std::map< Key *, ConfigurationValueType > | KeyContainer |
Private Member Functions | |
void | parse (std::istream &inputStream) |
bool | checkSemantics (const std::string &key, const std::string &value, int lineNumber, const std::string &line) |
bool | isComment (const std::string &line) |
bool | legalTime (const std::string &line) |
std::string | valueOfKey (const std::string &key, int index) |
Private Attributes | |
bool | check_ |
True if semantics of the configuration file is checked. More... | |
ValueContainer | values_ |
Contains all the values of configuration file. More... | |
KeyContainer | keys_ |
Contains all the legal keys of the configuration file. More... | |
Class that is able to read files with key-value-pairs, such as the processor configuration file.
Can do simple sanity and type checking of the file while loading it.
Definition at line 50 of file ConfigurationFile.hh.
|
private |
Definition at line 107 of file ConfigurationFile.hh.
|
private |
Definition at line 103 of file ConfigurationFile.hh.
|
protected |
Error types.
Enumerator | |
---|---|
FE_SYNTAX | Syntax error. |
FE_ILLEGAL_TYPE | Illegal type error. |
FE_UNKNOWN_KEY | Unknown key error. |
FE_MISSING_VALUE | Missing value error. |
Definition at line 85 of file ConfigurationFile.hh.
|
protected |
Different value types.
Definition at line 73 of file ConfigurationFile.hh.
ConfigurationFile::ConfigurationFile | ( | bool | doChecking = false | ) |
Constructor.
doChecking | If true, checks the semantics of the configuration file while reading it. |
Definition at line 72 of file ConfigurationFile.cc.
|
virtual |
Destructor.
Definition at line 78 of file ConfigurationFile.cc.
References MapTools::deleteAllKeys(), and keys_.
|
protected |
Add supported key type.
key | Key to be added. |
type | Type of the value. |
caseSensitive | True if key is case sensitive. |
Definition at line 292 of file ConfigurationFile.cc.
References ConfigurationFile::Key::caseSensitive_, keys_, and ConfigurationFile::Key::name_.
Referenced by ProcessorConfigurationFile::ProcessorConfigurationFile().
bool ConfigurationFile::booleanValue | ( | const std::string & | key, |
int | index = 0 |
||
) |
Returns the boolean value of the given key.
key | The key. |
index | The index of the value. |
KeyNotFound | If key is not found. |
OutOfRange | If index is out of range. |
InvalidData | If value type is wrong. |
Definition at line 202 of file ConfigurationFile.cc.
References __func__, StringTools::stringToLower(), value(), and valueOfKey().
|
private |
Check the semantics of key value pair.
key | The key. |
value | The value. |
lineNumber | The line number. |
line | The line. |
Definition at line 406 of file ConfigurationFile.cc.
References ConfigurationFile::Key::caseSensitive_, FE_ILLEGAL_TYPE, FE_UNKNOWN_KEY, handleError(), keys_, legalTime(), ConfigurationFile::Key::name_, StringTools::stringToUpper(), Conversion::toFloat(), Conversion::toInt(), value(), VT_BOOLEAN, VT_FLOAT, VT_INTEGER, VT_READABLE_TIME, and VT_UNIX_TIMESTAMP.
Referenced by parse().
float ConfigurationFile::floatValue | ( | const std::string & | key, |
int | index = 0 |
||
) |
Returns the float value of the given key.
key | The key. |
index | The index of the value. |
KeyNotFound | If key is not found. |
OutOfRange | If index is out of range. |
InvalidData | If data is wrong type. |
Definition at line 167 of file ConfigurationFile.cc.
References __func__, Conversion::toFloat(), value(), and valueOfKey().
|
protectedvirtual |
Default implementation, all errors are handled.
Reimplemented in ProcessorConfigurationFile.
Definition at line 310 of file ConfigurationFile.cc.
Referenced by checkSemantics(), and parse().
bool ConfigurationFile::hasKey | ( | const std::string & | key | ) |
Returns true if there is a given key with a value in configuration.
key | The key. |
Definition at line 99 of file ConfigurationFile.cc.
References values_.
int ConfigurationFile::intValue | ( | const std::string & | key, |
int | index = 0 |
||
) |
Returns the int value of the given key.
key | The key. |
index | The index of the value. |
KeyNotFound | If key is not found. |
OutOfRange | If index is out of range. |
InvalidData | If data is wrong type. |
Definition at line 146 of file ConfigurationFile.cc.
References __func__, Conversion::toInt(), value(), and valueOfKey().
Referenced by ProcessorConfigurationFile::architectureSize(), ProcessorConfigurationFile::encodingMapSize(), and ProcessorConfigurationFile::implementationSize().
|
private |
Returns true if line is a comment.
line | Line to be checked. |
Definition at line 388 of file ConfigurationFile.cc.
Referenced by parse().
int ConfigurationFile::itemCount | ( | const std::string & | key | ) |
Returns the number of values a given key has.
key | The key. |
KeyNotFound | If key is not found. |
Definition at line 126 of file ConfigurationFile.cc.
|
private |
Returns true if string is a legal time representation.
line | Line to be checked. |
Definition at line 483 of file ConfigurationFile.cc.
Referenced by checkSemantics(), and timeStampValue().
void ConfigurationFile::load | ( | std::istream & | inputStream | ) |
Parses the configuration file and stores the results to internal structure.
inputStream | Input file stream. |
Definition at line 88 of file ConfigurationFile.cc.
References parse().
Referenced by ProcessorConfigurationFile::ProcessorConfigurationFile().
|
private |
Parses the configuration file.
inputStream | Stream where file is read from. |
Definition at line 324 of file ConfigurationFile.cc.
References check_, checkSemantics(), StringTools::chopString(), FE_MISSING_VALUE, FE_SYNTAX, handleError(), isComment(), StringTools::trim(), value(), and values_.
Referenced by load().
string ConfigurationFile::stringValue | ( | const std::string & | key, |
int | index = 0 |
||
) |
Returns string value of the given key.
key | The key. |
index | The index of the value. |
KeyNotFound | If key is not found. |
OutOfRange | If index is out of range. |
Definition at line 187 of file ConfigurationFile.cc.
References valueOfKey().
unsigned int ConfigurationFile::timeStampValue | ( | const std::string & | key | ) |
Returns the time stamp value of the given key.
key | The key. |
KeyNotFound | If key is not found. |
Definition at line 228 of file ConfigurationFile.cc.
References __func__, legalTime(), Conversion::toInt(), StringTools::trim(), value(), and values_.
Referenced by ProcessorConfigurationFile::architectureModified(), ProcessorConfigurationFile::encodingMapModified(), and ProcessorConfigurationFile::implementationModified().
std::string ConfigurationFile::value | ( | const std::string & | key, |
int | index = 0 |
||
) |
Returns the value of the given key.
key | The key. |
index | The index of the value. |
KeyNotFound | If key is not found. |
OutOfRange | If index is out of range. |
Definition at line 114 of file ConfigurationFile.cc.
References valueOfKey().
Referenced by ProcessorConfigurationFile::architectureName(), booleanValue(), checkSemantics(), ProcessorConfigurationFile::encodingMapName(), floatValue(), ProcessorConfigurationFile::implementationName(), intValue(), parse(), and timeStampValue().
|
private |
Returns the value of the given key and a given index.
key | The key. |
index | Index of the value. |
KeyNotFound | If key is not found. |
OutOfRange | If index is out of range. |
Definition at line 505 of file ConfigurationFile.cc.
References __func__, and values_.
Referenced by booleanValue(), floatValue(), intValue(), stringValue(), and value().
|
private |
True if semantics of the configuration file is checked.
Definition at line 134 of file ConfigurationFile.hh.
Referenced by parse().
|
private |
Contains all the legal keys of the configuration file.
Definition at line 138 of file ConfigurationFile.hh.
Referenced by addSupportedKey(), checkSemantics(), and ~ConfigurationFile().
|
private |
Contains all the values of configuration file.
Definition at line 136 of file ConfigurationFile.hh.
Referenced by hasKey(), itemCount(), parse(), timeStampValue(), and valueOfKey().