libjmmcg
release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
|
#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"
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_map & | operator= (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 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.
using key_type = uint64_t |
Definition at line 1 of file bitfield_map.hpp.
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.
using raw_mapped_data_t = std::array<uint8_t, range_mapped_types_size> |
Definition at line 26 of file bitfield_map.hpp.
typedef typename Header_t::size_type size_type |
Definition at line 2 of file bitfield_map.hpp.
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.
anonymous enum : std::size_t |
Definition at line 16 of file bitfield_map.hpp.
anonymous enum : bool |
Definition at line 32 of file bitfield_map.hpp.
|
constexprnoexcept |
Perform a range-checked selection of the requested element.
Algorithmic complexity: O(sizeof(key_type)) Pre-condition: empty()==false.
|
constexprnoexcept |
Perform a range-checked selection of the requested element.
Algorithmic complexity: O(sizeof(key_type)) Pre-condition: empty()==false.
|
constexprnoexcept |
Default-construct an empty container.
Algorithmic complexity: O(1) Post-condition: empty()==true.
|
constexprnoexcept |
Algorithmic complexity: O(sizeof(range of mapped_types)) Post-condition: bm.empty()==true.
|
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.
__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...
__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...
__attribute__::BOOST_MPL_ASSERT_RELATION | ( | boost::mpl::empty< mapped_types >::value | , |
! | , | ||
true | |||
) |
__attribute__::BOOST_MPL_ASSERT_RELATION | ( | range_mapped_types_size | , |
0 | |||
) |
__attribute__::BOOST_MPL_ASSERT_RELATION | ( | sizeof(bitfields_tags_type) | , |
<= | , | ||
sizeof(key_type) | |||
) |
__attribute__::BOOST_MPL_ASSERT_RELATION | ( | sizeof(underlying_key_type) | , |
sizeof(bitfields_tags_type) | |||
) |
|
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.
|
constexprnoexcept |
Indicate if there are any elements selected in the mapped_types.
Algorithmic complexity: O(1) Invariant: emply() iff size()==0
|
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.
|
noexcept |
Find if the SelectedField is enabled in the key_type,.
Algorithmic complexity: O(1)
|
constexprnoexcept |
Bit-wise swap the contents of the container with that of the argument.
Algorithmic complexity: O(sizeof(range of mapped_types))
|
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.
|
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()
|
constexprnoexcept |
Bit-wise swap the contents of the container with that of the argument.
Algorithmic complexity: O(sizeof(range of mapped_types))
|
noexcept |
Algorithmic complexity: POD: O(1) otherwise O(sizeof(key_type)^2)