Public Types | Public Member Functions | Private Attributes | List of all members
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. More...
 
int size () const
 Return the number of key/value pairs. More...
 
std::string getString (const std::string &, bool capitalize=false) const throw ( ConfigError, FieldConvertError )
 Get a value as a string. More...
 
int getInt (const std::string &) const throw ( ConfigError, FieldConvertError )
 Get a value as a int. More...
 
double getDouble (const std::string &) const throw ( ConfigError, FieldConvertError )
 Get a value as a double. More...
 
bool getBool (const std::string &) const throw ( ConfigError, FieldConvertError )
 Get a value as a bool. More...
 
int getDay (const std::string &) const throw ( ConfigError, FieldConvertError )
 Get a value as a day of week. More...
 
void setString (const std::string &, const std::string &)
 Set a value from a string. More...
 
void setInt (const std::string &, int)
 Set a value from a int. More...
 
void setDouble (const std::string &, double)
 Set a value from a double. More...
 
void setBool (const std::string &, bool)
 Set a value from a bool. More...
 
void setDay (const std::string &, int)
 Set a value from a day. More...
 
bool has (const std::string &) const
 Check if the dictionary contains a value for key. More...
 
void merge (const Dictionary &)
 Merge two dictionaries. More...
 
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.

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

Definition at line 40 of file Dictionary.h.

40 {}
virtual FIX::Dictionary::~Dictionary ( )
inlinevirtual

Definition at line 41 of file Dictionary.h.

41 {}

Member Function Documentation

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

Definition at line 84 of file Dictionary.h.

References m_data.

Referenced by FIX::operator<<().

84 { 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<<().

85 { return m_data.end(); }
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.

References FIX::BoolConvertor::convert().

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

73 {
74  try
75  {
76  return BoolConvertor::convert( getString(key) );
77  }
78  catch ( FieldConvertError& )
79  {
80  throw ConfigError( "Illegal value " + getString(key) + " for " + key );
81  }
82 }
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:32
static std::string convert(bool value)
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.

86 {
87  try
88  {
89  std::string value = getString(key);
90  if( value.size() < 2 ) throw FieldConvertError(0);
91  std::string abbr = value.substr(0, 2);
92  std::transform( abbr.begin(), abbr.end(), abbr.begin(), tolower );
93  if( abbr == "su" ) return 1;
94  if( abbr == "mo" ) return 2;
95  if( abbr == "tu" ) return 3;
96  if( abbr == "we" ) return 4;
97  if( abbr == "th" ) return 5;
98  if( abbr == "fr" ) return 6;
99  if( abbr == "sa" ) return 7;
100  if( value.size() < 2 ) throw FieldConvertError(0);
101  }
102  catch ( FieldConvertError& )
103  {
104  throw ConfigError( "Illegal value " + getString(key) + " for " + key );
105  }
106  return -1;
107 }
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:32
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().

60 {
61  try
62  {
63  return DoubleConvertor::convert( getString(key) );
64  }
65  catch ( FieldConvertError& )
66  {
67  throw ConfigError( "Illegal value " + getString(key) + " for " + key );
68  }
69 }
static std::string convert(double value, int padding=0)
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:32
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.

References FIX::IntConvertor::convert().

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

47 {
48  try
49  {
50  return IntConvertor::convert( getString(key) );
51  }
52  catch ( FieldConvertError& )
53  {
54  throw ConfigError( "Illegal value " + getString(key) + " for " + key );
55  }
56 }
static std::string convert(signed_int value)
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:32
std::string FIX::Dictionary::getName ( ) const
inline

Get the name of the dictionary.

Definition at line 48 of file Dictionary.h.

References m_name.

48 { return m_name; }
std::string m_name
Definition: Dictionary.h:89
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>>().

34 {
35  Data::const_iterator i = m_data.find( string_toUpper(key) );
36  if ( i == m_data.end() ) throw ConfigError( key + " not defined" );
37 
38  std::string result = i->second;
39  if( capitalize )
40  std::transform(result.begin(), result.end(), result.begin(), toupper);
41 
42  return result;
43 }
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
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>>().

156 {
157  Data::const_iterator i = toMerge.m_data.begin();
158  for ( ; i != toMerge.m_data.end(); ++i )
159  if ( m_data.find( i->first ) == m_data.end() )
160  m_data[ i->first ] = i->second;
161 }
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().

125 {
127 }
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
std::string string_strip(const std::string &value)
Definition: Utility.cpp:67
static std::string convert(bool value)
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().

130 {
131  switch( value )
132  {
133  case 1:
134  setString( key, "SU" ); break;
135  case 2:
136  setString( key, "MO" ); break;
137  case 3:
138  setString( key, "TU" ); break;
139  case 4:
140  setString( key, "WE" ); break;
141  case 5:
142  setString( key, "TH" ); break;
143  case 6:
144  setString( key, "FR" ); break;
145  case 7:
146  setString( key, "SA" ); break;
147  }
148 }
void setString(const std::string &, const std::string &)
Set a value from a string.
Definition: Dictionary.cpp:109
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().

120 {
122 }
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
static std::string convert(double value, int padding=0)
std::string string_strip(const std::string &value)
Definition: Utility.cpp:67
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().

115 {
117 }
static std::string convert(signed_int value)
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
std::string string_strip(const std::string &value)
Definition: Utility.cpp:67
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().

110 {
112 }
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
std::string string_strip(const std::string &value)
Definition: Utility.cpp:67
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<<().

50 { return m_data.size(); }

Member Data Documentation

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

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 Sat Mar 29 2014 15:13:33 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001