CoDiPack  2.2.0
A Code Differentiation Package
SciComp TU Kaiserslautern
Loading...
Searching...
No Matches
passiveArgumentStoreTraits.hpp
1/*
2 * CoDiPack, a Code Differentiation Package
3 *
4 * Copyright (C) 2015-2024 Chair for Scientific Computing (SciComp), University of Kaiserslautern-Landau
5 * Homepage: http://scicomp.rptu.de
6 * Contact: Prof. Nicolas R. Gauger (codi@scicomp.uni-kl.de)
7 *
8 * Lead developers: Max Sagebaum, Johannes Blühdorn (SciComp, University of Kaiserslautern-Landau)
9 *
10 * This file is part of CoDiPack (http://scicomp.rptu.de/software/codi).
11 *
12 * CoDiPack is free software: you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, either version 3 of the
15 * License, or (at your option) any later version.
16 *
17 * CoDiPack is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty
19 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20 *
21 * See the GNU General Public License for more details.
22 * You should have received a copy of the GNU
23 * General Public License along with CoDiPack.
24 * If not, see <http://www.gnu.org/licenses/>.
25 *
26 * For other licensing options please contact us.
27 *
28 * Authors:
29 * - SciComp, University of Kaiserslautern-Landau:
30 * - Max Sagebaum
31 * - Johannes Blühdorn
32 * - Former members:
33 * - Tim Albring
34 */
35#pragma once
36
37#include "../../../config.h"
38#include "../../../misc/byteDataView.hpp"
40#include "../../../misc/temporaryMemory.hpp"
41
43namespace codi {
44
56 template<typename T_T, typename T_S = T_T, typename = void>
58 using T = CODI_DD(T_T, int);
59 using S = CODI_DD(T_S, short);
60
61 using Store = T;
62
64 CODI_INLINE static size_t countSize(T&& value, size_t size, bool storeRequired);
65
67 CODI_INLINE static void restore(ByteDataView* store, TemporaryMemory& allocator, size_t size, bool storeRequired,
68 Store& value);
69
71 CODI_INLINE static void store(ByteDataView* dataStore, TemporaryMemory& allocator, T const& value, size_t size,
72 bool storeRequired);
73 };
74
75#ifndef DOXYGEN_DISABLE
76
78 template<typename T_T, typename T_S>
79 struct PassiveArgumentStoreTraits<T_T, T_S, typename std::enable_if<std::is_integral<T_T>::value>::type> {
80 using T = CODI_DD(T_T, int);
81 using S = CODI_DD(T_S, short);
82
83 using Store = T;
84
86 CODI_INLINE static size_t countSize(T const& value, size_t size, bool storeRequired) {
87 CODI_UNUSED(value, size);
88
89 size_t storeSize = 0;
90
91 if (storeRequired) {
92 storeSize += sizeof(S);
93 }
94
95 return storeSize;
96 }
97
99 CODI_INLINE static void restore(ByteDataView* dataStore, TemporaryMemory& allocator, size_t size,
100 bool storeRequired, Store& value) {
101 CODI_UNUSED(allocator, size);
102 if (storeRequired) {
103 value = *dataStore->template read<S>(1);
104 }
105 }
106
108 CODI_INLINE static void store(ByteDataView* dataStore, TemporaryMemory& allocator, T const& value, size_t size,
109 bool storeRequired) {
110 CODI_UNUSED(allocator, size);
111
112 if (storeRequired) {
113 dataStore->write<S>(value);
114 }
115 }
116 };
117
118#endif
119}
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
void CODI_UNUSED(Args const &...)
Disable unused warnings for an arbitrary number of arguments.
Definition macros.hpp:46
Definition byteDataView.hpp:51
Traits for storing passive arguments in byte streams.
Definition passiveArgumentStoreTraits.hpp:57
static void restore(ByteDataView *store, TemporaryMemory &allocator, size_t size, bool storeRequired, Store &value)
Restore the data for this type.
static void store(ByteDataView *dataStore, TemporaryMemory &allocator, T const &value, size_t size, bool storeRequired)
Store the data for the type in the data store.
T_T T
See PassiveArgumentStoreTraits.
Definition passiveArgumentStoreTraits.hpp:58
T_S S
See PassiveArgumentStoreTraits.
Definition passiveArgumentStoreTraits.hpp:59
static size_t countSize(T &&value, size_t size, bool storeRequired)
Count the required size for storing the data.
T Store
Type for the variable declaration for restoring the data.
Definition passiveArgumentStoreTraits.hpp:61
Allocator for temporary used memory.
Definition temporaryMemory.hpp:54