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

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

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

◆ Dictionary() [2/2]

FIX::Dictionary::Dictionary ( )
inline

Definition at line 40 of file Dictionary.h.

40 {}

◆ ~Dictionary()

virtual FIX::Dictionary::~Dictionary ( )
inlinevirtual

Definition at line 41 of file Dictionary.h.

41 {}

Member Function Documentation

◆ begin()

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(); }

◆ end()

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(); }

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

References FIX::BoolConvertor::convert().

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

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 }
static std::string convert(bool value)
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:32

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

Referenced by size().

86 {
87  try
88  {
89  std::string value = getString(key);
90  if( value.size() < 2 ) throw FieldConvertError();
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  }
101  catch ( FieldConvertError& )
102  {
103  throw ConfigError( "Illegal value " + getString(key) + " for " + key );
104  }
105  return -1;
106 }
std::string getString(const std::string &, bool capitalize=false) const
Get a value as a string.
Definition: Dictionary.cpp:32

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

References FIX::DoubleConvertor::convert().

Referenced by size().

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

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

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(), FIX::ThreadedSocketAcceptor::onInitialize(), and size().

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

◆ getName()

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

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

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<<(), FIX::operator>>(), and size().

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

◆ has()

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

◆ merge()

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

Merge two dictionaries.

Definition at line 154 of file Dictionary.cpp.

References m_data.

Referenced by FIX::operator>>(), and size().

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

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

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

Referenced by size().

124 {
126 }
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)

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

References setString().

Referenced by size().

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

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

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

Referenced by size().

119 {
121 }
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

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

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

Referenced by size().

114 {
116 }
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

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

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

Referenced by setDay(), and size().

109 {
111 }
std::string string_toUpper(const std::string &value)
Definition: Utility.cpp:53
std::string string_strip(const std::string &value)
Definition: Utility.cpp:67

◆ size()

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

Return the number of key/value pairs.

Definition at line 50 of file Dictionary.h.

References getBool(), getDay(), getDouble(), getInt(), getString(), has(), m_data, merge(), setBool(), setDay(), setDouble(), setInt(), and setString().

Referenced by FIX::operator<<().

50 { return m_data.size(); }

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:

Generated on Sun Apr 15 2018 21:44:05 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001