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

/home/orenmnero/autobuild/quickfix/src/C++/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   SessionID( const BeginString& beginString,
00036              const SenderCompID& senderCompID,
00037              const TargetCompID& targetCompID,
00038              const std::string& sessionQualifier = "" )
00039   : m_beginString( beginString ),
00040     m_senderCompID( senderCompID ),
00041     m_targetCompID( targetCompID ),
00042     m_sessionQualifier( sessionQualifier ) {}
00043 
00044   SessionID( const std::string& beginString,
00045              const std::string& senderCompID,
00046              const std::string& targetCompID,
00047              const std::string& sessionQualifier = "" )
00048   : m_beginString( BeginString(beginString) ),
00049     m_senderCompID( SenderCompID(senderCompID) ),
00050     m_targetCompID( TargetCompID(targetCompID) ),
00051     m_sessionQualifier( sessionQualifier ) {}
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 
00063   std::string toString() const
00064   {
00065       std::string str;
00066       return toString( str );
00067   }
00068 
00070   void fromString( const std::string& str )
00071   {
00072     std::string::size_type first =
00073       str.find_first_of(':');
00074     std::string::size_type second =
00075       str.find("->");
00076     std::string::size_type third =
00077       str.find_last_of(':');
00078     if( first == std::string::npos )
00079       return;
00080     if( second == std::string::npos )
00081       return;
00082     m_beginString = str.substr(0, first);
00083     m_senderCompID = str.substr(first+1, second - first - 1);
00084     if( first == third )
00085     {
00086       m_targetCompID = str.substr(second+2);
00087       m_sessionQualifier = "";
00088     }
00089     else
00090     {
00091       m_targetCompID = str.substr(second+2, third - second - 2);
00092       m_sessionQualifier = str.substr(third+1);
00093     }
00094   }
00095 
00097   std::string& toString( std::string& str ) const
00098   {
00099     str = getBeginString().getValue() + ":" +
00100           getSenderCompID().getValue() + "->" +
00101           getTargetCompID().getValue();
00102     if( m_sessionQualifier.size() )
00103       str += ":" + m_sessionQualifier;
00104     return str;
00105   }
00106 
00107   friend bool operator<( const SessionID&, const SessionID& );
00108   friend bool operator==( const SessionID&, const SessionID& );
00109   friend bool operator!=( const SessionID&, const SessionID& );
00110   friend std::ostream& operator<<( std::ostream&, const SessionID& );
00111   friend std::ostream& operator>>( std::ostream&, const SessionID& );
00112 
00113   SessionID operator~()
00114   {
00115     return SessionID( m_beginString, SenderCompID( m_targetCompID ),
00116                       TargetCompID( m_senderCompID ), m_sessionQualifier );
00117   }
00118 
00119 private:
00120   BeginString m_beginString;
00121   SenderCompID m_senderCompID;
00122   TargetCompID m_targetCompID;
00123   std::string m_sessionQualifier;
00124 };
00127 inline bool operator<( const SessionID& lhs, const SessionID& rhs )
00128 {
00129   if ( lhs.m_beginString < rhs.m_beginString )
00130     return true;
00131   else if ( rhs.m_beginString < lhs.m_beginString )
00132     return false;
00133   else if ( lhs.m_senderCompID < rhs.m_senderCompID )
00134     return true;
00135   else if ( rhs.m_senderCompID < lhs.m_senderCompID )
00136     return false;
00137   else if ( lhs.m_targetCompID < rhs.m_targetCompID )
00138     return true;
00139   else if ( rhs.m_targetCompID < lhs.m_targetCompID )
00140     return false;
00141   else if ( lhs.m_sessionQualifier < rhs.m_sessionQualifier )
00142     return true;
00143   else if ( rhs.m_sessionQualifier < lhs.m_sessionQualifier )
00144     return false;
00145   else
00146     return false;
00147 }
00148 inline bool operator==( const SessionID& lhs, const SessionID& rhs )
00149 {
00150   return ( ( lhs.m_beginString == rhs.m_beginString ) &&
00151            ( lhs.m_senderCompID == rhs.m_senderCompID ) &&
00152            ( lhs.m_targetCompID == rhs.m_targetCompID ) &&
00153            ( lhs.m_sessionQualifier == rhs.m_sessionQualifier ));
00154 }
00155 inline bool operator!=( const SessionID& lhs, const SessionID& rhs )
00156 {
00157   return !( lhs == rhs );
00158 }
00159 
00160 inline std::ostream& operator<<
00161 ( std::ostream& stream, const SessionID& sessionID )
00162 {
00163   std::string str;
00164   stream << sessionID.toString( str );
00165   return stream;
00166 }
00167 
00168 inline std::istream& operator>>
00169 ( std::istream& stream, SessionID& sessionID )
00170 {
00171   std::string str;
00172   stream >> str;
00173   sessionID.fromString( str );
00174   return stream;
00175 }
00176 
00177 }
00178 #endif //FIX_SESSIONID_H

Generated on Mon Jul 24 19:36:30 2006 for QuickFIX by doxygen 1.3.6-20040222 written by Dimitri van Heesch, © 1997-2001