Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
FIX::SessionSettings Class Reference

Container for setting dictionaries mapped to sessions. More...

#include <SessionSettings.h>

Collaboration diagram for FIX::SessionSettings:
Collaboration graph
[legend]

Public Types

typedef std::map< SessionID,
Dictionary
Dictionaries
 

Public Member Functions

 SessionSettings ()
 
 SessionSettings (std::istream &stream) throw ( ConfigError )
 
 SessionSettings (const std::string &file) throw ( ConfigError )
 
const bool has (const SessionID &) const
 Check if session setings are present. More...
 
const Dictionaryget (const SessionID &) const throw ( ConfigError )
 Get a dictionary for a session. More...
 
void set (const SessionID &, Dictionary) throw ( ConfigError )
 Set a dictionary for a session. More...
 
const Dictionaryget () const
 Get global default settings. More...
 
void set (const Dictionary &defaults) throw ( ConfigError )
 Set global default settings. More...
 
int size () const
 Number of session settings. More...
 
std::set< SessionIDgetSessions () const
 

Private Member Functions

void validate (const Dictionary &) const throw ( ConfigError )
 

Private Attributes

Dictionaries m_settings
 
Dictionary m_defaults
 

Friends

std::ostream & operator<< (std::ostream &, const SessionSettings &)
 

Detailed Description

Container for setting dictionaries mapped to sessions.

Definition at line 130 of file SessionSettings.h.

Member Typedef Documentation

Definition at line 153 of file SessionSettings.h.

Constructor & Destructor Documentation

FIX::SessionSettings::SessionSettings ( )
inline

Definition at line 133 of file SessionSettings.h.

133 {}
FIX::SessionSettings::SessionSettings ( std::istream &  stream)
throw (ConfigError
)

Definition at line 33 of file SessionSettings.cpp.

35 {
36  stream >> *this;
37 }
FIX::SessionSettings::SessionSettings ( const std::string &  file)
throw (ConfigError
)

Definition at line 39 of file SessionSettings.cpp.

41 {
42  std::ifstream fstream( file.c_str() );
43  if ( !fstream.is_open() )
44  throw ConfigError( ( "File " + file + " not found" ).c_str() );
45  fstream >> *this;
46 }

Member Function Documentation

const Dictionary & FIX::SessionSettings::get ( const SessionID sessionID) const
throw (ConfigError
)

Get a dictionary for a session.

Definition at line 125 of file SessionSettings.cpp.

Referenced by FIX::Initiator::connect(), FIX::FileStoreFactory::create(), FIX::FileLogFactory::create(), FIX::ScreenLogFactory::create(), FIX::Initiator::getSessionSettings(), FIX::Acceptor::getSessionSettings(), FIX::Acceptor::initialize(), FIX::Initiator::initialize(), and FIX::operator<<().

127 {
128  Dictionaries::const_iterator i;
129  i = m_settings.find( sessionID );
130  if ( i == m_settings.end() ) throw ConfigError( "Session not found" );
131  return i->second;
132 }
const Dictionary& FIX::SessionSettings::get ( ) const
inline

Get global default settings.

Definition at line 146 of file SessionSettings.h.

References m_defaults.

146 { return m_defaults; }
std::set< SessionID > FIX::SessionSettings::getSessions ( ) const

Definition at line 158 of file SessionSettings.cpp.

References m_settings.

Referenced by FIX::Acceptor::initialize(), FIX::Initiator::initialize(), and FIX::operator<<().

159 {
160  std::set < SessionID > result;
161  Dictionaries::const_iterator i;
162  for ( i = m_settings.begin(); i != m_settings.end(); ++i )
163  result.insert( i->first );
164  return result;
165 }
const bool FIX::SessionSettings::has ( const SessionID sessionID) const

Check if session setings are present.

Definition at line 120 of file SessionSettings.cpp.

References m_settings.

Referenced by FIX::ScreenLogFactory::create().

121 {
122  return m_settings.find( sessionID ) != m_settings.end();
123 }
void FIX::SessionSettings::set ( const SessionID sessionID,
Dictionary  settings 
)
throw (ConfigError
)

Set a dictionary for a session.

Definition at line 134 of file SessionSettings.cpp.

References FIX::BEGINSTRING, FIX::SENDERCOMPID, and FIX::TARGETCOMPID.

137 {
138  if( has(sessionID) )
139  throw ConfigError( "Duplicate Session " + sessionID.toString() );
140 
141  settings.setString( BEGINSTRING, sessionID.getBeginString() );
142  settings.setString( SENDERCOMPID, sessionID.getSenderCompID() );
143  settings.setString( TARGETCOMPID, sessionID.getTargetCompID() );
144 
145  settings.merge( m_defaults );
146  validate( settings );
147  m_settings[ sessionID ] = settings;
148 }
const char BEGINSTRING[]
const char TARGETCOMPID[]
const bool has(const SessionID &) const
Check if session setings are present.
const char SENDERCOMPID[]
void validate(const Dictionary &) const
void FIX::SessionSettings::set ( const Dictionary defaults)
throw (ConfigError
)

Set global default settings.

Definition at line 150 of file SessionSettings.cpp.

151 {
152  m_defaults = defaults;
153  Dictionaries::iterator i = m_settings.begin();
154  for( i = m_settings.begin(); i != m_settings.end(); ++i )
155  i->second.merge( defaults );
156 }
int FIX::SessionSettings::size ( ) const
inline

Number of session settings.

Definition at line 151 of file SessionSettings.h.

References m_settings.

151 { return m_settings.size(); }
void FIX::SessionSettings::validate ( const Dictionary dictionary) const
throw (ConfigError
)
private

Definition at line 167 of file SessionSettings.cpp.

References FIX::BEGINSTRING, FIX::BeginString_FIX40, FIX::BeginString_FIX41, FIX::BeginString_FIX42, FIX::BeginString_FIX43, FIX::BeginString_FIX44, FIX::BeginString_FIXT11, and FIX::CONNECTION_TYPE.

169 {
170  std::string beginString = dictionary.getString( BEGINSTRING );
171  if( beginString != BeginString_FIX40 &&
172  beginString != BeginString_FIX41 &&
173  beginString != BeginString_FIX42 &&
174  beginString != BeginString_FIX43 &&
175  beginString != BeginString_FIX44 &&
176  beginString != BeginString_FIXT11 )
177  {
178  throw ConfigError( std::string(BEGINSTRING) + " must be FIX.4.0 to FIX.4.4 or FIXT.1.1" );
179  }
180 
181  std::string connectionType = dictionary.getString( CONNECTION_TYPE );
182  if( connectionType != "initiator" &&
183  connectionType != "acceptor" )
184  {
185  throw ConfigError( std::string(CONNECTION_TYPE) + " must be 'initiator' or 'acceptor'" );
186  }
187 }
const char BeginString_FIX44[]
Definition: Values.h:32
const char CONNECTION_TYPE[]
const char BeginString_FIX42[]
Definition: Values.h:34
const char BeginString_FIXT11[]
Definition: Values.h:30
const char BEGINSTRING[]
const char BeginString_FIX43[]
Definition: Values.h:33
const char BeginString_FIX41[]
Definition: Values.h:35
const char BeginString_FIX40[]
Definition: Values.h:36

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  ,
const SessionSettings  
)
friend

Definition at line 87 of file SessionSettings.cpp.

88 {
89  const Dictionary& defaults = s.m_defaults;
90  if( defaults.size() )
91  {
92  stream << "[DEFAULT]" << std::endl;
94  for( i = defaults.begin(); i != defaults.end(); ++i )
95  stream << i->first << "=" << i->second << std::endl;
96  stream << std::endl;
97  }
98 
99  std::set<SessionID> sessions = s.getSessions();
100  std::set<SessionID>::iterator i;
101  for( i = sessions.begin(); i != sessions.end(); ++i )
102  {
103  stream << "[SESSION]" << std::endl;
104  const Dictionary& section = s.get( *i );
105  if( !section.size() ) continue;
106 
108  for( i = section.begin(); i != section.end(); ++i )
109  {
110  if( defaults.has(i->first) && defaults.getString(i->first) == i->second )
111  continue;
112  stream << i->first << "=" << i->second << std::endl;
113  }
114  stream << std::endl;
115  }
116 
117  return stream;
118 }
Data::const_iterator iterator
Definition: Dictionary.h:44

Member Data Documentation

Dictionary FIX::SessionSettings::m_defaults
private

Definition at line 160 of file SessionSettings.h.

Referenced by get(), and FIX::operator<<().

Dictionaries FIX::SessionSettings::m_settings
private

Definition at line 159 of file SessionSettings.h.

Referenced by getSessions(), has(), and size().


The documentation for this class was generated from the following files:

Generated on Sat Mar 29 2014 15:13:35 for QuickFIX by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2001