Index Source Files Annotated Class List Alphabetical Class List Class Hierarchy Graphical Class Hierarchy

# SessionID.h

Go to the documentation of this file.

    00001 /* -*- C++ -*- */
    00002
    00003 /****************************************************************************
    00004 ** Copyright (c) quickfixengine.org  All rights reserved.
    00005 **
    00006 ** This file is part of the QuickFIX FIX Engine
    00007 **
    00008 ** This file may be distributed under the terms of the quickfixengine.org
    00009 ** license as defined by quickfixengine.org and appearing in the file
    00010 ** LICENSE included in the packaging of this file.
    00011 **
    00012 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
    00013 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    00014 **
    00015 ** See http://www.quickfixengine.org/LICENSE for licensing information.
    00016 **
    00017 ** Contact ask@quickfixengine.org if any conditions of this licensing are
    00018 ** not clear to you.
    00019 **
    00020 ****************************************************************************/
    00021
    00022 #ifndef FIX_SESSIONID_H
    00023 #define FIX_SESSIONID_H
    00024
    00025 #include "Fields.h"
    00026
    00027 namespace FIX
    00028 {
    00030 class SessionID
    00031 {
    00032 public:
    00033   SessionID()
    00034   {
    00035         toString(m_frozenString);
    00036   }
    00037
    00038   SessionID( const std::string& beginString,
    00039              const std::string& senderCompID,
    00040              const std::string& targetCompID,
    00041              const std::string& sessionQualifier = "" )
    00042   : m_beginString( BeginString(beginString) ),
    00043     m_senderCompID( SenderCompID(senderCompID) ),
    00044     m_targetCompID( TargetCompID(targetCompID) ),
    00045     m_sessionQualifier( sessionQualifier ),
    00046           m_isFIXT(false)
    00047   {
    00048     toString(m_frozenString);
    00049                 if( beginString.substr(0, 4) == "FIXT" )
    00050                         m_isFIXT = true;
    00051   }
    00052
    00053   const BeginString& getBeginString() const
    00054     { return m_beginString; }
    00055   const SenderCompID& getSenderCompID() const
    00056     { return m_senderCompID; }
    00057   const TargetCompID& getTargetCompID() const
    00058     { return m_targetCompID; }
    00059   const std::string& getSessionQualifier() const
    00060     { return m_sessionQualifier; }
    00061   const bool isFIXT() const
    00062     { return m_isFIXT; }
    00063
    00065   std::string toString() const
    00066   {
    00067     return m_frozenString;
    00068   }
    00069
    00070   // Return a reference for a high-performance scenario
    00071   const std::string& toStringFrozen() const
    00072   {
    00073     return m_frozenString;
    00074   }
    00075
    00077   void fromString( const std::string& str )
    00078   {
    00079     std::string::size_type first =
    00080       str.find_first_of(':');
    00081     std::string::size_type second =
    00082       str.find("->");
    00083     std::string::size_type third =
    00084       str.find_last_of(':');
    00085     if( first == std::string::npos )
    00086       return;
    00087     if( second == std::string::npos )
    00088       return;
    00089     m_beginString = str.substr(0, first);
    00090     m_senderCompID = str.substr(first+1, second - first - 1);
    00091     if( first == third )
    00092     {
    00093       m_targetCompID = str.substr(second+2);
    00094       m_sessionQualifier = "";
    00095     }
    00096     else
    00097     {
    00098       m_targetCompID = str.substr(second+2, third - second - 2);
    00099       m_sessionQualifier = str.substr(third+1);
    00100     }
    00101     toString(m_frozenString);
    00102   }
    00103
    00105   std::string& toString( std::string& str ) const
    00106   {
    00107     str = getBeginString().getValue() + ":" +
    00108           getSenderCompID().getValue() + "->" +
    00109           getTargetCompID().getValue();
    00110     if( m_sessionQualifier.size() )
    00111       str += ":" + m_sessionQualifier;
    00112     return str;
    00113   }
    00114
    00115   friend bool operator<( const SessionID&, const SessionID& );
    00116   friend bool operator==( const SessionID&, const SessionID& );
    00117   friend bool operator!=( const SessionID&, const SessionID& );
    00118   friend std::ostream& operator<<( std::ostream&, const SessionID& );
    00119   friend std::ostream& operator>>( std::ostream&, const SessionID& );
    00120
    00121   SessionID operator~() const
    00122   {
    00123     return SessionID( m_beginString, SenderCompID( m_targetCompID ),
    00124                       TargetCompID( m_senderCompID ), m_sessionQualifier );
    00125   }
    00126
    00127 private:
    00128   BeginString m_beginString;
    00129   SenderCompID m_senderCompID;
    00130   TargetCompID m_targetCompID;
    00131   std::string m_sessionQualifier;
    00132   bool m_isFIXT;
    00133   std::string m_frozenString;
    00134 };
    00137 inline bool operator<( const SessionID& lhs, const SessionID& rhs )
    00138 {
    00139   return lhs.toStringFrozen() < rhs.toStringFrozen();
    00140 }
    00141
    00142 inline bool operator==( const SessionID& lhs, const SessionID& rhs )
    00143 {
    00144   return lhs.toStringFrozen() == rhs.toStringFrozen();
    00145 }
    00146
    00147 inline bool operator!=( const SessionID& lhs, const SessionID& rhs )
    00148 {
    00149   return !( lhs == rhs );
    00150 }
    00151
    00152 inline std::ostream& operator<<
    00153 ( std::ostream& stream, const SessionID& sessionID )
    00154 {
    00155   stream << sessionID.toStringFrozen();
    00156   return stream;
    00157 }
    00158
    00159 inline std::istream& operator>>
    00160 ( std::istream& stream, SessionID& sessionID )
    00161 {
    00162   std::string str;
    00163   stream >> str;
    00164   sessionID.fromString( str );
    00165   return stream;
    00166 }
    00167
    00168 }
    00169 #endif //FIX_SESSIONID_H
    00170