10 #ifndef LARDATAALG_UTILITIES_MAPPEDCONTAINER_H 11 #define LARDATAALG_UTILITIES_MAPPEDCONTAINER_H 45 template <
typename T = std::
size_t>
122 template <
typename Cont,
typename Mapping>
144 std::remove_cv_t<Value_t> fDefValue {};
147 template <
typename Container,
typename Reference>
181 using iterator = IteratorBase<MappedContainer_t, reference>;
183 = IteratorBase<MappedContainer_t const, const_reference>;
218 : fData(cont), fMapping(mapping), fSize(size), fDefValue(defValue)
333 {
return map_element(index); }
335 {
return map_element(index); }
355 decltype(
auto) front()
const {
return map_element(0U); }
356 decltype(
auto) front() {
return map_element(0U); }
364 decltype(
auto) back()
const {
return map_element(
size() - 1); }
365 decltype(
auto) back() {
return map_element(
size() - 1); }
440 template <
typename Cont,
typename Mapping>
459 template <
typename T>
460 T&
NullRef() {
T* nullTptr =
nullptr;
return *nullTptr; }
466 template <
typename Cont>
487 decltype(
auto) container()
const 489 decltype(
auto) container()
495 {
return container()[
index]; }
497 {
return container()[
index]; }
503 template <
typename Cont,
typename >
509 using Base_t::Base_t;
514 template <
typename Cont>
516 <Cont,
std::enable_if_t<util::is_reference_wrapper_v<Cont>>>
524 using Base_t::Base_t;
546 template <
typename Cont,
typename Mapping>
547 template <
typename Container,
typename Reference>
565 using value_type = std::remove_cv_t<typename Container_t::value_type>;
569 using pointer = decltype(&std::declval<reference>());
581 : fCont(&cont), fIndex(index)
588 template <
typename OC,
typename OR>
590 : fCont(from.cont), fIndex(from.
index)
597 template <
typename OC,
typename OR>
599 { fCont = from.
fCont; fIndex = from.
fIndex;
return *
this; }
614 {
return (*fCont)[fIndex +
n]; }
643 {
auto it = *
this; it +=
n;
return it; }
647 {
auto it = *
this; it -=
n;
return it; }
651 {
return fIndex - other.
fIndex; }
661 template <
typename OC,
typename OR>
663 {
return (fCont == other.
fCont) && (fIndex == other.
fIndex); }
666 template <
typename OC,
typename OR>
668 {
return (fCont != other.
fCont) || (fIndex != other.
fIndex); }
671 template <
typename OC,
typename OR>
672 bool operator<= (IteratorBase<OC, OR>
const&
other)
const 673 {
return (fCont ==
other.fCont) && (fIndex <=
other.fIndex); }
676 template <
typename OC,
typename OR>
677 bool operator< (IteratorBase<OC, OR>
const&
other)
const 678 {
return (fCont ==
other.fCont) && (fIndex <
other.fIndex); }
681 template <
typename OC,
typename OR>
683 {
return (fCont == other.
fCont) && (fIndex >= other.
fIndex); }
686 template <
typename OC,
typename OR>
688 {
return (fCont == other.
fCont) && (fIndex > other.
fIndex); }
698 typename Cont,
typename Mapping,
699 typename Container,
typename Reference
718 template <
typename Cont>
729 template <
typename T>
742 template <
typename Cont>
745 std::remove_reference_t<
746 util::collection_from_reference_t<
747 util::strip_referenceness_t<Cont>
762 template <
typename Cont,
typename Mapping>
768 template <
typename Cont,
typename Mapping>
772 auto const dataIndex = map_index(index);
773 return (dataIndex == InvalidIndex)? defaultValue(): fData[dataIndex];
778 template <
typename Cont,
typename Mapping>
782 auto const dataIndex = map_index(index);
783 return (dataIndex == InvalidIndex)? defaultValue(): fData[dataIndex];
788 template <
typename Cont,
typename Mapping>
792 if (index >=
size()) {
793 throw std::out_of_range(
794 "MappedContainer::at(" +
std::to_string(index) +
"): out of range (size: " 798 return map_element(index);
803 template <
typename Cont,
typename Mapping>
807 if (index >=
size()) {
808 throw std::out_of_range(
809 "MappedContainer::at(" +
std::to_string(index) +
"): out of range (size: " 813 return map_element(index);
818 template <
typename Cont,
typename Mapping>
834 template <
typename Cont,
typename Mapping>
837 {
return fMapping[
index]; }
841 template <
typename Cont,
typename Mapping>
844 {
return fMapping[
index]; }
850 #endif // LARDATAALG_UTILITIES_MAPPEDCONTAINER_H MappedContainer< Cont, Mapping >::template IteratorBase< Container, Reference > operator+(typename MappedContainer< Cont, Mapping >::template IteratorBase< Container, Reference >::difference_type n, typename MappedContainer< Cont, Mapping >::template IteratorBase< Container, Reference > const &it)
auto mapContainer(Cont cont, Mapping mapping)
Returns a container-like object mapping the content of cont.
Namespace for general, non-LArSoft-specific utilities.
typename Storage_t::value_type Value_t
Type of contained value.
IteratorBase(IteratorBase< OC, OR > const &from)
Copy constructor: from a different container type.
std::ptrdiff_t difference_type
MappingIndex_t fIndex
Current index in container.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::iterator iterator
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
A meta-container providing transparent mapping on top of another.
Mapping Mapping_t
Type of the mapping object.
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Iterator_t & operator--()
Decrements this iterator and returns it decremented.
const_reference defaultValue() const
IteratorBase< MappedContainer_t, reference > iterator
size_type minimal_size() const
Returns the minimum size to include all mapped values.
std::size_t MappingIndex_t
Type of the index passed to the mapping.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::size_type size_type
reference operator*() const
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::reference reference
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::const_reference const_reference
ContainerStorageBase(Container_t const &cont)
const_iterator cbegin() const
Returns a constant iterator to the first mapped element.
size_type size() const
Returns the nominal size of the container (after mapping).
std::remove_cv_t< typename Container_t::value_type > value_type
Iterator_t operator++(int)
Increments this iterator and returns its old value.
Iterator_t operator--(int)
Decrements this iterator and returns its old value.
const_iterator begin() const
Returns a constant iterator to the first mapped element.
static constexpr T invalidIndex()
Non-template base class for MappedContainer.
util::with_const_as_t< typename Storage_t::reference, util::collection_value_access_t< DataContainer_t > > reference
T const & const_reference
typename Container_t::size_type size_type
void setDefaultValue(value_type defValue)
IteratorBase(Container_t &cont, MappingIndex_t index)
Constructor: iterator pointing to element index of cont.
QuadExpr operator-(double v, const QuadExpr &e)
ContainerStorageBase(Container_t &&cont)
typename Traits_t::size_type index_type
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
std::ptrdiff_t difference_type
typename Cont::type DataContainer_t
iterator end()
Returns an iterator past the last mapped element.
Iterator_t & operator++()
decltype(auto) map_index(MappingIndex_t index) const
Returns the index in the original data which is mapped to index.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::difference_type difference_type
typename Container_t::difference_type difference_type
phot::IPhotonLibrary::T0s_t DataContainer_t
Type of the original container.
const_iterator cend() const
Returns a constant iterator past the last mapped element.
static int max(int a, int b)
typename Traits_t::reference reference
typename Traits_t::const_reference const_reference
decltype(auto) map_element(MappingIndex_t index)
Returns the value mapped to the specified index.
decltype(&std::declval< reference >()) pointer
IteratorBase< MappedContainer_t const, const_reference > const_iterator
iterator begin()
Returns an iterator to the first mapped element.
decltype(auto) container() const
MappingStorage_t fMapping
Mapping of stored data into final one.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::value_type value_type
MappedContainer(DataContainer_t const &cont, Mapping_t const &mapping)
Constructor: acquires data and mapping.
const_iterator end() const
Returns a constant iterator past the last mapped element.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::const_iterator const_iterator
std::vector< size_t > Mapping(std::vector< geo::AuxDetGeo * > &adgeo)
typename Traits_t::size_type size_type
util::collection_value_t< Mapping_t > DataIndex_t
Type of the index passed to the original container.
size_type max_size() const
Returns the size of the largest possible container of this type.
Container_t * fCont
Pointer to the container.
bool empty() const
Returns whether the container has no elements.
std::input_iterator_tag iterator_category
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
bool operator!=(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
Never admit a infinite_endcount_iterator to be equal to anything else.
Storage_t fData
Data to be mapped.
decltype(auto) at(MappingIndex_t index) const
Returns the content corresponding to the specified index.
reference defaultValue()
Returns the default value for elements with no original content.
MappedContainer(DataContainer_t const &cont, Mapping_t const &mapping, size_type size, value_type defValue)
Constructor: acquires data, mapping and a default value.
typename Storage_t::const_reference const_reference
bool operator>(const VectorMap< _Key, _Tp, _Compare > &__x, const VectorMap< _Key, _Tp, _Compare > &__y)
Based on operator<.
QuadExpr operator*(double v, const QuadExpr &e)
bool operator==(infinite_endcount_iterator< T > const &, count_iterator< T > const &)
std::string to_string(ModuleType const mt)
typename Traits_t::value_type value_type
reference operator->() const
Returns a member of the mapped item the iterator currently points to.
bool operator>=(const VectorMap< _Key, _Tp, _Compare > &__x, const VectorMap< _Key, _Tp, _Compare > &__y)
Based on operator<.
typename Traits_t::difference_type difference_type
std::size_t Size_t
Type for describing container size.