Project
Loading...
Searching...
No Matches
HistogramConcept.h
Go to the documentation of this file.
1// Copyright 2019-2023 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef RANS_INTERNAL_CONTAINERS_HISTOGRAMCONCEPT_H_
17#define RANS_INTERNAL_CONTAINERS_HISTOGRAMCONCEPT_H_
18
19#include <gsl/span>
20
22
23namespace o2::rans::internal
24{
25
26template <typename source_T, typename value_T, typename difference_T, class derived_T>
28{
29 friend derived_T;
30
31 public:
33 using value_type = value_T;
34 using difference_type = difference_T;
35
36 // operations
37 template <typename source_IT>
38 inline derived_T& addSamples(source_IT begin, source_IT end)
39 {
40 static_assert(utils::isCompatibleIter_v<source_type, source_IT>);
41
42 if (begin == end) {
43 return static_cast<derived_T&>(*this);
44 } else {
45 return static_cast<derived_T*>(this)->addSamplesImpl(begin, end);
46 }
47 };
48
49 inline derived_T& addSamples(gsl::span<const source_type> samples)
50 {
51 return addSamples(samples.data(), samples.data() + samples.size());
52 };
53
54 template <typename freq_IT>
55 inline derived_T& addFrequencies(freq_IT begin, freq_IT end, difference_type offset)
56 {
57 static_assert(utils::isCompatibleIter_v<value_type, freq_IT>);
58
59 if (begin == end) {
60 return static_cast<derived_T&>(*this);
61 } else {
62 return static_cast<derived_T*>(this)->addFrequenciesImpl(begin, end, offset);
63 }
64 };
65
66 inline derived_T& addFrequencies(gsl::span<const value_type> frequencies, difference_type offset)
67 {
68 return addFrequencies(frequencies.data(), frequencies.data() + frequencies.size(), offset);
69 };
70
71 derived_T& operator+(derived_T& other)
72 {
73 return addFrequencies(other.cbegin(), other.cbegin(), other.getOffset());
74 };
75
76 protected:
77 HistogramConcept() = default;
78
79 template <typename freq_IT>
80 HistogramConcept(freq_IT begin, freq_IT end, difference_type offset)
81 {
82 static_assert(utils::isIntegralIter_v<freq_IT>);
83 addFrequencies(begin, end, offset);
84 };
85};
86
87} // namespace o2::rans::internal
88
89#endif /* RANS_INTERNAL_CONTAINERS_HISTOGRAMCONCEPT_H_ */
common helper classes and functions
derived_T & addFrequencies(gsl::span< const value_type > frequencies, difference_type offset)
derived_T & addFrequencies(freq_IT begin, freq_IT end, difference_type offset)
derived_T & addSamples(source_IT begin, source_IT end)
derived_T & addSamples(gsl::span< const source_type > samples)
derived_T & operator+(derived_T &other)
HistogramConcept(freq_IT begin, freq_IT end, difference_type offset)
GLuint GLuint end
Definition glcorearb.h:469
GLintptr offset
Definition glcorearb.h:660
VectorOfTObjectPtrs other