Project
Loading...
Searching...
No Matches
HistogramInterface.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_HISTOGRAMINTERFACE_H_
17#define RANS_INTERNAL_CONTAINERS_HISTOGRAMINTERFACE_H_
18
19#include <gsl/span>
20
22
23namespace o2::rans::internal
24{
25
26template <class source_T, class value_T, class difference_T, class derived_T>
28{
29
30 public:
32 using value_type = value_T;
33 using difference_type = difference_T;
34
35 // operations
36 template <typename source_IT>
37 inline derived_T& addSamples(source_IT begin, source_IT end)
38 {
39 static_assert(utils::isCompatibleIter_v<source_type, source_IT>);
40
41 if (begin == end) {
42 return static_cast<derived_T&>(*this);
43 } else {
44 return static_cast<derived_T*>(this)->addSamples(begin, end);
45 }
46 };
47
48 inline derived_T& addSamples(gsl::span<const source_type> samples)
49 {
50 return addSamples(samples.data(), samples.data() + samples.size());
51 };
52
53 template <typename freq_IT>
54 inline derived_T& addFrequencies(freq_IT begin, freq_IT end, difference_type offset)
55 {
56 static_assert(utils::isCompatibleIter_v<value_type, freq_IT>);
57
58 if (begin == end) {
59 return static_cast<derived_T&>(*this);
60 } else {
61 return static_cast<derived_T*>(this)->addFrequencies(begin, end, offset);
62 }
63 };
64
65 inline derived_T& addFrequencies(gsl::span<const value_type> frequencies, difference_type offset)
66 {
67 return addFrequencies(frequencies.data(), frequencies.data() + frequencies.size(), offset);
68 };
69
70 derived_T& operator+(derived_T& other)
71 {
72 return addFrequencies(other.cbegin(), other.cbegin(), other.getOffset());
73 };
74
75 protected:
76 HistogramInterface() = default;
77
78 template <typename freq_IT>
80 {
81 static_assert(utils::isIntegralIter_v<freq_IT>);
82 addFrequencies(begin, end, offset);
83 };
84};
85
86} // namespace o2::rans::internal
87
88#endif /* RANS_INTERNAL_CONTAINERS_HISTOGRAMINTERFACE_H_ */
common helper classes and functions
derived_T & addFrequencies(freq_IT begin, freq_IT end, difference_type offset)
derived_T & operator+(derived_T &other)
derived_T & addFrequencies(gsl::span< const value_type > frequencies, difference_type offset)
derived_T & addSamples(source_IT begin, source_IT end)
HistogramInterface(freq_IT begin, freq_IT end, difference_type offset)
derived_T & addSamples(gsl::span< const source_type > samples)
GLuint GLuint end
Definition glcorearb.h:469
GLintptr offset
Definition glcorearb.h:660
VectorOfTObjectPtrs other