![]() |
For storage and retrieval of key/value pairs. More...
#include <Dictionary.h>
Public Types | |
typedef std::map< std::string, std::string > | Data |
typedef Data::const_iterator | iterator |
typedef iterator | const_iterator |
Public Member Functions | |
Dictionary (const std::string &name) | |
Dictionary () | |
virtual | ~Dictionary () |
std::string | getName () const |
Get the name of the dictionary. | |
int | size () const |
Return the number of key/value pairs. | |
std::string | getString (const std::string &, bool capitalize=false) const throw ( ConfigError, FieldConvertError ) |
Get a value as a string. | |
long | getLong (const std::string &) const throw ( ConfigError, FieldConvertError ) |
Get a value as a long. | |
double | getDouble (const std::string &) const throw ( ConfigError, FieldConvertError ) |
Get a value as a double. | |
bool | getBool (const std::string &) const throw ( ConfigError, FieldConvertError ) |
Get a value as a bool. | |
int | getDay (const std::string &) const throw ( ConfigError, FieldConvertError ) |
Get a value as a day of week. | |
void | setString (const std::string &, const std::string &) |
Set a value from a string. | |
void | setLong (const std::string &, long) |
Set a value from a long. | |
void | setDouble (const std::string &, double) |
Set a value from a double. | |
void | setBool (const std::string &, bool) |
Set a value from a bool. | |
void | setDay (const std::string &, int) |
Set a value from a day. | |
bool | has (const std::string &) const |
Check if the dictionary contains a value for key. | |
void | merge (const Dictionary &) |
Merge two dictionaries. | |
iterator | begin () const |
iterator | end () const |
Private Attributes | |
Data | m_data |
std::string | m_name |
For storage and retrieval of key/value pairs.
Definition at line 36 of file Dictionary.h.
Definition at line 45 of file Dictionary.h.
typedef std::map< std::string, std::string > FIX::Dictionary::Data |
Definition at line 43 of file Dictionary.h.
typedef Data::const_iterator FIX::Dictionary::iterator |
Definition at line 44 of file Dictionary.h.
FIX::Dictionary::Dictionary | ( | const std::string & | name | ) | [inline] |
Definition at line 39 of file Dictionary.h.
00039 : m_name( name ) {}
FIX::Dictionary::Dictionary | ( | ) | [inline] |
Definition at line 40 of file Dictionary.h.
virtual FIX::Dictionary::~Dictionary | ( | ) | [inline, virtual] |
Definition at line 41 of file Dictionary.h.
iterator FIX::Dictionary::begin | ( | ) | const [inline] |
iterator FIX::Dictionary::end | ( | ) | const [inline] |
bool FIX::Dictionary::getBool | ( | const std::string & | key | ) | const throw ( ConfigError, FieldConvertError ) |
Get a value as a bool.
Definition at line 85 of file Dictionary.cpp.
References FIX::BoolConvertor::convert(), QF_STACK_POP, QF_STACK_PUSH, and FIX::string_toUpper().
Referenced by FIX::ScreenLogFactory::init(), FIX::ThreadedSocketAcceptor::onConfigure(), and FIX::SocketAcceptor::onConfigure().
00087 { QF_STACK_PUSH(Dictionary::getBool) 00088 00089 Data::const_iterator i = m_data.find( string_toUpper(key) ); 00090 if ( i == m_data.end() ) throw ConfigError( key + " not defined" ); 00091 try 00092 { 00093 return BoolConvertor::convert( i->second ); 00094 } 00095 catch ( FieldConvertError& ) 00096 { 00097 throw ConfigError( "Illegal value " + i->second + " for " + key ); 00098 } 00099 00100 QF_STACK_POP 00101 }
int FIX::Dictionary::getDay | ( | const std::string & | key | ) | const throw ( ConfigError, FieldConvertError ) |
Get a value as a day of week.
Definition at line 103 of file Dictionary.cpp.
References QF_STACK_POP, QF_STACK_PUSH, and FIX::string_toUpper().
00105 { QF_STACK_PUSH(Dictionary::getDay) 00106 00107 Data::const_iterator i = m_data.find( string_toUpper(key) ); 00108 if ( i == m_data.end() ) throw ConfigError( key + " not defined" ); 00109 try 00110 { 00111 std::string value = i->second; 00112 if( value.size() < 2 ) throw FieldConvertError(0); 00113 std::string abbr = value.substr(0, 2); 00114 std::transform( abbr.begin(), abbr.end(), abbr.begin(), tolower ); 00115 if( abbr == "su" ) return 1; 00116 if( abbr == "mo" ) return 2; 00117 if( abbr == "tu" ) return 3; 00118 if( abbr == "we" ) return 4; 00119 if( abbr == "th" ) return 5; 00120 if( abbr == "fr" ) return 6; 00121 if( abbr == "sa" ) return 7; 00122 if( value.size() < 2 ) throw FieldConvertError(0); 00123 } 00124 catch ( FieldConvertError& ) 00125 { 00126 throw ConfigError( "Illegal value " + i->second + " for " + key ); 00127 } 00128 return -1; 00129 00130 QF_STACK_POP 00131 }
double FIX::Dictionary::getDouble | ( | const std::string & | key | ) | const throw ( ConfigError, FieldConvertError ) |
Get a value as a double.
Definition at line 67 of file Dictionary.cpp.
References FIX::DoubleConvertor::convert(), QF_STACK_POP, QF_STACK_PUSH, and FIX::string_toUpper().
00069 { QF_STACK_PUSH(Dictionary::getDouble) 00070 00071 Data::const_iterator i = m_data.find( string_toUpper(key) ); 00072 if ( i == m_data.end() ) throw ConfigError( key + " not defined" ); 00073 try 00074 { 00075 return DoubleConvertor::convert( i->second ); 00076 } 00077 catch ( FieldConvertError& ) 00078 { 00079 throw ConfigError( "Illegal value " + i->second + " for " + key ); 00080 } 00081 00082 QF_STACK_POP 00083 }
long FIX::Dictionary::getLong | ( | const std::string & | key | ) | const throw ( ConfigError, FieldConvertError ) |
Get a value as a long.
Definition at line 49 of file Dictionary.cpp.
References FIX::IntConvertor::convert(), QF_STACK_POP, QF_STACK_PUSH, and FIX::string_toUpper().
Referenced by FIX::ThreadedSocketInitiator::getHost(), FIX::SocketInitiator::getHost(), FIX::ThreadedSocketAcceptor::onConfigure(), FIX::SocketAcceptor::onConfigure(), FIX::ThreadedSocketAcceptor::onInitialize(), and FIX::SocketAcceptor::onInitialize().
00051 { QF_STACK_PUSH(Dictionary::getLong) 00052 00053 Data::const_iterator i = m_data.find( string_toUpper(key) ); 00054 if ( i == m_data.end() ) throw ConfigError( key + " not defined" ); 00055 try 00056 { 00057 return IntConvertor::convert( i->second ); 00058 } 00059 catch ( FieldConvertError& ) 00060 { 00061 throw ConfigError( "Illegal value " + i->second + " for " + key ); 00062 } 00063 00064 QF_STACK_POP 00065 }
std::string FIX::Dictionary::getName | ( | ) | const [inline] |
Get the name of the dictionary.
Definition at line 48 of file Dictionary.h.
References m_name.
00048 { return m_name; }
std::string FIX::Dictionary::getString | ( | const std::string & | key, | |
bool | capitalize = false | |||
) | const throw ( ConfigError, FieldConvertError ) |
Get a value as a string.
Definition at line 33 of file Dictionary.cpp.
References QF_STACK_POP, QF_STACK_PUSH, and FIX::string_toUpper().
Referenced by FIX::FileStoreFactory::create(), FIX::FileLogFactory::create(), FIX::ThreadedSocketInitiator::getHost(), FIX::SocketInitiator::getHost(), FIX::Initiator::initialize(), and FIX::Acceptor::initialize().
00035 { QF_STACK_PUSH(Dictionary::getString) 00036 00037 Data::const_iterator i = m_data.find( string_toUpper(key) ); 00038 if ( i == m_data.end() ) throw ConfigError( key + " not defined" ); 00039 00040 std::string result = i->second; 00041 if( capitalize ) 00042 std::transform(result.begin(), result.end(), result.begin(), toupper); 00043 00044 return result; 00045 00046 QF_STACK_POP 00047 }
bool FIX::Dictionary::has | ( | const std::string & | key | ) | const |
Check if the dictionary contains a value for key.
Definition at line 181 of file Dictionary.cpp.
References m_data, QF_STACK_POP, QF_STACK_PUSH, and FIX::string_toUpper().
Referenced by FIX::FileLogFactory::create(), FIX::ThreadedSocketInitiator::getHost(), FIX::SocketInitiator::getHost(), FIX::ScreenLogFactory::init(), FIX::ThreadedSocketAcceptor::onConfigure(), FIX::SocketAcceptor::onConfigure(), FIX::ThreadedSocketAcceptor::onInitialize(), and FIX::SocketAcceptor::onInitialize().
00182 { QF_STACK_PUSH(Dictionary::has) 00183 return m_data.find( string_toUpper(key) ) != m_data.end(); 00184 QF_STACK_POP 00185 }
void FIX::Dictionary::merge | ( | const Dictionary & | toMerge | ) |
Merge two dictionaries.
Definition at line 187 of file Dictionary.cpp.
References m_data, QF_STACK_POP, and QF_STACK_PUSH.
00188 { QF_STACK_PUSH(Dictionary::merge) 00189 00190 Data::const_iterator i = toMerge.m_data.begin(); 00191 for ( ; i != toMerge.m_data.end(); ++i ) 00192 if ( m_data.find( i->first ) == m_data.end() ) 00193 m_data[ i->first ] = i->second; 00194 00195 QF_STACK_POP 00196 }
void FIX::Dictionary::setBool | ( | const std::string & | key, | |
bool | value | |||
) |
Set a value from a bool.
Definition at line 151 of file Dictionary.cpp.
References FIX::BoolConvertor::convert(), m_data, QF_STACK_POP, QF_STACK_PUSH, FIX::string_strip(), and FIX::string_toUpper().
00152 { QF_STACK_PUSH(Dictionary::setBool) 00153 m_data[ string_strip(string_toUpper(key)) ] = BoolConvertor::convert( value ); 00154 QF_STACK_POP 00155 }
void FIX::Dictionary::setDay | ( | const std::string & | key, | |
int | value | |||
) |
Set a value from a day.
Definition at line 157 of file Dictionary.cpp.
References QF_STACK_POP, QF_STACK_PUSH, and setString().
00158 { QF_STACK_PUSH(Dictionary::setDay) 00159 00160 switch( value ) 00161 { 00162 case 1: 00163 setString( key, "SU" ); break; 00164 case 2: 00165 setString( key, "MO" ); break; 00166 case 3: 00167 setString( key, "TU" ); break; 00168 case 4: 00169 setString( key, "WE" ); break; 00170 case 5: 00171 setString( key, "TH" ); break; 00172 case 6: 00173 setString( key, "FR" ); break; 00174 case 7: 00175 setString( key, "SA" ); break; 00176 } 00177 00178 QF_STACK_POP 00179 }
void FIX::Dictionary::setDouble | ( | const std::string & | key, | |
double | value | |||
) |
Set a value from a double.
Definition at line 145 of file Dictionary.cpp.
References FIX::DoubleConvertor::convert(), m_data, QF_STACK_POP, QF_STACK_PUSH, FIX::string_strip(), and FIX::string_toUpper().
00146 { QF_STACK_PUSH(Dictionary::setDouble) 00147 m_data[ string_strip(string_toUpper(key)) ] = DoubleConvertor::convert( value ); 00148 QF_STACK_POP 00149 }
void FIX::Dictionary::setLong | ( | const std::string & | key, | |
long | value | |||
) |
Set a value from a long.
Definition at line 139 of file Dictionary.cpp.
References FIX::IntConvertor::convert(), m_data, QF_STACK_POP, QF_STACK_PUSH, setString(), FIX::string_strip(), and FIX::string_toUpper().
00140 { QF_STACK_PUSH(Dictionary::setString) 00141 m_data[ string_strip(string_toUpper(key)) ] = IntConvertor::convert( value ); 00142 QF_STACK_POP 00143 }
void FIX::Dictionary::setString | ( | const std::string & | key, | |
const std::string & | value | |||
) |
Set a value from a string.
Definition at line 133 of file Dictionary.cpp.
References m_data, QF_STACK_POP, QF_STACK_PUSH, FIX::string_strip(), and FIX::string_toUpper().
Referenced by setDay(), and setLong().
00134 { QF_STACK_PUSH(Dictionary::setString) 00135 m_data[ string_strip(string_toUpper(key)) ] = string_strip(value); 00136 QF_STACK_POP 00137 }
int FIX::Dictionary::size | ( | ) | const [inline] |
Return the number of key/value pairs.
Definition at line 50 of file Dictionary.h.
References m_data.
00050 { return m_data.size(); }
Data FIX::Dictionary::m_data [private] |
Definition at line 88 of file Dictionary.h.
Referenced by begin(), end(), has(), merge(), setBool(), setDouble(), setLong(), setString(), and size().
std::string FIX::Dictionary::m_name [private] |
Definition at line 89 of file Dictionary.h.
Referenced by getName().