SessionID.h
Go to the documentation of this file.
/* -*- C++ -*- */
/****************************************************************************
** Copyright (c) 2001-2014
**
** This file is part of the QuickFIX FIX Engine
**
** This file may be distributed under the terms of the quickfixengine.org
** license as defined by quickfixengine.org and appearing in the file
** LICENSE included in the packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.quickfixengine.org/LICENSE for licensing information.
**
** Contact ask@quickfixengine.org if any conditions of this licensing are
** not clear to you.
**
****************************************************************************/
#ifndef FIX_SESSIONID_H
#define FIX_SESSIONID_H
#include "Fields.h"
namespace FIX
{
class SessionID
{
public:
SessionID()
{
toString(m_frozenString);
}
SessionID( const std::string& beginString,
const std::string& senderCompID,
const std::string& targetCompID,
const std::string& sessionQualifier = "" )
: m_beginString( BeginString(beginString) ),
m_senderCompID( SenderCompID(senderCompID) ),
m_targetCompID( TargetCompID(targetCompID) ),
m_sessionQualifier( sessionQualifier ),
m_isFIXT(false)
{
toString(m_frozenString);
if( beginString.substr(0, 4) == "FIXT" )
m_isFIXT = true;
}
const BeginString& getBeginString() const
{ return m_beginString; }
const SenderCompID& getSenderCompID() const
{ return m_senderCompID; }
const TargetCompID& getTargetCompID() const
{ return m_targetCompID; }
const std::string& getSessionQualifier() const
{ return m_sessionQualifier; }
const bool isFIXT() const
{ return m_isFIXT; }
std::string toString() const
{
return m_frozenString;
}
// Return a reference for a high-performance scenario
const std::string& toStringFrozen() const
{
return m_frozenString;
}
void fromString( const std::string& str )
{
std::string::size_type first =
str.find_first_of(':');
std::string::size_type second =
str.find("->");
std::string::size_type third =
str.find_last_of(':');
if( first == std::string::npos )
return;
if( second == std::string::npos )
return;
m_beginString = str.substr(0, first);
m_senderCompID = str.substr(first+1, second - first - 1);
if( first == third )
{
m_targetCompID = str.substr(second+2);
m_sessionQualifier = "";
}
else
{
m_targetCompID = str.substr(second+2, third - second - 2);
m_sessionQualifier = str.substr(third+1);
}
toString(m_frozenString);
}
std::string& toString( std::string& str ) const
{
str = getBeginString().getValue() + ":" +
getSenderCompID().getValue() + "->" +
getTargetCompID().getValue();
if( m_sessionQualifier.size() )
str += ":" + m_sessionQualifier;
return str;
}
friend bool operator<( const SessionID&, const SessionID& );
friend bool operator==( const SessionID&, const SessionID& );
friend bool operator!=( const SessionID&, const SessionID& );
friend std::ostream& operator<<( std::ostream&, const SessionID& );
friend std::ostream& operator>>( std::ostream&, const SessionID& );
SessionID operator~() const
{
return SessionID( m_beginString, SenderCompID( m_targetCompID ),
TargetCompID( m_senderCompID ), m_sessionQualifier );
}
private:
BeginString m_beginString;
SenderCompID m_senderCompID;
TargetCompID m_targetCompID;
std::string m_sessionQualifier;
bool m_isFIXT;
std::string m_frozenString;
};
inline bool operator<( const SessionID& lhs, const SessionID& rhs )
{
return lhs.toStringFrozen() < rhs.toStringFrozen();
}
inline bool operator==( const SessionID& lhs, const SessionID& rhs )
{
return lhs.toStringFrozen() == rhs.toStringFrozen();
}
inline bool operator!=( const SessionID& lhs, const SessionID& rhs )
{
return !( lhs == rhs );
}
inline std::ostream& operator<<
( std::ostream& stream, const SessionID& sessionID )
{
stream << sessionID.toStringFrozen();
return stream;
}
inline std::istream& operator>>
( std::istream& stream, SessionID& sessionID )
{
std::string str;
stream >> str;
sessionID.fromString( str );
return stream;
}
}
#endif //FIX_SESSIONID_H
Fields.h
FIX::SessionID
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition SessionID.h:31
FIX::SessionID::m_frozenString
std::string m_frozenString
Definition SessionID.h:133
FIX::SessionID::getSenderCompID
const SenderCompID & getSenderCompID() const
Definition SessionID.h:55
FIX::SessionID::SessionID
SessionID(const std::string &beginString, const std::string &senderCompID, const std::string &targetCompID, const std::string &sessionQualifier="")
Definition SessionID.h:38
FIX::SessionID::m_beginString
BeginString m_beginString
Definition SessionID.h:128
FIX::SessionID::m_senderCompID
SenderCompID m_senderCompID
Definition SessionID.h:129
FIX::SessionID::getSessionQualifier
const std::string & getSessionQualifier() const
Definition SessionID.h:59
FIX::SessionID::m_targetCompID
TargetCompID m_targetCompID
Definition SessionID.h:130
FIX::SessionID::operator<
friend bool operator<(const SessionID &, const SessionID &)
Definition SessionID.h:137
FIX::SessionID::m_isFIXT
bool m_isFIXT
Definition SessionID.h:132
FIX::SessionID::m_sessionQualifier
std::string m_sessionQualifier
Definition SessionID.h:131
FIX::SessionID::operator==
friend bool operator==(const SessionID &, const SessionID &)
Definition SessionID.h:142
FIX::SessionID::getBeginString
const BeginString & getBeginString() const
Definition SessionID.h:53
FIX::SessionID::toString
std::string & toString(std::string &str) const
Get a string representation without making a copy.
Definition SessionID.h:105
FIX::SessionID::operator!=
friend bool operator!=(const SessionID &, const SessionID &)
Definition SessionID.h:147
FIX::SessionID::fromString
void fromString(const std::string &str)
Build from string representation of SessionID.
Definition SessionID.h:77
FIX::SessionID::operator>>
friend std::ostream & operator>>(std::ostream &, const SessionID &)
FIX::SessionID::SessionID
SessionID()
Definition SessionID.h:33
FIX::SessionID::isFIXT
const bool isFIXT() const
Definition SessionID.h:61
FIX::SessionID::toStringFrozen
const std::string & toStringFrozen() const
Definition SessionID.h:71
FIX::SessionID::operator~
SessionID operator~() const
Definition SessionID.h:121
FIX::SessionID::getTargetCompID
const TargetCompID & getTargetCompID() const
Definition SessionID.h:57
FIX::SessionID::toString
std::string toString() const
Get a string representation of the SessionID.
Definition SessionID.h:65
FIX::SessionID::operator<<
friend std::ostream & operator<<(std::ostream &, const SessionID &)
Definition SessionID.h:153
FIX
Definition Acceptor.cpp:35
FIX::operator==
bool operator==(const DatabaseConnectionID &lhs, const DatabaseConnectionID &rhs)
Definition DatabaseConnectionID.h:91
FIX::operator<
bool operator<(const DatabaseConnectionID &lhs, const DatabaseConnectionID &rhs)
Definition DatabaseConnectionID.h:66
FIX::operator!=
bool operator!=(const DatabaseConnectionID &lhs, const DatabaseConnectionID &rhs)
Definition DatabaseConnectionID.h:99