fix8  version 1.4.0
Open Source C++ FIX Framework
FIX8::SessionManager< T > Class Template Reference

Session Manager. More...

#include <multisession.hpp>

Public Member Functions

 SessionManager ()=default
 Ctor. More...
 
virtual ~SessionManager ()
 Dtor. More...
 
bool add (const f8String &name, T *what)
 
T * for_each_if (std::function< bool(T *)> func)
 
bool remove (const f8String &name)
 
T * find (const f8String &name)
 
T * operator[] (const f8String &name) const
 
unsigned size () const
 

Private Attributes

f8_mutex _mutex
 
std::map< f8String, T * > _sessionmap
 

Detailed Description

template<typename T>
class FIX8::SessionManager< T >

Session Manager.

Definition at line 106 of file multisession.hpp.

Constructor & Destructor Documentation

template<typename T >
FIX8::SessionManager< T >::SessionManager ( )
default

Ctor.

template<typename T >
virtual FIX8::SessionManager< T >::~SessionManager ( )
inlinevirtual

Dtor.

Definition at line 116 of file multisession.hpp.

117  {
118  f8_scoped_lock guard(_mutex);
119  std::for_each (_sessionmap.begin(), _sessionmap.end(), [](typename decltype(_sessionmap)::value_type& pp){ delete pp.second; });
120  }
f8_scoped_lock_impl< f8_mutex > f8_scoped_lock
Definition: thread.hpp:451
std::map< f8String, T * > _sessionmap

Member Function Documentation

template<typename T >
bool FIX8::SessionManager< T >::add ( const f8String name,
T *  what 
)
inline

Add a T* to the manager; takes ownership of the object

Parameters
nameunique name for this session
whatT* to add
Returns
true if successful

Definition at line 126 of file multisession.hpp.

Referenced by main().

127  {
128  if (!what)
129  throw f8Exception("bad or missing session");
130  f8_scoped_lock guard(_mutex);
131  return _sessionmap.insert({name, what}).second;
132  }
f8_scoped_lock_impl< f8_mutex > f8_scoped_lock
Definition: thread.hpp:451
std::map< f8String, T * > _sessionmap
template<typename T >
T* FIX8::SessionManager< T >::find ( const f8String name)
inline

Find a session by session name

Parameters
namesession name
Returns
T* or nullptr if not found

Definition at line 165 of file multisession.hpp.

Referenced by FIX8::SessionManager< T >::operator[]().

166  {
167  f8_scoped_lock guard(_mutex);
168  const auto itr(_sessionmap.find(name));
169  return itr == _sessionmap.cend() ? nullptr : itr->second;
170  }
f8_scoped_lock_impl< f8_mutex > f8_scoped_lock
Definition: thread.hpp:451
std::map< f8String, T * > _sessionmap
template<typename T >
T* FIX8::SessionManager< T >::for_each_if ( std::function< bool(T *)>  func)
inline

Call supplied function on each T* in the manager

Parameters
funcstd::function to call, which returns true on success
Returns
nullptr if all sessions executed successfully, or ptr to session that failed

Definition at line 137 of file multisession.hpp.

Referenced by main().

138  {
139  for (auto& pp : _sessionmap)
140  {
141  f8_scoped_lock guard(_mutex);
142  if (!func(pp.second))
143  return pp.second;
144  }
145  return nullptr;
146  }
f8_scoped_lock_impl< f8_mutex > f8_scoped_lock
Definition: thread.hpp:451
std::map< f8String, T * > _sessionmap
template<typename T >
T* FIX8::SessionManager< T >::operator[] ( const f8String name) const
inline

Find a session by session name, subscript operator version

Parameters
namesession name
Returns
T* or nullptr if not found

Definition at line 175 of file multisession.hpp.

References FIX8::SessionManager< T >::find().

175 { return find(name); }
T * find(const f8String &name)
template<typename T >
bool FIX8::SessionManager< T >::remove ( const f8String name)
inline

Remove a T* from the manager; destroys the object

Parameters
namesession name
Returns
true if successful

Definition at line 151 of file multisession.hpp.

152  {
153  f8_scoped_lock guard(_mutex);
154  auto itr(_sessionmap.find(name));
155  if (itr == _sessionmap.end())
156  return false;
157  delete itr->second;
158  _sessionmap.erase(itr);
159  return true;
160  }
f8_scoped_lock_impl< f8_mutex > f8_scoped_lock
Definition: thread.hpp:451
std::map< f8String, T * > _sessionmap
template<typename T >
unsigned FIX8::SessionManager< T >::size ( ) const
inline

Get the number of sessions being manager by this object

Returns
count of sessions

Definition at line 179 of file multisession.hpp.

179 { return static_cast<unsigned>(_sessionmap.size()); }
std::map< f8String, T * > _sessionmap

Member Data Documentation

template<typename T >
f8_mutex FIX8::SessionManager< T >::_mutex
private

Definition at line 108 of file multisession.hpp.

template<typename T >
std::map<f8String, T*> FIX8::SessionManager< T >::_sessionmap
private

Definition at line 109 of file multisession.hpp.


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