SessionID.h
Go to the documentation of this file.
1/* -*- C++ -*- */
2
3/****************************************************************************
4** Copyright (c) 2001-2014
5**
6** This file is part of the QuickFIX FIX Engine
7**
8** This file may be distributed under the terms of the quickfixengine.org
9** license as defined by quickfixengine.org and appearing in the file
10** LICENSE included in the packaging of this file.
11**
12** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14**
15** See http://www.quickfixengine.org/LICENSE for licensing information.
16**
17** Contact ask@quickfixengine.org if any conditions of this licensing are
18** not clear to you.
19**
20****************************************************************************/
21
22#ifndef FIX_SESSIONID_H
23#define FIX_SESSIONID_H
24
25#include "Fields.h"
26
27namespace FIX
28{
31{
32public:
37
38 SessionID( const std::string& beginString,
39 const std::string& senderCompID,
40 const std::string& targetCompID,
41 const std::string& sessionQualifier = "" )
42 : m_beginString( BeginString(beginString) ),
43 m_senderCompID( SenderCompID(senderCompID) ),
44 m_targetCompID( TargetCompID(targetCompID) ),
45 m_sessionQualifier( sessionQualifier ),
46 m_isFIXT(false)
47 {
49 if( beginString.substr(0, 4) == "FIXT" )
50 m_isFIXT = true;
51 }
52
53 const BeginString& getBeginString() const
54 { return m_beginString; }
55 const SenderCompID& getSenderCompID() const
56 { return m_senderCompID; }
57 const TargetCompID& getTargetCompID() const
58 { return m_targetCompID; }
59 const std::string& getSessionQualifier() const
60 { return m_sessionQualifier; }
61 const bool isFIXT() const
62 { return m_isFIXT; }
63
65 std::string toString() const
66 {
67 return m_frozenString;
68 }
69
70 // Return a reference for a high-performance scenario
71 const std::string& toStringFrozen() const
72 {
73 return m_frozenString;
74 }
75
77 void fromString( const std::string& str )
78 {
79 std::string::size_type first =
80 str.find_first_of(':');
81 std::string::size_type second =
82 str.find("->");
83 std::string::size_type third =
84 str.find_last_of(':');
85 if( first == std::string::npos )
86 return;
87 if( second == std::string::npos )
88 return;
89 m_beginString = str.substr(0, first);
90 m_senderCompID = str.substr(first+1, second - first - 1);
91 if( first == third )
92 {
93 m_targetCompID = str.substr(second+2);
95 }
96 else
97 {
98 m_targetCompID = str.substr(second+2, third - second - 2);
99 m_sessionQualifier = str.substr(third+1);
100 }
102 }
103
105 std::string& toString( std::string& str ) const
106 {
107 str = getBeginString().getValue() + ":" +
108 getSenderCompID().getValue() + "->" +
109 getTargetCompID().getValue();
110 if( m_sessionQualifier.size() )
111 str += ":" + m_sessionQualifier;
112 return str;
113 }
114
115 friend bool operator<( const SessionID&, const SessionID& );
116 friend bool operator==( const SessionID&, const SessionID& );
117 friend bool operator!=( const SessionID&, const SessionID& );
118 friend std::ostream& operator<<( std::ostream&, const SessionID& );
119 friend std::ostream& operator>>( std::ostream&, const SessionID& );
120
122 {
123 return SessionID( m_beginString, SenderCompID( m_targetCompID ),
124 TargetCompID( m_senderCompID ), m_sessionQualifier );
125 }
126
127private:
128 BeginString m_beginString;
129 SenderCompID m_senderCompID;
130 TargetCompID m_targetCompID;
133 std::string m_frozenString;
134};
137inline bool operator<( const SessionID& lhs, const SessionID& rhs )
138{
139 return lhs.toStringFrozen() < rhs.toStringFrozen();
140}
141
142inline bool operator==( const SessionID& lhs, const SessionID& rhs )
143{
144 return lhs.toStringFrozen() == rhs.toStringFrozen();
145}
146
147inline bool operator!=( const SessionID& lhs, const SessionID& rhs )
148{
149 return !( lhs == rhs );
150}
151
152inline std::ostream& operator<<
153( std::ostream& stream, const SessionID& sessionID )
154{
155 stream << sessionID.toStringFrozen();
156 return stream;
157}
158
159inline std::istream& operator>>
160( std::istream& stream, SessionID& sessionID )
161{
162 std::string str;
163 stream >> str;
164 sessionID.fromString( str );
165 return stream;
166}
167
168}
169#endif //FIX_SESSIONID_H
170
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition SessionID.h:31
std::string m_frozenString
Definition SessionID.h:133
const SenderCompID & getSenderCompID() const
Definition SessionID.h:55
SessionID(const std::string &beginString, const std::string &senderCompID, const std::string &targetCompID, const std::string &sessionQualifier="")
Definition SessionID.h:38
BeginString m_beginString
Definition SessionID.h:128
SenderCompID m_senderCompID
Definition SessionID.h:129
const std::string & getSessionQualifier() const
Definition SessionID.h:59
TargetCompID m_targetCompID
Definition SessionID.h:130
friend bool operator<(const SessionID &, const SessionID &)
Definition SessionID.h:137
std::string m_sessionQualifier
Definition SessionID.h:131
friend bool operator==(const SessionID &, const SessionID &)
Definition SessionID.h:142
const BeginString & getBeginString() const
Definition SessionID.h:53
std::string & toString(std::string &str) const
Get a string representation without making a copy.
Definition SessionID.h:105
friend bool operator!=(const SessionID &, const SessionID &)
Definition SessionID.h:147
void fromString(const std::string &str)
Build from string representation of SessionID.
Definition SessionID.h:77
friend std::ostream & operator>>(std::ostream &, const SessionID &)
const bool isFIXT() const
Definition SessionID.h:61
const std::string & toStringFrozen() const
Definition SessionID.h:71
SessionID operator~() const
Definition SessionID.h:121
const TargetCompID & getTargetCompID() const
Definition SessionID.h:57
std::string toString() const
Get a string representation of the SessionID.
Definition SessionID.h:65
friend std::ostream & operator<<(std::ostream &, const SessionID &)
Definition SessionID.h:153
bool operator==(const DatabaseConnectionID &lhs, const DatabaseConnectionID &rhs)
bool operator<(const DatabaseConnectionID &lhs, const DatabaseConnectionID &rhs)
bool operator!=(const DatabaseConnectionID &lhs, const DatabaseConnectionID &rhs)

Generated on Fri Sep 27 2024 13:45:21 for QuickFIX by doxygen 1.9.8 written by Dimitri van Heesch, © 1997-2001