Project
Loading...
Searching...
No Matches
FlattenRestore.h
Go to the documentation of this file.
1// Copyright 2019-2020 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
12#ifndef FLATTERRESTORE_H
13#define FLATTERRESTORE_H
14
19
20#include <type_traits>
21
22namespace o2::algorithm
23{
24namespace flatten
25{
26
37template <typename ValueType, typename... Args>
38constexpr size_t value_size(ValueType const& value, Args&&... args)
39{
40 size_t size = sizeof(typename std::remove_pointer<typename std::remove_reference<ValueType>::type>::type);
41 if constexpr (sizeof...(Args) > 0) {
42 size += value_size(std::forward<Args>(args)...);
43 }
44 return size;
45}
46
53template <typename TargetType, typename ValueType, typename... Args>
54static size_t copy_to(TargetType& wrtptr, size_t count, ValueType* array, Args&&... args)
55{
56 static_assert(std::is_pointer<TargetType>::value == true, "need reference to pointer");
57 static_assert(sizeof(typename std::remove_pointer<TargetType>::type) == 1, "need char-like pointer");
58
59 size_t copySize = 0;
60 if (array != nullptr) {
61 copySize = count * value_size(array);
62 memcpy(wrtptr, array, copySize);
63 wrtptr += copySize;
64 } else if (count > 0) {
65 throw std::runtime_error("invalid nullptr to array of " + std::to_string(count) + " element(s)");
66 }
67 if constexpr (sizeof...(Args) > 0) {
68 copySize += copy_to(wrtptr, count, std::forward<Args>(args)...);
69 }
70 return copySize;
71}
72
81template <typename BufferType, typename ValueType, typename... Args>
82static size_t set_from(BufferType& readptr, size_t count, ValueType& array, Args&&... args)
83{
84 static_assert(std::is_pointer<typename std::remove_reference<ValueType>::type>::value == true, "need reference to pointer");
85 array = reinterpret_cast<typename std::remove_reference<ValueType>::type>(readptr);
86 size_t readSize = count * value_size(array);
87 readptr += readSize;
88 if constexpr (sizeof...(Args) > 0) {
89 readSize += set_from(readptr, count, std::forward<Args>(args)...);
90 }
91 return readSize;
92}
93
101template <typename BufferType, typename... Args>
102static size_t calc_size(BufferType const& dummyptr, size_t count, Args&&... args)
103{
104 return count * value_size(std::forward<Args>(args)...);
105}
106
107} // namespace flatten
108} // namespace o2::algorithm
109
110#endif
GLint GLsizei count
Definition glcorearb.h:399
GLsizeiptr size
Definition glcorearb.h:659
GLenum array
Definition glcorearb.h:4274
GLsizei const GLfloat * value
Definition glcorearb.h:819
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
constexpr size_t value_size(ValueType const &value, Args &&... args)
uint8_t BufferType
This is the type of the vector to be used for the EncodedBlocks buffer allocation.
std::string to_string(gsl::span< T, Size > span)
Definition common.h:52