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 
27 namespace FIX
28 {
30 class SessionID
31 {
32 public:
34  {
36  }
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; }
56  { return m_senderCompID; }
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);
94  m_sessionQualifier = "";
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  {
125  }
126 
127 private:
131  std::string m_sessionQualifier;
132  bool m_isFIXT;
133  std::string m_frozenString;
134 };
137 inline bool operator<( const SessionID& lhs, const SessionID& rhs )
138 {
139  return lhs.toStringFrozen() < rhs.toStringFrozen();
140 }
141 
142 inline bool operator==( const SessionID& lhs, const SessionID& rhs )
143 {
144  return lhs.toStringFrozen() == rhs.toStringFrozen();
145 }
146 
147 inline bool operator!=( const SessionID& lhs, const SessionID& rhs )
148 {
149  return !( lhs == rhs );
150 }
151 
152 inline std::ostream& operator<<
153 ( std::ostream& stream, const SessionID& sessionID )
154 {
155  stream << sessionID.toStringFrozen();
156  return stream;
157 }
158 
159 inline 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 
const std::string & getSessionQualifier() const
Definition: SessionID.h:59
friend std::ostream & operator>>(std::ostream &, const SessionID &)
std::string m_sessionQualifier
Definition: SessionID.h:131
SessionID operator~() const
Definition: SessionID.h:121
friend bool operator<(const SessionID &, const SessionID &)
Definition: SessionID.h:137
const std::string & toStringFrozen() const
Definition: SessionID.h:71
friend bool operator==(const SessionID &, const SessionID &)
Definition: SessionID.h:142
std::string & toString(std::string &str) const
Get a string representation without making a copy.
Definition: SessionID.h:105
const TargetCompID & getTargetCompID() const
Definition: SessionID.h:57
BeginString m_beginString
Definition: SessionID.h:128
std::string toString() const
Get a string representation of the SessionID.
Definition: SessionID.h:65
void fromString(const std::string &str)
Build from string representation of SessionID.
Definition: SessionID.h:77
TargetCompID m_targetCompID
Definition: SessionID.h:130
Definition: Acceptor.cpp:34
const int TargetCompID
SenderCompID m_senderCompID
Definition: SessionID.h:129
const bool isFIXT() const
Definition: SessionID.h:61
const BeginString & getBeginString() const
Definition: SessionID.h:53
const int SenderCompID
SessionID(const std::string &beginString, const std::string &senderCompID, const std::string &targetCompID, const std::string &sessionQualifier="")
Definition: SessionID.h:38
const int BeginString
Unique session id consists of BeginString, SenderCompID and TargetCompID.
Definition: SessionID.h:30
const SenderCompID & getSenderCompID() const
Definition: SessionID.h:55
friend std::ostream & operator<<(std::ostream &, const SessionID &)
Definition: SessionID.h:153
std::string m_frozenString
Definition: SessionID.h:133
friend bool operator!=(const SessionID &, const SessionID &)
Definition: SessionID.h:147

Generated on Sun Apr 15 2018 21:44:02 for QuickFIX by doxygen 1.8.13 written by Dimitri van Heesch, © 1997-2001