37 #ifndef FIX8_TRAITS_HPP_
38 #define FIX8_TRAITS_HPP_
47 #if defined FIX8_HAVE_EXTENDED_METADATA
50 const struct FieldTrait *_traits;
51 const unsigned _fieldcnt;
123 FieldTrait(
unsigned short fnum,
unsigned ftype,
unsigned short pos,
unsigned short compon,
unsigned short field_traits
124 #
if defined FIX8_HAVE_EXTENDED_METADATA
129 #if defined FIX8_HAVE_EXTENDED_METADATA
130 , _group(TraitHelper{
group, fieldcnt})
147 bool ismandatory=
false,
bool isgroup=
false,
const unsigned compon=0,
bool ispresent=
false) :
156 #if defined FIX8_HAVE_EXTENDED_METADATA
157 const TraitHelper _group = TraitHelper{
nullptr, 0 };
194 F8API std::ostream&
operator<<(std::ostream& os,
const FieldTrait& what);
204 : _els(static_cast<unsigned>(els)), _sz((from + _els - 1)->_fnum + 1), _arr(new unsigned short [_sz])
206 std::fill(_arr, _arr + _sz, 0);
207 for (
unsigned offset(0); offset <
_els; ++offset)
208 *(_arr + (from + offset)->_fnum) = offset;
223 using result = std::pair<iterator, bool>;
233 const size_t val(sz * res / 100);
234 return val ? val : 1;
252 : _reserve(), _sz(sz), _arr(new
FieldTrait[_sz]), _ftha(ftha)
253 { memcpy(_arr, arr_start, _sz *
sizeof(
FieldTrait)); }
261 { memcpy(_arr, arr_start, _sz *
sizeof(
FieldTrait)); }
266 _sz(from._sz), _rsz(from._rsz), _arr(new
FieldTrait[_rsz]), _ftha(from._ftha)
273 _sz(sz), _rsz(_sz +
calc_reserve(_sz, _reserve)), _arr(), _ftha() {}
287 answer = res.first != res.second;
303 return key < _ftha->
_sz && (_arr + _ftha->
_arr[key])->_fnum == key ? _arr + _ftha->
_arr[key] :
end();
306 return res.first != res.second ? res.first :
end();
317 return res.first != res.second ? res.first :
end();
326 return key < _ftha->
_sz && (_arr + _ftha->
_arr[key])->_fnum == key ? _arr + _ftha->
_arr[key] :
end();
329 return res.first != res.second ? res.first :
end();
338 return res.first != res.second ? res.first :
end();
356 return std::make_pair(_arr,
true);
362 return std::make_pair(
end(),
false);
366 memmove(where + 1, where, (
end() - where) *
sizeof(
FieldTrait));
372 const size_t wptr(where - _arr);
374 memcpy(new_arr, _arr,
sizeof(
FieldTrait) * wptr);
375 memcpy(new_arr + wptr, what,
sizeof(
FieldTrait));
376 memcpy(new_arr + wptr + 1, where, (
end() - where) *
sizeof(
FieldTrait));
381 return std::make_pair(where,
true);
389 {
return what_end - what_begin; }
410 bool empty()
const {
return _sz == 0; }
447 template<
typename InputIterator>
459 if (itr == _presence.
end())
460 itr = _presence.
find(field);
461 return itr != _presence.
end();
467 bool has(
const unsigned short field)
const
470 return itr != _presence.
end();
476 unsigned getval(
const unsigned short field)
503 if (itr != _presence.
end())
504 return itr->_field_traits.has(type);
505 itr = _presence.
find(field);
526 if (itr == _presence.
end())
528 itr = _presence.
find(field);
529 if (itr != _presence.
end())
542 if (itr != _presence.
end())
552 if (itr == _presence.
end())
554 itr = _presence.
find(field);
555 if (itr != _presence.
end())
568 if (itr != _presence.
end())
580 template<
typename InputIterator>
581 void add(
const InputIterator begin,
const size_t cnt) { _presence.
insert(begin, begin + cnt); }
620 if (itr != _presence.
end())
622 itr = _presence.
find(field);
629 unsigned short getComp(
const unsigned short field)
const
641 if (itr != _presence.
end())
643 itr = _presence.
find(field);
650 unsigned short getPos(
const unsigned short field)
const
667 F8API std::ostream&
operator<<(std::ostream& os,
const FieldTraits& what);
671 #endif // FIX8_TRAITS_HPP_
FieldTrait(const unsigned short field, const FieldType ftype, const unsigned short pos=0, bool ismandatory=false, bool isgroup=false, const unsigned compon=0, bool ispresent=false)
integral_type get() const
static F8API std::string & get_type_string(FieldType ftype, std::string &to)
const_iterator end() const
void clear(const unsigned short field, Presence::const_iterator &itr, FieldTrait::TraitTypes type=FieldTrait::present)
static FieldType underlying_type(FieldType ftype)
Binary comparitor functor.
unsigned short find_missing(FieldTrait::TraitTypes type=FieldTrait::mandatory) const
FieldTraits(const InputIterator begin, const size_t cnt, const FieldTrait_Hash_Array *ftha)
void insert(const_iterator what_begin, const_iterator what_end)
static size_t calc_reserve(size_t sz, size_t res)
presorted_set(const size_t sz=0, const size_t reserve=FIX8_RESERVE_PERCENT)
const FieldTrait_Hash_Array * _ftha
const_iterator begin() const
static bool is_char(FieldType ftype)
unsigned short getPos(const unsigned short field, Presence::const_iterator &itr) const
presorted_set(const_iterator arr_start, const size_t sz, const size_t reserve=FIX8_RESERVE_PERCENT)
bool has(const unsigned short field, Presence::const_iterator &itr) const
bool is_mandatory(const unsigned short field) const
const_iterator find(const FieldTrait what) const
const Presence & get_presence() const
iterator find(const unsigned short key)
FieldTrait(unsigned short fnum, unsigned ftype, unsigned short pos, unsigned short compon, unsigned short field_traits)
std::ostream & operator<<(std::ostream &os, const GroupBase &what)
bool is_component(const unsigned short field) const
FieldTrait_Hash_Array(const FieldTrait *from, const size_t els)
FieldTrait(const unsigned short field)
static size_t calc_reserve(size_t sz, size_t res)
void add(const InputIterator begin, const size_t cnt)
result insert(const_iterator what)
Used for static trait interrogation.
iterator find(const FieldTrait what)
static bool is_float(FieldType ftype)
iterator find(const unsigned short key, bool &answer)
const_iterator at(const size_t idx) const
result insert(const_iterator what)
void clear_flag(FieldTrait::TraitTypes type=FieldTrait::present)
std::pair< iterator, bool > result
unsigned short _component
const_iterator find(const unsigned short key) const
void set(const unsigned short field, FieldTrait::TraitTypes type=FieldTrait::present)
#define FIX8_RESERVE_PERCENT
Binary position comparitor functor.
ebitset< TraitTypes, unsigned short > _field_traits
void clear(const unsigned short field, FieldTrait::TraitTypes type=FieldTrait::present)
static size_t distance(const_iterator what_begin, const_iterator what_end)
bool is_group(const unsigned short field, Presence::const_iterator &itr) const
bool has(const unsigned short field) const
friend F8API std::ostream & operator<<(std::ostream &os, const FieldTrait &what)
bool operator()(const FieldTrait &p1, const FieldTrait &p2) const
static bool is_int(FieldType ftype)
iterator find(const T what, bool &answer)
static bool is_string(FieldType ftype)
bool add(const FieldTrait &what)
integral_type has(const T sbit) const
A collection of FieldTraits for a message. Which fields are required, which are present.
FieldTrait(const FieldTrait &from)
Copy Ctor.
unsigned short getPos(const unsigned short field) const
unsigned short getComp(const unsigned short field) const
presorted_set(const_iterator arr_start, const size_t sz, const FieldTrait_Hash_Array *ftha)
friend F8API std::ostream & operator<<(std::ostream &os, const FieldTraits &what)
bool operator()(const FieldTrait *p1, const FieldTrait *p2) const
FieldTrait()=default
Ctor.
presorted_set(const presorted_set &from)
iterator find(const FieldTrait what, bool &answer)
void set(const T sbit, bool on=true)
unsigned short getComp(const unsigned short field, Presence::const_iterator &itr) const
std::pair< iterator, iterator > internal_result
bool is_group(const unsigned short field) const
std::pair< const_iterator, const_iterator > const_internal_result
unsigned getval(const unsigned short field)
bool is_present(const unsigned short field) const
void set(const unsigned short field, Presence::const_iterator &itr, FieldTrait::TraitTypes type)
Fast index lookup for FieldTrait.