Classes | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Friends | List of all members
FIX::FieldBase Class Reference

Base representation of all Field classes. More...

#include <Field.h>

Inheritance diagram for FIX::FieldBase:
Inheritance graph
[legend]
Collaboration diagram for FIX::FieldBase:
Collaboration graph
[legend]

Classes

class  field_metrics
 Class used to store field metrics like total length and checksum. More...
 

Public Member Functions

 FieldBase (int tag, const std::string &string)
 
virtual ~FieldBase ()
 
 FieldBase (const FieldBase &rhs)
 
FieldBaseoperator= (const FieldBase &rhs)
 
void swap (FieldBase &rhs)
 
void setTag (int tag)
 
void setField (int field)
 
void setString (const std::string &string)
 
int getTag () const
 Get the fields integer tag. More...
 
int getField () const
 
const std::string & getString () const
 Get the string representation of the fields value. More...
 
const std::string & getFixString () const
 Get the string representation of the Field (i.e.) 55=MSFT[SOH]. More...
 
size_t getLength () const
 Get the length of the fields string representation. More...
 
int getTotal () const
 Get the total value the fields characters added together. More...
 
bool operator< (const FieldBase &field) const
 Compares fields based on their tag numbers. More...
 

Private Member Functions

 FieldBase (int tag, std::string::const_iterator valueStart, std::string::const_iterator valueEnd, std::string::const_iterator tagStart, std::string::const_iterator tagEnd)
 Constructor which also calculates field metrics. More...
 
void calculate () const
 
void encodeTo (std::string &result) const
 Serializes string representation of the Field to input string. More...
 

Static Private Member Functions

static field_metrics no_metrics ()
 
static field_metrics calculateMetrics (std::string::const_iterator const start, std::string::const_iterator const end)
 Calculate metrics for any input string. More...
 
static field_metrics calculateMetrics (const std::string &field)
 

Private Attributes

int m_tag
 
std::string m_string
 
std::string m_data
 
field_metrics m_metrics
 

Friends

class Message
 

Detailed Description

Base representation of all Field classes.

This base class is the lowest common denominator of all fields. It keeps all fields in its most generic string representation with its integer tag.

Definition at line 49 of file Field.h.

Constructor & Destructor Documentation

◆ FieldBase() [1/3]

FIX::FieldBase::FieldBase ( int  tag,
std::string::const_iterator  valueStart,
std::string::const_iterator  valueEnd,
std::string::const_iterator  tagStart,
std::string::const_iterator  tagEnd 
)
inlineprivate

Constructor which also calculates field metrics.

Definition at line 80 of file Field.h.

85  : m_tag( tag )
86  , m_string( valueStart, valueEnd )
87  , m_metrics( calculateMetrics( tagStart, tagEnd ) )
88  {}
field_metrics m_metrics
Definition: Field.h:238
static field_metrics calculateMetrics(std::string::const_iterator const start, std::string::const_iterator const end)
Calculate metrics for any input string.
Definition: Field.h:213
std::string m_string
Definition: Field.h:236

◆ FieldBase() [2/3]

FIX::FieldBase::FieldBase ( int  tag,
const std::string &  string 
)
inline

Definition at line 91 of file Field.h.

92  : m_tag( tag ), m_string(string), m_metrics( no_metrics() )
93  {}
static field_metrics no_metrics()
Definition: Field.h:207

◆ ~FieldBase()

virtual FIX::FieldBase::~FieldBase ( )
inlinevirtual

Definition at line 95 of file Field.h.

95 {}

◆ FieldBase() [3/3]

FIX::FieldBase::FieldBase ( const FieldBase rhs)
inline

Definition at line 97 of file Field.h.

98  : m_tag( rhs.getTag() )
99  , m_string( rhs.m_string )
100  , m_metrics( rhs.m_metrics )
101  {
102 
103  }

Member Function Documentation

◆ calculate()

void FIX::FieldBase::calculate ( ) const
inlineprivate

Definition at line 184 of file Field.h.

185  {
186  if( m_metrics.isValid() ) return;
187 
189  }
bool isValid() const
Definition: Field.h:68
const std::string & getFixString() const
Get the string representation of the Field (i.e.) 55=MSFT[SOH].
Definition: Field.h:156

References calculateMetrics(), getFixString(), FIX::FieldBase::field_metrics::isValid(), and m_metrics.

Referenced by getLength(), and getTotal().

◆ calculateMetrics() [1/2]

static field_metrics FIX::FieldBase::calculateMetrics ( const std::string &  field)
inlinestaticprivate

Definition at line 230 of file Field.h.

231  {
232  return calculateMetrics( field.begin(), field.end() );
233  }

References calculateMetrics().

◆ calculateMetrics() [2/2]

static field_metrics FIX::FieldBase::calculateMetrics ( std::string::const_iterator const  start,
std::string::const_iterator const  end 
)
inlinestaticprivate

Calculate metrics for any input string.

Definition at line 213 of file Field.h.

216  {
217  int checksum = 0;
218  for ( std::string::const_iterator str = start; str != end; ++str )
219  checksum += (unsigned char)( *str );
220 
221 #if defined(__SUNPRO_CC)
222  std::ptrdiff_t d;
223  std::distance(start, end, d);
224  return field_metrics( d, checksum );
225 #else
226  return field_metrics( std::distance( start, end ), checksum );
227 #endif
228  }

Referenced by calculate(), and calculateMetrics().

◆ encodeTo()

void FIX::FieldBase::encodeTo ( std::string &  result) const
inlineprivate

Serializes string representation of the Field to input string.

Definition at line 192 of file Field.h.

193  {
194  size_t tagLength = FIX::number_of_symbols_in( m_tag );
195  size_t totalLength = tagLength + m_string.length() + 2;
196 
197  result.resize( totalLength );
198 
199  char * buf = (char*)result.c_str();
200  FIX::integer_to_string( buf, tagLength, m_tag );
201 
202  buf[tagLength] = '=';
203  memcpy( buf + tagLength + 1, m_string.data(), m_string.length() );
204  buf[totalLength - 1] = '\001';
205  }
char * integer_to_string(char *buf, const size_t len, signed_int t)
int number_of_symbols_in(const signed_int value)

References FIX::integer_to_string(), m_string, m_tag, and FIX::number_of_symbols_in().

Referenced by getFixString().

◆ getField()

int FIX::FieldBase::getField ( ) const
inline
Deprecated:
Use getTag

Definition at line 148 of file Field.h.

149  { return getTag(); }
int getTag() const
Get the fields integer tag.
Definition: Field.h:144

References getTag().

◆ getFixString()

const std::string& FIX::FieldBase::getFixString ( ) const
inline

Get the string representation of the Field (i.e.) 55=MSFT[SOH].

Definition at line 156 of file Field.h.

157  {
158  if( m_data.empty() )
159  encodeTo( m_data );
160 
161  return m_data;
162  }
void encodeTo(std::string &result) const
Serializes string representation of the Field to input string.
Definition: Field.h:192
std::string m_data
Definition: Field.h:237

References encodeTo(), and m_data.

Referenced by calculate().

◆ getLength()

size_t FIX::FieldBase::getLength ( ) const
inline

Get the length of the fields string representation.

Definition at line 165 of file Field.h.

166  {
167  calculate();
168  return m_metrics.getLength();
169  }
size_t getLength() const
Definition: Field.h:62
void calculate() const
Definition: Field.h:184

References calculate(), FIX::FieldBase::field_metrics::getLength(), and m_metrics.

◆ getString()

const std::string& FIX::FieldBase::getString ( ) const
inline

◆ getTag()

int FIX::FieldBase::getTag ( ) const
inline

◆ getTotal()

int FIX::FieldBase::getTotal ( ) const
inline

Get the total value the fields characters added together.

Definition at line 172 of file Field.h.

173  {
174  calculate();
175  return m_metrics.getCheckSum();
176  }
int getCheckSum() const
Definition: Field.h:65

References calculate(), FIX::FieldBase::field_metrics::getCheckSum(), and m_metrics.

◆ no_metrics()

static field_metrics FIX::FieldBase::no_metrics ( )
inlinestaticprivate

Definition at line 207 of file Field.h.

208  {
209  return field_metrics( 0, 0 );
210  }

Referenced by setString(), and setTag().

◆ operator<()

bool FIX::FieldBase::operator< ( const FieldBase field) const
inline

Compares fields based on their tag numbers.

Definition at line 179 of file Field.h.

180  { return m_tag < field.m_tag; }

References m_tag.

◆ operator=()

FieldBase& FIX::FieldBase::operator= ( const FieldBase rhs)
inline

Definition at line 105 of file Field.h.

106  {
107  m_tag = rhs.getTag();
108  m_string = rhs.m_string;
109  m_metrics = rhs.m_metrics;
110  m_data.clear();
111 
112  return *this;
113  }

References getTag(), m_data, m_metrics, m_string, and m_tag.

◆ setField()

void FIX::FieldBase::setField ( int  field)
inline
Deprecated:
Use setTag

Definition at line 131 of file Field.h.

132  {
133  setTag( field );
134  }
void setTag(int tag)
Definition: Field.h:123

References setTag().

◆ setString()

void FIX::FieldBase::setString ( const std::string &  string)
inline

◆ setTag()

void FIX::FieldBase::setTag ( int  tag)
inline

Definition at line 123 of file Field.h.

124  {
125  m_tag = tag;
126  m_metrics = no_metrics();
127  m_data.clear();
128  }

References m_data, m_metrics, m_tag, and no_metrics().

Referenced by setField().

◆ swap()

void FIX::FieldBase::swap ( FieldBase rhs)
inline

Definition at line 115 of file Field.h.

116  {
117  std::swap( m_tag, rhs.m_tag );
118  std::swap( m_metrics, rhs.m_metrics );
119  m_string.swap( rhs.m_string );
120  m_data.swap( rhs.m_data );
121  }
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:5991

References m_data, m_metrics, m_string, m_tag, and swap().

Referenced by FIX::swap().

Friends And Related Function Documentation

◆ Message

friend class Message
friend

Definition at line 77 of file Field.h.

Member Data Documentation

◆ m_data

std::string FIX::FieldBase::m_data
mutableprivate

Definition at line 237 of file Field.h.

Referenced by getFixString(), operator=(), setString(), setTag(), and swap().

◆ m_metrics

field_metrics FIX::FieldBase::m_metrics
mutableprivate

Definition at line 238 of file Field.h.

Referenced by calculate(), getLength(), getTotal(), operator=(), setString(), setTag(), and swap().

◆ m_string

std::string FIX::FieldBase::m_string
private

Definition at line 236 of file Field.h.

Referenced by encodeTo(), getString(), operator=(), setString(), and swap().

◆ m_tag

int FIX::FieldBase::m_tag
private

Definition at line 235 of file Field.h.

Referenced by encodeTo(), getTag(), operator<(), operator=(), setTag(), and swap().


The documentation for this class was generated from the following file:

Generated on Wed Nov 24 2021 09:55:53 for QuickFIX by doxygen 1.9.1 written by Dimitri van Heesch, © 1997-2001