Index  Source Files  Annotated Class List  Alphabetical Class List  Class Hierarchy  Graphical Class Hierarchy   
 

FIX::Dictionary Class Reference

For storage and retrieval of key/value pairs. More...

#include <Dictionary.h>

List of all members.

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 &, const long &)
 Set a value from a long.

void setDouble (const std::string &, const double &)
 Set a value from a double.

void setBool (const std::string &, const bool &)
 Set a value from a bool.

void setDay (const std::string &, const 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.


Private Types

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

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

typedef std::map< std::string, std::string > FIX::Dictionary::Data [private]
 

Definition at line 81 of file Dictionary.h.


Constructor & Destructor Documentation

FIX::Dictionary::Dictionary const std::string &  name  )  [inline]
 

Definition at line 39 of file Dictionary.h.

References m_name.

00039 : m_name( name ) {}

FIX::Dictionary::Dictionary  )  [inline]
 

Definition at line 40 of file Dictionary.h.

00040 {}

virtual FIX::Dictionary::~Dictionary  )  [inline, virtual]
 

Definition at line 41 of file Dictionary.h.

00041 {}


Member Function Documentation

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

Get a value as a bool.

Definition at line 87 of file Dictionary.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

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

00089 { QF_STACK_PUSH(Dictionary::getBool)
00090 
00091   Data::const_iterator i = m_data.find( key );
00092   if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
00093   try
00094   {
00095     return BoolConvertor::convert( i->second );
00096   }
00097   catch ( FieldConvertError& )
00098   {
00099     throw ConfigError( "Illegal value " + i->second + " for " + key );
00100   }
00101 
00102   QF_STACK_POP
00103 }

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

Get a value as a day of week.

Definition at line 105 of file Dictionary.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

00107 { QF_STACK_PUSH(Dictionary::getDay)
00108 
00109   Data::const_iterator i = m_data.find( key );
00110   if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
00111   try
00112   {
00113     std::string value = i->second;
00114     if( value.size() < 2 ) throw FieldConvertError(0);
00115     std::string abbr = value.substr(0, 2);
00116     std::transform( abbr.begin(), abbr.end(), abbr.begin(), tolower );
00117     if( abbr == "su" ) return 1;
00118     if( abbr == "mo" ) return 2;
00119     if( abbr == "tu" ) return 3;
00120     if( abbr == "we" ) return 4;
00121     if( abbr == "th" ) return 5;
00122     if( abbr == "fr" ) return 6;
00123     if( abbr == "sa" ) return 7;
00124     if( value.size() < 2 ) throw FieldConvertError(0);
00125   }
00126   catch ( FieldConvertError& )
00127   {
00128     throw ConfigError( "Illegal value " + i->second + " for " + key );
00129   }
00130   return -1;
00131 
00132   QF_STACK_POP
00133 }

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

Get a value as a double.

Definition at line 69 of file Dictionary.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

00071 { QF_STACK_PUSH(Dictionary::getDouble)
00072 
00073   Data::const_iterator i = m_data.find( key );
00074   if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
00075   try
00076   {
00077     return DoubleConvertor::convert( i->second );
00078   }
00079   catch ( FieldConvertError& )
00080   {
00081     throw ConfigError( "Illegal value " + i->second + " for " + key );
00082   }
00083 
00084   QF_STACK_POP
00085 }

long FIX::Dictionary::getLong const std::string &   )  const throw ( ConfigError, FieldConvertError )
 

Get a value as a long.

Definition at line 51 of file Dictionary.cpp.

References QF_STACK_POP, and QF_STACK_PUSH.

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

00053 { QF_STACK_PUSH(Dictionary::getLong)
00054 
00055   Data::const_iterator i = m_data.find( key );
00056   if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
00057   try
00058   {
00059     return IntConvertor::convert( i->second );
00060   }
00061   catch ( FieldConvertError& )
00062   {
00063     throw ConfigError( "Illegal value " + i->second + " for " + key );
00064   }
00065 
00066   QF_STACK_POP
00067 }

std::string FIX::Dictionary::getName  )  const [inline]
 

Get the name of the dictionary.

Definition at line 44 of file Dictionary.h.

References m_name.

00044 { return m_name; }

std::string FIX::Dictionary::getString const std::string &  ,
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, and QF_STACK_PUSH.

Referenced by FIX::FileStoreFactory::create(), FIX::FileLogFactory::create(), FIX::ThreadedSocketInitiator::getHost(), FIX::SocketInitiator::getHost(), and FIX::operator>>().

00035 { QF_STACK_PUSH(Dictionary::getString)
00036 
00037   Data::const_iterator i = m_data.find( key );
00038   if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
00039 
00040   std::string result = i->second;
00041   if( capitalize )
00042   {
00043     for( std::string::size_type i = 0; i <= result.size(); ++i )
00044       result[i] = toupper(result[i]);
00045   }
00046   return result;
00047 
00048   QF_STACK_POP
00049 }

bool FIX::Dictionary::has const std::string &   )  const
 

Check if the dictionary contains a value for key.

Definition at line 183 of file Dictionary.cpp.

References m_data, QF_STACK_POP, and QF_STACK_PUSH.

Referenced by FIX::ScreenLogFactory::init(), FIX::ThreadedSocketAcceptor::onConfigure(), FIX::SocketAcceptor::onConfigure(), FIX::ThreadedSocketAcceptor::onInitialize(), FIX::SocketAcceptor::onInitialize(), and FIX::operator>>().

00184 { QF_STACK_PUSH(Dictionary::has)
00185   return m_data.find( key ) != m_data.end();
00186   QF_STACK_POP
00187 }

void FIX::Dictionary::merge const Dictionary  ) 
 

Merge two dictionaries.

Definition at line 189 of file Dictionary.cpp.

References m_data, QF_STACK_POP, and QF_STACK_PUSH.

Referenced by FIX::operator>>().

00190 { QF_STACK_PUSH(Dictionary::merge)
00191 
00192   Data::const_iterator i = toMerge.m_data.begin();
00193   for ( ; i != toMerge.m_data.end(); ++i )
00194     if ( m_data.find( i->first ) == m_data.end() )
00195       m_data[ i->first ] = i->second;
00196 
00197   QF_STACK_POP
00198 }

void FIX::Dictionary::setBool const std::string &  ,
const bool & 
 

Set a value from a bool.

Definition at line 153 of file Dictionary.cpp.

References m_data, QF_STACK_POP, and QF_STACK_PUSH.

00154 { QF_STACK_PUSH(Dictionary::setBool)
00155   m_data[ key ] = BoolConvertor::convert( value );
00156   QF_STACK_POP
00157 }

void FIX::Dictionary::setDay const std::string &  ,
const int & 
 

Set a value from a day.

Definition at line 159 of file Dictionary.cpp.

References QF_STACK_POP, QF_STACK_PUSH, and setString().

00160 { QF_STACK_PUSH(Dictionary::setDay)
00161   
00162     switch( value )
00163     {
00164     case 1:
00165       setString( key, "SU" ); break;
00166     case 2:
00167       setString( key, "MO" ); break;
00168     case 3:
00169       setString( key, "TU" ); break;
00170     case 4:
00171       setString( key, "WE" ); break;
00172     case 5:
00173       setString( key, "TH" ); break;
00174     case 6:
00175       setString( key, "FR" ); break;
00176     case 7:
00177       setString( key, "SA" ); break;
00178     }
00179 
00180   QF_STACK_POP
00181 }

void FIX::Dictionary::setDouble const std::string &  ,
const double & 
 

Set a value from a double.

Definition at line 147 of file Dictionary.cpp.

References m_data, QF_STACK_POP, and QF_STACK_PUSH.

00148 { QF_STACK_PUSH(Dictionary::setDouble)
00149   m_data[ key ] = DoubleConvertor::convert( value );
00150   QF_STACK_POP
00151 }

void FIX::Dictionary::setLong const std::string &  ,
const long & 
 

Set a value from a long.

Definition at line 141 of file Dictionary.cpp.

References m_data, QF_STACK_POP, and QF_STACK_PUSH.

00142 { QF_STACK_PUSH(Dictionary::setString)
00143   m_data[ key ] = IntConvertor::convert( value );
00144   QF_STACK_POP
00145 }

void FIX::Dictionary::setString const std::string &  ,
const std::string & 
 

Set a value from a string.

Definition at line 135 of file Dictionary.cpp.

References m_data, QF_STACK_POP, and QF_STACK_PUSH.

Referenced by setDay().

00136 { QF_STACK_PUSH(Dictionary::setString)
00137   m_data[ key ] = value;
00138   QF_STACK_POP
00139 }

int FIX::Dictionary::size  )  const [inline]
 

Return the number of key/value pairs.

Definition at line 46 of file Dictionary.h.

References m_data.

00046 { return m_data.size(); }


Member Data Documentation

Data FIX::Dictionary::m_data [private]
 

Definition at line 82 of file Dictionary.h.

Referenced by has(), merge(), setBool(), setDouble(), setLong(), setString(), and size().

std::string FIX::Dictionary::m_name [private]
 

Definition at line 83 of file Dictionary.h.

Referenced by Dictionary(), and getName().


The documentation for this class was generated from the following files:
Generated on Mon Jul 24 19:36:36 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001