10 #ifndef LARDATAALG_UTILITIES_MAPPEDCONTAINER_H
11 #define LARDATAALG_UTILITIES_MAPPEDCONTAINER_H
45 template <
typename T = std::
size_t>
46 static constexpr T
invalidIndex() {
return std::numeric_limits<T>::max(); }
122 template <
typename Cont,
typename Mapping>
147 template <
typename Container,
typename Reference>
181 using iterator = IteratorBase<MappedContainer_t, reference>;
183 = IteratorBase<MappedContainer_t const, const_reference>;
440 template <typename Cont, typename Mapping>
459 template <
typename T>
460 T&
NullRef() { T* nullTptr =
nullptr;
return *nullTptr; }
466 template <
typename Cont>
485 : fCont(
std::move(cont)) {}
487 decltype(
auto) container()
const
489 decltype(
auto) container()
495 {
return container()[index]; }
497 {
return container()[index]; }
503 template <
typename Cont,
typename >
504 class ContainerStorage:
public ContainerStorageBase<Cont> {
509 using Base_t::Base_t;
514 template <
typename 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)
594 Iterator_t& operator= (Iterator_t
const&) =
default;
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
714 namespace util::details {
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>
764 {
return minimal_size(fData.container(), fMapping.container()); }
768 template <
typename Cont,
typename Mapping>
770 (MappingIndex_t index)
const
772 auto const dataIndex = map_index(index);
773 return (dataIndex == InvalidIndex)? defaultValue(): fData[dataIndex];
778 template <
typename Cont,
typename Mapping>
779 decltype(
auto) util::MappedContainer<Cont, Mapping>::map_element
780 (MappingIndex_t index)
782 auto const dataIndex = map_index(index);
783 return (dataIndex == InvalidIndex)? defaultValue(): fData[dataIndex];
788 template <
typename Cont,
typename Mapping>
789 decltype(
auto) util::MappedContainer<Cont, Mapping>::at
790 (MappingIndex_t index)
const
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>
804 decltype(
auto) util::MappedContainer<Cont, Mapping>::at
805 (MappingIndex_t index)
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>
820 (DataContainer_t
const&, Mapping_t
const& mapping) -> size_type
834 template <
typename Cont,
typename Mapping>
835 decltype(
auto) util::MappedContainer<Cont, Mapping>::map_index
836 (MappingIndex_t index)
const
837 {
return fMapping[index]; }
841 template <
typename Cont,
typename Mapping>
842 decltype(
auto) util::MappedContainer<Cont, Mapping>::map_index
843 (MappingIndex_t index)
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)
typename Cont::type DataContainer_t
auto mapContainer(Cont cont, Mapping mapping)
Returns a container-like object mapping the content of cont.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
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
bool operator==(TensorIndices< RANK1 > const &a, TensorIndices< RANK2 > const &b)
Comparison operator with tensors of different rank.
MappingIndex_t fIndex
Current index in container.
std::remove_cv_t< Value_t > fDefValue
< Value returned for elements not mapped.
typename std::remove_reference_t< util::collection_from_reference_t< util::strip_referenceness_t< Cont > > >::iterator iterator
A meta-container providing transparent mapping on top of another.
Mapping Mapping_t
Type of the mapping object.
Iterator_t & operator--()
Decrements this iterator and returns it decremented.
const_reference defaultValue() const
IteratorBase< MappedContainer_t, reference > iterator
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
decltype(auto) back() const
Returns the last element in the container.
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.
MappedContainer()=default
Default constructor: container will be unusable until assigned to.
std::size_t size(FixedBins< T, C > const &) noexcept
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
static size_type minimal_size(DataContainer_t const &cont, Mapping_t const &mapping)
Returns the minimum size to include all mapped values.
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
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 std::enable_if< B, T >::type enable_if_t
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.
String & operator+=(String &s, VectorDumper< Vector > const &manip)
Appends a string rendering of a vector to the specified string.
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.
Size_t fSize
Nominal size of the container.
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
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
typename Traits_t::size_type size_type
std::string to_string(WindowPattern const &pattern)
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
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)
static constexpr DataIndex_t InvalidIndex
bool operator!=(TensorIndices< RANK1 > const &a, TensorIndices< RANK2 > const &b)
Comparison operator with tensors of different rank.
decltype(auto) front() const
Returns the first element in the container.
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.