66 virtual ~DataItemBase() {}
68 virtual DataItemBase* clone() = 0;
71 template<
typename T_Type>
72 struct DataItem :
public DataItemBase {
76 explicit DataItem(Type
const& value) {
77 data = (
void*)
new Type(value);
81 Type* pointer = (Type*)data;
85 DataItemBase* clone() {
86 return new DataItem<Type>(*((Type*)data));
90 template<
typename Type>
91 struct DataArray :
public DataItemBase {
96 DataArray(Type
const* value,
int size) {
97 data = (
void*)
new Type[size];
99 std::copy(value, &value[size], (Type*)data);
103 Type* pointer = (Type*)data;
107 DataItemBase* clone() {
108 return new DataArray<Type>(*((Type*)data), size);
112 std::vector<DataItemBase*> store;
123 copyAll(other, *
this);
134 copyAll(other, *
this);
141 for (
size_t i = 0; i < store.size(); ++i) {
150 template<
typename Type>
152 store.push_back(
new DataItem<Type>(value));
153 return store.size() - 1;
159 template<
typename Type>
160 size_t addData(Type
const* value,
int const size) {
161 store.push_back(
new DataArray<Type>(value, size));
162 return store.size() - 1;
170 template<
typename Type>
172 getData<Type>(&value, 1);
176 template<
typename Type>
178 Type* data = nextStore<Type>();
183 template<
typename Type>
185 Type* data = nextStore<Type>();
190 template<
typename Type>
192 Type* convPointer = nextStore<Type>();
194 std::copy(convPointer, &convPointer[size], value);
198 template<
typename Type>
200 Type* data = nextStore<Type>();
218 template<
typename Type>
220 getDataByIndex<Type>(&value, 1, pos);
226 template<
typename Type>
228 Type* data = getStore<Type>(pos);
235 template<
typename Type>
237 Type* data = getStore<Type>(pos);
244 template<
typename Type>
246 Type* convPointer = getStore<Type>(pos);
248 std::copy(convPointer, &convPointer[size], value);
252 template<
typename Type>
254 Type* data = nextStore<Type>();
263 for (
size_t i = 0; i < from.store.size(); ++i) {
264 to.store.push_back(from.store[i]->clone());
266 to.storePos = from.storePos;
269 template<
typename Type>
270 Type* getStore(
size_t pos) {
271 return (Type*)store[pos]->data;
274 template<
typename Type>
276 Type* pointer = getStore<Type>(storePos);
278 if (storePos >= store.size()) {
#define CODI_DD(Type, Default)
Abbreviation for CODI_DECLARE_DEFAULT.
Definition macros.hpp:94
#define CODI_ANY
Used in default declarations of expression templates.
Definition macros.hpp:98
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
Ease of access structure for user-provided data on the tape for external functions....
Definition externalFunctionUserData.hpp:59
void getDataByIndex(Type *value, int const size, size_t pos)
Definition externalFunctionUserData.hpp:245
void getData(Type &value)
Get a copy of the next data item.
Definition externalFunctionUserData.hpp:171
ExternalFunctionUserData & operator=(ExternalFunctionUserData const &other)
Copy operator.
Definition externalFunctionUserData.hpp:132
void getDataByIndex(Type &value, size_t pos)
Definition externalFunctionUserData.hpp:219
Type const * getDataArrayByIndex()
Get the address of a data item based on the index. Intended for reference access to array items.
Definition externalFunctionUserData.hpp:253
Type & getDataRefByIndex(size_t pos)
Definition externalFunctionUserData.hpp:236
ExternalFunctionUserData()
Constructor.
Definition externalFunctionUserData.hpp:119
ExternalFunctionUserData(ExternalFunctionUserData const &other)
Constructor.
Definition externalFunctionUserData.hpp:122
~ExternalFunctionUserData()
Destructor.
Definition externalFunctionUserData.hpp:127
Type const & getDataByIndex(size_t pos)
Definition externalFunctionUserData.hpp:227
void getData(Type *value, int const size)
Get the next data item and copy it as an array. The target array must have the correct size.
Definition externalFunctionUserData.hpp:191
Type const * getDataArray()
Get the address of the next data item. Intended for reference access to array items.
Definition externalFunctionUserData.hpp:199
void resetPos()
Manually reset the position.
Definition externalFunctionUserData.hpp:205
void clear()
Delete all data entries.
Definition externalFunctionUserData.hpp:140
Type & getDataRef()
Get a reference to the next data item.
Definition externalFunctionUserData.hpp:184
Type const & getData()
Get a constant reference to the next data item.
Definition externalFunctionUserData.hpp:177
size_t addData(Type const &value)
Definition externalFunctionUserData.hpp:151
size_t addData(Type const *value, int const size)
Definition externalFunctionUserData.hpp:160