Public Types | Public Member Functions | Private Attributes
FIX::Dictionary Class Reference

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

#include <Dictionary.h>

List of all members.

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.
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

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.


Constructor & Destructor Documentation

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

Definition at line 39 of file Dictionary.h.

: m_name( name ) {}

Definition at line 40 of file Dictionary.h.

{}
virtual FIX::Dictionary::~Dictionary ( ) [inline, virtual]

Definition at line 41 of file Dictionary.h.

{}

Member Function Documentation

iterator FIX::Dictionary::begin ( ) const [inline]

Definition at line 84 of file Dictionary.h.

References m_data.

Referenced by FIX::operator<<().

{ return m_data.begin(); }
iterator FIX::Dictionary::end ( ) const [inline]

Definition at line 85 of file Dictionary.h.

References m_data.

Referenced by FIX::operator<<().

{ return m_data.end(); }
bool FIX::Dictionary::getBool ( const std::string &  key) const throw ( ConfigError, FieldConvertError )
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(0);
    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;
    if( value.size() < 2 ) throw FieldConvertError(0);
  }
  catch ( FieldConvertError& )
  {
    throw ConfigError( "Illegal value " + getString(key) + " for " + key );
  }
  return -1;
}
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.

References FIX::DoubleConvertor::convert().

{
  try
  {
    return DoubleConvertor::convert( getString(key) );
  }
  catch ( FieldConvertError& )
  {
    throw ConfigError( "Illegal value " + getString(key) + " for " + key );
  }
}
int FIX::Dictionary::getInt ( const std::string &  key) const throw ( ConfigError, FieldConvertError )
std::string FIX::Dictionary::getName ( ) const [inline]

Get the name of the dictionary.

Definition at line 48 of file Dictionary.h.

References m_name.

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

References FIX::string_toUpper().

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

{
  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;
}
bool FIX::Dictionary::has ( const std::string &  key) const
void FIX::Dictionary::merge ( const Dictionary toMerge)

Merge two dictionaries.

Definition at line 155 of file Dictionary.cpp.

References m_data.

Referenced by FIX::operator>>().

{
  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;
}
void FIX::Dictionary::setBool ( const std::string &  key,
bool  value 
)

Set a value from a bool.

Definition at line 124 of file Dictionary.cpp.

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

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

Set a value from a day.

Definition at line 129 of file Dictionary.cpp.

References setString().

{  
    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;
    }
}
void FIX::Dictionary::setDouble ( const std::string &  key,
double  value 
)

Set a value from a double.

Definition at line 119 of file Dictionary.cpp.

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

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

Set a value from a int.

Definition at line 114 of file Dictionary.cpp.

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

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

Set a value from a string.

Definition at line 109 of file Dictionary.cpp.

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

Referenced by setDay().

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

Return the number of key/value pairs.

Definition at line 50 of file Dictionary.h.

References m_data.

Referenced by FIX::operator<<().

{ return m_data.size(); }

Member Data Documentation

Definition at line 88 of file Dictionary.h.

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

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:

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001