FIX::Dictionary Class Reference

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.
size_t | 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.
int | getInt (const std::string &) const throw ( ConfigError, FieldConvertError )
| Get a value as a int.
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 | setInt (const std::string &, int)
| Set a value from a int.
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

## Detailed Description

For storage and retrieval of key/value pairs.

Definition at line 36 of file Dictionary.h.

## Member Typedef Documentation

## const_iterator

typedef iterator FIX::Dictionary::const_iterator

Definition at line 45 of file Dictionary.h.

## Data

typedef std::map< std::string, std::string > FIX::Dictionary::Data

Definition at line 43 of file Dictionary.h.

## iterator

typedef Data::const_iterator FIX::Dictionary::iterator

Definition at line 44 of file Dictionary.h.

## Constructor & Destructor Documentation

## Dictionary() [1/2]

FIX::Dictionary::Dictionary | ( | const std::string & | name | ) |

inline

Definition at line 39 of file Dictionary.h.

: m_name( name ) {}
FIX::Dictionary::m_name
std::string m_name
Definition Dictionary.h:89

## Dictionary() [2/2]

FIX::Dictionary::Dictionary | ( |  | ) |

inline

Definition at line 40 of file Dictionary.h.

{}

## ~Dictionary()

virtual FIX::Dictionary::~Dictionary | ( |  | ) |

inline virtual

Definition at line 41 of file Dictionary.h.

{}

## Member Function Documentation

## begin()

iterator FIX::Dictionary::begin | ( |  | ) | const

inline

Definition at line 84 of file Dictionary.h.

{ return m_data.begin(); }
FIX::Dictionary::m_data
Data m_data
Definition Dictionary.h:88

References m_data.

## end()

iterator FIX::Dictionary::end | ( |  | ) | const

inline

Definition at line 85 of file Dictionary.h.

{ return m_data.end(); }

References m_data.

Referenced by FIX::SessionSettings::has().

## getBool()

bool FIX::Dictionary::getBool | ( | const std::string & | key | ) | const
throw | ( | ConfigError,
|  | FieldConvertError
| ) |  |

Get a value as a bool.

Definition at line 71 of file Dictionary.cpp.

{
try
{
return BoolConvertor::convert( getString(key) );
}
catch ( FieldConvertError& )
{
throw ConfigError( "Illegal value " + getString(key) + " for " + key );
}
}
FIX::Dictionary::getString
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition Dictionary.cpp:32
FIX::BoolConvertor::convert
static std::string convert(bool value)
Definition FieldConvertors.h:401

References FIX::BoolConvertor::convert().

Referenced by FIX::ScreenLogFactory::init(), FIX::SocketAcceptor::onConfigure(), FIX::SocketInitiator::onConfigure(), FIX::ThreadedSocketAcceptor::onConfigure(), FIX::ThreadedSocketInitiator::onConfigure(), FIX::SocketAcceptor::onInitialize(), and FIX::ThreadedSocketAcceptor::onInitialize().

## getDay()

int FIX::Dictionary::getDay | ( | const std::string & | key | ) | const
throw | ( | ConfigError,
|  | FieldConvertError
| ) |  |

Get a value as a day of week.

Definition at line 84 of file Dictionary.cpp.

{
try
{
std::string value = getString(key);
if( value.size() < 2 ) throw FieldConvertError();
std::string abbr = value.substr(0, 2);
std::transform( abbr.begin(), abbr.end(), abbr.begin(), tolower );
if( abbr == "su" ) return 1;
if( abbr == "mo" ) return 2;
if( abbr == "tu" ) return 3;
if( abbr == "we" ) return 4;
if( abbr == "th" ) return 5;
if( abbr == "fr" ) return 6;
if( abbr == "sa" ) return 7;
}
catch ( FieldConvertError& )
{
throw ConfigError( "Illegal value " + getString(key) + " for " + key );
}
return -1;
}

## getDouble()

double FIX::Dictionary::getDouble | ( | const std::string & | key | ) | const
throw | ( | ConfigError,
|  | FieldConvertError
| ) |  |

Get a value as a double.

Definition at line 58 of file Dictionary.cpp.

{
try
{
return DoubleConvertor::convert( getString(key) );
}
catch ( FieldConvertError& )
{
throw ConfigError( "Illegal value " + getString(key) + " for " + key );
}
}
FIX::DoubleConvertor::convert
static std::string convert(double value, int padding=0)
Definition FieldConvertors.h:255

References FIX::DoubleConvertor::convert().

## getInt()

int FIX::Dictionary::getInt | ( | const std::string & | key | ) | const
throw | ( | ConfigError,
|  | FieldConvertError
| ) |  |

Get a value as a int.

Definition at line 45 of file Dictionary.cpp.

{
try
{
return IntConvertor::convert( getString(key) );
}
catch ( FieldConvertError& )
{
throw ConfigError( "Illegal value " + getString(key) + " for " + key );
}
}
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition FieldConvertors.h:153

References FIX::IntConvertor::convert().

Referenced by FIX::SocketInitiator::getHost(), FIX::ThreadedSocketInitiator::getHost(), FIX::SocketAcceptor::onConfigure(), FIX::SocketInitiator::onConfigure(), FIX::ThreadedSocketAcceptor::onConfigure(), FIX::ThreadedSocketInitiator::onConfigure(), FIX::SocketAcceptor::onInitialize(), and FIX::ThreadedSocketAcceptor::onInitialize().

## getName()

std::string FIX::Dictionary::getName | ( |  | ) | const

inline

Get the name of the dictionary.

Definition at line 48 of file Dictionary.h.

{ return m_name; }

References m_name.

## getString()

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 32 of file Dictionary.cpp.

{
Data::const_iterator i = m_data.find( string_toUpper(key) );
if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
std::string result = i->second;
if( capitalize )
std::transform(result.begin(), result.end(), result.begin(), toupper);
return result;
}
FIX::string_toUpper
std::string string_toUpper(const std::string &value)
Definition Utility.cpp:53

References FIX::string_toUpper().

Referenced by FIX::FileLogFactory::create(), FIX::FileLogFactory::create(), FIX::FileStoreFactory::create(), FIX::SocketInitiator::getHost(), FIX::ThreadedSocketInitiator::getHost(), FIX::Acceptor::initialize(), and FIX::Initiator::initialize().

## has()

bool FIX::Dictionary::has | ( | const std::string & | key | ) | const

Check if the dictionary contains a value for key.

Definition at line 149 of file Dictionary.cpp.

{
return m_data.find( string_toUpper(key) ) != m_data.end();
}

References m_data, and FIX::string_toUpper().

Referenced by FIX::FileLogFactory::create(), FIX::FileLogFactory::create(), FIX::SocketInitiator::getHost(), FIX::ThreadedSocketInitiator::getHost(), FIX::ScreenLogFactory::init(), FIX::SocketAcceptor::onConfigure(), FIX::SocketInitiator::onConfigure(), FIX::ThreadedSocketAcceptor::onConfigure(), FIX::ThreadedSocketInitiator::onConfigure(), FIX::SocketAcceptor::onInitialize(), and FIX::ThreadedSocketAcceptor::onInitialize().

## merge()

void FIX::Dictionary::merge | ( | const Dictionary & | toMerge | ) |

Merge two dictionaries.

Definition at line 154 of file Dictionary.cpp.

{
Data::const_iterator i = toMerge.m_data.begin();
for ( ; i != toMerge.m_data.end(); ++i )
if ( m_data.find( i->first ) == m_data.end() )
m_data[ i->first ] = i->second;
}

References m_data.

## setBool()

void FIX::Dictionary::setBool | ( | const std::string & | key,
|  | bool | value
| ) |  |

Set a value from a bool.

Definition at line 123 of file Dictionary.cpp.

{
m_data[ string_strip(string_toUpper(key)) ] = BoolConvertor::convert( value );
}
FIX::string_strip
std::string string_strip(const std::string &value)
Definition Utility.cpp:67

References FIX::BoolConvertor::convert(), m_data, FIX::string_strip(), and FIX::string_toUpper().

## setDay()

void FIX::Dictionary::setDay | ( | const std::string & | key,
|  | int | value
| ) |  |

Set a value from a day.

Definition at line 128 of file Dictionary.cpp.

{
switch( value )
{
case 1:
setString( key, "SU" ); break;
case 2:
setString( key, "MO" ); break;
case 3:
setString( key, "TU" ); break;
case 4:
setString( key, "WE" ); break;
case 5:
setString( key, "TH" ); break;
case 6:
setString( key, "FR" ); break;
case 7:
setString( key, "SA" ); break;
}
}
FIX::Dictionary::setString
void setString(const std::string &, const std::string &)
Set a value from a string.
Definition Dictionary.cpp:108

References setString().

## setDouble()

void FIX::Dictionary::setDouble | ( | const std::string & | key,
|  | double | value
| ) |  |

Set a value from a double.

Definition at line 118 of file Dictionary.cpp.

{
m_data[ string_strip(string_toUpper(key)) ] = DoubleConvertor::convert( value );
}

References FIX::DoubleConvertor::convert(), m_data, FIX::string_strip(), and FIX::string_toUpper().

## setInt()

void FIX::Dictionary::setInt | ( | const std::string & | key,
|  | int | value
| ) |  |

Set a value from a int.

Definition at line 113 of file Dictionary.cpp.

{
m_data[ string_strip(string_toUpper(key)) ] = IntConvertor::convert( value );
}

References FIX::IntConvertor::convert(), m_data, FIX::string_strip(), and FIX::string_toUpper().

## setString()

void FIX::Dictionary::setString | ( | const std::string & | key,
|  | const std::string & | value
| ) |  |

Set a value from a string.

Definition at line 108 of file Dictionary.cpp.

{
m_data[ string_strip(string_toUpper(key)) ] = string_strip(value);
}

References m_data, FIX::string_strip(), and FIX::string_toUpper().

Referenced by setDay().

## size()

size_t FIX::Dictionary::size | ( |  | ) | const

inline

Return the number of key/value pairs.

Definition at line 50 of file Dictionary.h.

{ return m_data.size(); }

References m_data.

## Member Data Documentation

## m_data

Data FIX::Dictionary::m_data

private

Definition at line 88 of file Dictionary.h.

Referenced by begin(), end(), has(), merge(), setBool(), setDouble(), setInt(), setString(), and size().

## m_name

std::string FIX::Dictionary::m_name

private

Definition at line 89 of file Dictionary.h.

Referenced by getName().

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

- Dictionary.h
- Dictionary.cpp