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

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.

84{ return m_data.begin(); }

References m_data.

◆ end()

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

Definition at line 85 of file Dictionary.h.

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

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.
static std::string convert(bool value)

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.

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}

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

60{
61 try
62 {
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)

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.

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)

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.

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

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

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

◆ merge()

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

Merge two dictionaries.

Definition at line 154 of file Dictionary.cpp.

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}

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.

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

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.

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.

119{
121}

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.

114{
116}

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.

109{
111}

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.

50{ 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:

Generated on Sat Feb 3 2024 04:23:15 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001