libjmmcg  build_2783
A C++ library containing an eclectic mix of useful, advanced components.
jmmcg::bitfield_map< BFSM, BFSz > Class Template Reference

This container is an associative collection of types. The domain is a bit-map of the mapped_types that are selected in the range. More...

#include <bitfield_map.hpp>

Public Types

enum  : std::size_t
 
enum  : bool
 
using key_type = uint64_t
 
using size_type = std::size_t
 
using mapped_types = BFSM
 The range of mapped-types that may be selected by the domain. This range is a collection that is indexed by the unique enum-tag of the range. More...
 
using bitfields_tags_type = typename boost::mpl::deref< typename boost::mpl::begin< mapped_types >::type >::type::first::value_type
 The range of enum-tags used to indicate the requested element in the mapped_types range. More...
 
using underlying_key_type = typename std::underlying_type< bitfields_tags_type >::type
 The underlying type of the domain enum. More...
 
using raw_mapped_data_t = std::array< uint8_t, range_mapped_types_size >
 

Public Member Functions

 BOOST_MPL_ASSERT ((std::is_pod< bitfields_tags_type >))
 
 BOOST_MPL_ASSERT ((std::is_integral< typename std::underlying_type< bitfields_tags_type >::type >))
 
 BOOST_MPL_ASSERT_RELATION (sizeof(bitfields_tags_type),<=, sizeof(key_type))
 
 BOOST_MPL_ASSERT_RELATION (sizeof(underlying_key_type),==, sizeof(bitfields_tags_type))
 
 BOOST_MPL_ASSERT_RELATION (range_mapped_types_size, >, 0)
 
 BOOST_MPL_ASSERT_RELATION (boost::mpl::empty< mapped_types >::value, !=, true)
 
constexpr bitfield_map () noexcept(true) FORCE_INLINE
 Default-construct an empty container. More...
 
constexpr bitfield_map (bitfield_map const &) noexcept(true) FORCE_INLINE
 Bit-wise copy the contents of the argument into the constructed container, out of the argument. More...
 
constexpr bitfield_map (bitfield_map &&) noexcept(true) FORCE_INLINE
 
 ~bitfield_map () noexcept(true) FORCE_INLINE
 
constexpr bitfield_mapoperator= (bitfield_map &&) noexcept(true) FORCE_INLINE
 Bit-wise swap the contents of the container with that of the argument. More...
 
constexpr bool empty () const noexcept(true) FORCE_INLINE
 Indicate if there are any elements selected in the mapped_types. More...
 
constexpr size_type size () const noexcept(true) FORCE_INLINE
 Indicate the total size of any elements selected in the mapped_types, including the size of the domain bitfield. More...
 
constexpr void clear () noexcept(true) FORCE_INLINE
 Erase each enabled mapped_types selected in the key_type. More...
 
template<bitfields_tags_type SelectedField, class AsType = typename std::integral_constant<bitfields_tags_type, SelectedField>::type, class Ret = typename boost::mpl::at<mapped_types, AsType>::type>
constexpr const Ret & at () const noexcept(false) FORCE_INLINE
 Perform a range-checked selection of the requested element. More...
 
template<bitfields_tags_type SelectedField, class AsType = typename std::integral_constant<bitfields_tags_type, SelectedField>::type, class Ret = typename boost::mpl::at<mapped_types, AsType>::type>
constexpr Ret & at () noexcept(false) FORCE_INLINE
 Perform a range-checked selection of the requested element. More...
 
template<bitfields_tags_type SelectedField, class AsType = typename std::integral_constant<bitfields_tags_type, SelectedField>::type, class Ret = typename boost::mpl::at<mapped_types, AsType>::type>
void erase () noexcept(true) FORCE_INLINE
 Remove and delete the SelectedField element, if enabled, from the mapped_types range. More...
 
template<bitfields_tags_type SelectedField>
bool find () const noexcept(true) FORCE_INLINE
 Find if the SelectedField is enabled in the key_type,. More...
 
template<bitfields_tags_type SelectedField, class AsType = typename std::integral_constant<bitfields_tags_type, SelectedField>::type, class Arg = typename boost::mpl::at<mapped_types, AsType>::type>
void push_back (Arg const &) noexcept(false) FORCE_INLINE
 Enable the SelectedField in the key_type, and initialise the appropriate element in the mapped_types, if necessary,. More...
 
constexpr void swap (bitfield_map &) noexcept(true) FORCE_INLINE
 Bit-wise swap the contents of the container with that of the argument. More...
 

Static Public Member Functions

static constexpr size_type max_size () noexcept(true) FORCE_INLINE
 Indicate the maximum size of all elements that can be selected in the mapped_types, including the size of the domain bitfield. More...
 

Public Attributes

enum jmmcg::bitfield_map:: { ... }  __attribute__
 

Detailed Description

template<class BFSM, std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
class jmmcg::bitfield_map< BFSM, BFSz >

This container is an associative collection of types. The domain is a bit-map of the mapped_types that are selected in the range.

This container packs a selection of objects of the types that are given in mapped_types into an internal buffer of contiguous memory. If few types are selected, then the size() returns much less than the size of the object (which must be large enough to holds all of the mapped_types). It could be useful for passing assorted large mapped_types along a slow network link, when, usually, not all are needed. Note that the types placed in mapped_types must be able to support arbitrary alignment - no guarantee of correct alignment is made by this class. These types are packed into the internal buffer such that there is no padding used, hence no guarantee of correct alignment. This restriction implies that only PODs are likely to be supported, in general.

Definition at line 79 of file bitfield_map.hpp.

Member Typedef Documentation

◆ bitfields_tags_type

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
using jmmcg::bitfield_map< BFSM, BFSz >::bitfields_tags_type = typename boost::mpl::deref<typename boost::mpl::begin<mapped_types>::type>::type::first::value_type

The range of enum-tags used to indicate the requested element in the mapped_types range.

Definition at line 101 of file bitfield_map.hpp.

◆ key_type

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
using jmmcg::bitfield_map< BFSM, BFSz >::key_type = uint64_t

Definition at line 98 of file bitfield_map.hpp.

◆ mapped_types

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
using jmmcg::bitfield_map< BFSM, BFSz >::mapped_types = BFSM

The range of mapped-types that may be selected by the domain. This range is a collection that is indexed by the unique enum-tag of the range.

Definition at line 100 of file bitfield_map.hpp.

◆ raw_mapped_data_t

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
using jmmcg::bitfield_map< BFSM, BFSz >::raw_mapped_data_t = std::array<uint8_t, range_mapped_types_size>

Definition at line 123 of file bitfield_map.hpp.

◆ size_type

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
using jmmcg::bitfield_map< BFSM, BFSz >::size_type = std::size_t

Definition at line 99 of file bitfield_map.hpp.

◆ underlying_key_type

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
using jmmcg::bitfield_map< BFSM, BFSz >::underlying_key_type = typename std::underlying_type<bitfields_tags_type>::type

The underlying type of the domain enum.

Definition at line 102 of file bitfield_map.hpp.

Member Enumeration Documentation

◆ anonymous enum

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
anonymous enum : std::size_t

Definition at line 113 of file bitfield_map.hpp.

◆ anonymous enum

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
anonymous enum : bool

Definition at line 129 of file bitfield_map.hpp.

Constructor & Destructor Documentation

◆ bitfield_map() [1/3]

template<class BFSM , std::size_t BFSz>
constexpr jmmcg::bitfield_map< BFSM, BFSz >::bitfield_map ( )
inlineconstexprnoexcept

Default-construct an empty container.

Algorithmic complexity: O(1) Post-condition: empty()==true.

Definition at line 313 of file bitfield_map_impl.hpp.

◆ bitfield_map() [2/3]

template<class BFSM , std::size_t BFSz>
constexpr jmmcg::bitfield_map< BFSM, BFSz >::bitfield_map ( bitfield_map< BFSM, BFSz > const &  bm)
inlineconstexprnoexcept

Bit-wise copy the contents of the argument into the constructed container, out of the argument.

Algorithmic complexity: O(sizeof(range of mapped_types)) Post-condition: bm.empty()==true.

Definition at line 341 of file bitfield_map_impl.hpp.

◆ bitfield_map() [3/3]

template<class BFSM , std::size_t BFSz>
constexpr jmmcg::bitfield_map< BFSM, BFSz >::bitfield_map ( bitfield_map< BFSM, BFSz > &&  bm)
inlineconstexprnoexcept

Algorithmic complexity: O(sizeof(range of mapped_types)) Post-condition: bm.empty()==true.

Definition at line 349 of file bitfield_map_impl.hpp.

◆ ~bitfield_map()

template<class BFSM , std::size_t BFSz>
jmmcg::bitfield_map< BFSM, BFSz >::~bitfield_map ( )
inlinenoexcept

Algorithmic complexity: POD: O(1) otherwise O(sizeof(key_type)^2)

See also
clear()

Definition at line 368 of file bitfield_map_impl.hpp.

Member Function Documentation

◆ at() [1/2]

template<class BFSM , std::size_t BFSz>
template<typename bitfield_map< BFSM, BFSz >::bitfields_tags_type SelectedField, class AsType , class Ret >
constexpr const Ret & jmmcg::bitfield_map< BFSM, BFSz >::at ( ) const
inlineconstexprnoexcept

Perform a range-checked selection of the requested element.

Algorithmic complexity: O(sizeof(key_type)) Pre-condition: empty()==false.

Returns
Return a reference to the enabled SelectedField in the mapped_types, otherwise throw a std::range_error exception..

Definition at line 405 of file bitfield_map_impl.hpp.

◆ at() [2/2]

template<class BFSM , std::size_t BFSz>
template<typename bitfield_map< BFSM, BFSz >::bitfields_tags_type SelectedField, class AsType , class Ret >
constexpr Ret & jmmcg::bitfield_map< BFSM, BFSz >::at ( )
inlineconstexprnoexcept

Perform a range-checked selection of the requested element.

Algorithmic complexity: O(sizeof(key_type)) Pre-condition: empty()==false.

Returns
Return a reference to the enabled SelectedField in the mapped_types, otherwise throw a std::range_error exception..

Definition at line 412 of file bitfield_map_impl.hpp.

◆ BOOST_MPL_ASSERT() [1/2]

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
jmmcg::bitfield_map< BFSM, BFSz >::BOOST_MPL_ASSERT ( (std::is_integral< typename std::underlying_type< bitfields_tags_type >::type >)  )

Make sure the funky mpl actually finds something that is integral so could be an enumeration...

◆ BOOST_MPL_ASSERT() [2/2]

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
jmmcg::bitfield_map< BFSM, BFSz >::BOOST_MPL_ASSERT ( (std::is_pod< bitfields_tags_type >)  )

Make sure the funky mpl actually finds something that is POD-like so could be an enumeration...

◆ BOOST_MPL_ASSERT_RELATION() [1/4]

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
jmmcg::bitfield_map< BFSM, BFSz >::BOOST_MPL_ASSERT_RELATION ( boost::mpl::empty< mapped_types >::value  ,
,
true   
)

◆ BOOST_MPL_ASSERT_RELATION() [2/4]

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
jmmcg::bitfield_map< BFSM, BFSz >::BOOST_MPL_ASSERT_RELATION ( range_mapped_types_size  ,
 
)

◆ BOOST_MPL_ASSERT_RELATION() [3/4]

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
jmmcg::bitfield_map< BFSM, BFSz >::BOOST_MPL_ASSERT_RELATION ( sizeof(bitfields_tags_type ,
<=  ,
sizeof(key_type  
)

◆ BOOST_MPL_ASSERT_RELATION() [4/4]

template<class BFSM , std::size_t BFSz = sizeof(typename std::underlying_type<typename boost::mpl::deref<typename boost::mpl::begin<BFSM>::type>::type::first::value_type>::type)>
jmmcg::bitfield_map< BFSM, BFSz >::BOOST_MPL_ASSERT_RELATION ( sizeof(underlying_key_type ,
sizeof(bitfields_tags_type  
)

◆ clear()

template<class BFSM , std::size_t BFSz>
constexpr void jmmcg::bitfield_map< BFSM, BFSz >::clear ( )
inlineconstexprnoexcept

Erase each enabled mapped_types selected in the key_type.

Algorithmic complexity: POD: O(1) otherwise O(sizeof(key_type)^2) Post-condition: empty()==true.

Definition at line 357 of file bitfield_map_impl.hpp.

◆ empty()

template<class BFSM , std::size_t BFSz>
constexpr bool jmmcg::bitfield_map< BFSM, BFSz >::empty ( ) const
inlineconstexprnoexcept

Indicate if there are any elements selected in the mapped_types.

Algorithmic complexity: O(1) Invariant: emply() iff size()==0

Returns
true if no types have been selected in the mapped_types, otherwise false.

Definition at line 381 of file bitfield_map_impl.hpp.

◆ erase()

template<class BFSM , std::size_t BFSz>
template<typename bitfield_map< BFSM, BFSz >::bitfields_tags_type SelectedField, class AsType , class Ret >
void jmmcg::bitfield_map< BFSM, BFSz >::erase ( )
inlinenoexcept

Remove and delete the SelectedField element, if enabled, from the mapped_types range.

Note: this is not a generic erase, items should only be erased from the end of the collection, otherwise undefined behaviour will result. This should really be considered a pop_back() operation, where the end iterator is manually specified. Not ideal. No compaction of the mapped_types is performed after an erase, so if holes were left, this would cause the at() operations to behave incorrectly. Algorithmic complexity: POD: O(1) otherwise O(sizeof(key_type)) Pre-condition: SelectedField is the last enabled bit in the key_type.

See also
push_back()

Definition at line 419 of file bitfield_map_impl.hpp.

◆ find()

template<class BFSM , std::size_t BFSz>
template<typename bitfield_map< BFSM, BFSz >::bitfields_tags_type SelectedField>
bool jmmcg::bitfield_map< BFSM, BFSz >::find ( ) const
inlinenoexcept

Find if the SelectedField is enabled in the key_type,.

Algorithmic complexity: O(1)

Returns
True if the SelectedField is enabled in the key_type, otherwise false.

Definition at line 431 of file bitfield_map_impl.hpp.

◆ max_size()

template<class BFSM , std::size_t BFSz>
constexpr bitfield_map< BFSM, BFSz >::size_type jmmcg::bitfield_map< BFSM, BFSz >::max_size ( )
inlinestaticconstexprnoexcept

Indicate the maximum size of all elements that can be selected in the mapped_types, including the size of the domain bitfield.

Algorithmic complexity: O(1) Invariant: size()<=max_size()

Returns
At least the size, in bytes, of all of the types have can be selected in the mapped_types.
See also
size()

Definition at line 398 of file bitfield_map_impl.hpp.

◆ operator=()

template<class BFSM , std::size_t BFSz>
constexpr bitfield_map< BFSM, BFSz > & jmmcg::bitfield_map< BFSM, BFSz >::operator= ( bitfield_map< BFSM, BFSz > &&  bm)
inlineconstexprnoexcept

Bit-wise swap the contents of the container with that of the argument.

Algorithmic complexity: O(sizeof(range of mapped_types))

See also
swap()

Definition at line 374 of file bitfield_map_impl.hpp.

◆ push_back()

template<class BFSM , std::size_t BFSz>
template<typename bitfield_map< BFSM, BFSz >::bitfields_tags_type SelectedField, class AsType , class Arg >
void jmmcg::bitfield_map< BFSM, BFSz >::push_back ( Arg const &  arg)
inlinenoexcept

Enable the SelectedField in the key_type, and initialise the appropriate element in the mapped_types, if necessary,.

Note: This only works going from smaller to larger tags in the key_type, one must not insert in the middle, otherwise this may result in undefined behaviour. This is because of the internally-computed offsets into the range of mapped_types. Hence one must not insert randomly: it is likely that existing contents will be incorrectly overwritten, also leading to undefined behaviour. Algorithmic complexity: O(sizeof(key_type)) Post-condition: empty()==false.

Returns
A reference to the initialised element in the mapped_types.

Definition at line 442 of file bitfield_map_impl.hpp.

◆ size()

template<class BFSM , std::size_t BFSz>
constexpr bitfield_map< BFSM, BFSz >::size_type jmmcg::bitfield_map< BFSM, BFSz >::size ( ) const
inlineconstexprnoexcept

Indicate the total size of any elements selected in the mapped_types, including the size of the domain bitfield.

Algorithmic complexity: O(sizeof(key_type)) Invariant: size()<=max_size()

Returns
The size, in bytes, of the types have been selected in the mapped_types, otherwise 0, always less than or equal to the sum of the sizes of the types in mapped_types, range_mapped_types_size.
See also
max_size()

Definition at line 387 of file bitfield_map_impl.hpp.

◆ swap()

template<class BFSM , std::size_t BFSz>
constexpr void jmmcg::bitfield_map< BFSM, BFSz >::swap ( bitfield_map< BFSM, BFSz > &  bm)
inlineconstexprnoexcept

Bit-wise swap the contents of the container with that of the argument.

Algorithmic complexity: O(sizeof(range of mapped_types))

Definition at line 332 of file bitfield_map_impl.hpp.

Member Data Documentation

◆ __attribute__

enum { ... } jmmcg::bitfield_map< BFSM, BFSz >::__attribute__

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