libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
bitfield_map.hpp File Reference
#include "bit_fiddling.hpp"
#include "count_setbits.hpp"
#include "memops.hpp"
#include "sizeof_void.hpp"
#include <boost/mpl/accumulate.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/begin.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/not.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/size.hpp>
#include <boost/mpl/sizeof.hpp>
#include <boost/mpl/transform_view.hpp>
#include <cassert>
#include <limits>
#include <cstdint>
#include <sstream>
#include <stdexcept>
#include <type_traits>
#include "bitfield_map_impl.hpp"
Include dependency graph for bitfield_map.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  jmmcg::LIBJMMCG_VER_NAMESPACE::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. More...
 

Namespaces

namespace  jmmcg
 Link with -lrt to include these functions.
 
namespace  jmmcg::LIBJMMCG_VER_NAMESPACE
 

Typedefs

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 >
 

Enumerations

enum  : std::size_t
 
enum  : bool
 

Functions

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::LIBJMMCG_VER_NAMESPACE::bitfield_map jmmcg::LIBJMMCG_VER_NAMESPACE::__attribute__ ((packed))
 
 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...
 

Typedef Documentation

◆ bitfields_tags_type

typedef bitfields_to_type_map::bitfields_tags_type bitfields_tags_type

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

Definition at line 4 of file bitfield_map.hpp.

◆ key_type

using key_type = uint64_t

Definition at line 1 of file bitfield_map.hpp.

◆ mapped_types

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.

Definition at line 3 of file bitfield_map.hpp.

◆ raw_mapped_data_t

using raw_mapped_data_t = std::array<uint8_t, range_mapped_types_size>

Definition at line 26 of file bitfield_map.hpp.

◆ size_type

typedef typename Header_t::size_type size_type

Definition at line 2 of file bitfield_map.hpp.

◆ underlying_key_type

using underlying_key_type = typename std::underlying_type<bitfields_tags_type>::type

The underlying type of the domain enum.

Definition at line 5 of file bitfield_map.hpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : std::size_t

Definition at line 16 of file bitfield_map.hpp.

◆ anonymous enum

anonymous enum : bool

Definition at line 32 of file bitfield_map.hpp.

Function Documentation

◆ at() [1/2]

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& __attribute__::at ( ) const
constexprnoexcept

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..

◆ at() [2/2]

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& __attribute__::at ( )
constexprnoexcept

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..

◆ bitfield_map() [1/3]

constexpr __attribute__::bitfield_map ( )
constexprnoexcept

Default-construct an empty container.

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

◆ bitfield_map() [2/3]

constexpr __attribute__::bitfield_map ( bitfield_map &&  )
constexprnoexcept

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

◆ bitfield_map() [3/3]

constexpr __attribute__::bitfield_map ( bitfield_map const &  )
constexprnoexcept

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.

◆ BOOST_MPL_ASSERT() [1/2]

__attribute__::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]

__attribute__::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]

__attribute__::BOOST_MPL_ASSERT_RELATION ( boost::mpl::empty< mapped_types >::value  ,
,
true   
)

◆ BOOST_MPL_ASSERT_RELATION() [2/4]

__attribute__::BOOST_MPL_ASSERT_RELATION ( range_mapped_types_size  ,
 
)

◆ BOOST_MPL_ASSERT_RELATION() [3/4]

__attribute__::BOOST_MPL_ASSERT_RELATION ( sizeof(bitfields_tags_type ,
<=  ,
sizeof(key_type  
)

◆ BOOST_MPL_ASSERT_RELATION() [4/4]

__attribute__::BOOST_MPL_ASSERT_RELATION ( sizeof(underlying_key_type ,
sizeof(bitfields_tags_type  
)

◆ clear()

constexpr void __attribute__::clear ( )
constexprnoexcept

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.

◆ empty()

constexpr bool __attribute__::empty ( ) const
constexprnoexcept

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.

◆ erase()

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 __attribute__::erase ( )
noexcept

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()

◆ find()

template<bitfields_tags_type SelectedField>
bool __attribute__::find ( ) const
noexcept

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.

◆ operator=()

constexpr bitfield_map& __attribute__::operator= ( bitfield_map &&  )
constexprnoexcept

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

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

See also
swap()

◆ push_back()

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 __attribute__::push_back ( Arg const &  )
noexcept

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.

◆ size()

constexpr size_type __attribute__::size ( ) const
constexprnoexcept

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()

◆ swap()

constexpr void __attribute__::swap ( bitfield_map )
constexprnoexcept

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

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

◆ ~bitfield_map()

__attribute__::~bitfield_map ( )
noexcept

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

See also
clear()