fix8  version 1.4.0
Open Source C++ FIX Framework
traits.cpp
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------------------
2 /*
3 
4 Fix8 is released under the GNU LESSER GENERAL PUBLIC LICENSE Version 3.
5 
6 Fix8 Open Source FIX Engine.
7 Copyright (C) 2010-16 David L. Dight <fix@fix8.org>
8 
9 Fix8 is free software: you can redistribute it and / or modify it under the terms of the
10 GNU Lesser General Public License as published by the Free Software Foundation, either
11 version 3 of the License, or (at your option) any later version.
12 
13 Fix8 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
14 even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 
16 You should have received a copy of the GNU Lesser General Public License along with Fix8.
17 If not, see <http://www.gnu.org/licenses/>.
18 
19 BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO
20 THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE
21 COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
22 KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO
24 THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
25 YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
26 
27 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT
28 HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED
29 ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
30 CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT
31 NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR
32 THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH
33 HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
34 
35 */
36 //-----------------------------------------------------------------------------------------
37 #include "precomp.hpp"
38 #include <fix8/f8includes.hpp>
39 
40 //-------------------------------------------------------------------------------------------------
41 using namespace FIX8;
42 using namespace std;
43 
44 //-------------------------------------------------------------------------------------------------
45 ostream& FIX8::operator<<(ostream& os, const FieldTrait& what)
46 {
47  static const vector<string> bts { "mandatory", "present", "position", "group", "component", "suppress", "automatic" };
48  os << "Tag:" << what._fnum << " Type:" << what._ftype << " (";
49  string strtype;
50  os << FieldTrait::get_type_string(what._ftype, strtype);
51  os << ") Pos:" << what._pos;
52  if (what._component)
53  os << " Component:" << what._component;
54  os << " Flags:";
55  for (unsigned ii(what._field_traits.get()), pos(0); pos < FieldTrait::count; ++pos)
56  if (ii >> pos & 0x1)
57  os << bts[pos] << ' ';
58  return os;
59 }
60 
61 //-------------------------------------------------------------------------------------------------
62 ostream& FIX8::operator<<(ostream& os, const FieldTraits& what)
63 {
64  copy(what.get_presence().begin(), what.get_presence().end(), ostream_iterator<FieldTrait>(os, "\n"));
65  return os;
66 }
67 
68 //-------------------------------------------------------------------------------------------------
70 {
71  return to = FieldTrait::is_int(ftype) ? "int" : FieldTrait::is_char(ftype) ? "char"
72  : FieldTrait::is_float(ftype) ? "double" : FieldTrait::is_string(ftype) ? "f8String" : f8String();
73 }
74 
integral_type get() const
Definition: f8utils.hpp:924
static F8API std::string & get_type_string(FieldType ftype, std::string &to)
Definition: traits.cpp:69
static bool is_char(FieldType ftype)
Definition: traits.hpp:88
const Presence & get_presence() const
Definition: traits.hpp:658
std::ostream & operator<<(std::ostream &os, const GroupBase &what)
Definition: message.hpp:1373
Used for static trait interrogation.
Definition: traits.hpp:57
static bool is_float(FieldType ftype)
Definition: traits.hpp:93
unsigned short _component
Definition: traits.hpp:154
unsigned short _fnum
Definition: traits.hpp:152
ebitset< TraitTypes, unsigned short > _field_traits
Definition: traits.hpp:155
unsigned short _pos
Definition: traits.hpp:154
static bool is_int(FieldType ftype)
Definition: traits.hpp:83
static bool is_string(FieldType ftype)
Definition: traits.hpp:98
A collection of FieldTraits for a message. Which fields are required, which are present.
Definition: traits.hpp:437
std::string f8String
Definition: f8types.hpp:47
FieldType _ftype
Definition: traits.hpp:153