37#ifndef ARRAY_WRAPPER_H
38#define ARRAY_WRAPPER_H
48#include "data/constant.h"
49#include "data/dataHandler.h"
50#include "data/demangle.h"
70 static_assert(std::is_fundamental<T>::value ||
71 std::is_same<T, Data::Constant>(),
72 "Template class PrimitiveTypeArray<T> can only be used "
73 "for primitive types.");
88 mutable std::map<std::type_index, size_t> cachedAddressSpace;
173 const std::type_info&
type)
const override;
205 const size_t address)
const override;
209 const std::type_info&
type,
const size_t address)
const override;
211#ifdef CODE_GENERATION
223 if (
typeid(
T) ==
type) {
240 <<
" cannot be accessed in a "
242 throw std::invalid_argument(
message.str());
249 <<
" cannot be accessed at address " <<
address
251 throw std::out_of_range(
message.str());
277 auto iter = this->cachedAddressSpace.find(
type);
278 if (
iter != this->cachedAddressSpace.end()) {
282 if (
type ==
typeid(
T)) {
291 regex.append(
"\\s*(const\\s*)?\\[([0-9]+)\\]");
297 size_t result = this->nbElements - size + 1;
298 this->cachedAddressSpace.emplace(
type, result);
308 const std::type_info&
type,
const size_t address)
const
311 std::vector<size_t> result;
317 if (
type ==
typeid(
T)) {
332 const std::type_info&
type,
const size_t address)
const
335 throw std::runtime_error(
"Null pointer access.");
342 if (
type ==
typeid(
T)) {
345 UntypedSharedPtr::emptyDestructor<const T>());
356 for (
size_t idx = 0; idx <
arraySize; idx++) {
362 std::make_shared<UntypedSharedPtr::Model<const T[]>>(
array)};
386 if (
ptr ==
nullptr) {
396 message <<
"Size of pointed data (" <<
ptr->size()
397 <<
") does not correspond to the size of the ArrayWrapper ("
399 throw std::domain_error(
message.str());
433#ifdef CODE_GENERATION
437 const std::type_info&
a =
typeid(
T);
453#include "data/primitiveTypeArray.h"
size_t getAddressSpace(const std::type_info &type, size_t *dim1, size_t *dim2) const
Utility function for the class.
Definition array2DWrapper.h:217
Definition arrayWrapper.h:69
ArrayWrapper(const ArrayWrapper< T > &other)=default
Default copy constructor.
std::vector< T > * containerPtr
Pointer to the array containing the data accessed through the ArrayWrapper.
Definition arrayWrapper.h:105
virtual ~ArrayWrapper()=default
Default destructor.
ArrayWrapper(const DataHandler &other, size_t size)
Copy constructor for DataHandler.
Definition arrayWrapper.h:256
void resetData() override
Inherited from DataHandler. Does nothing.
Definition arrayWrapper.h:377
ArrayWrapper(size_t size=8, std::vector< T > *ptr=nullptr)
Constructor for the ArrayWrapper class.
Definition arrayWrapper.h:137
void invalidateCachedHash()
Invalidate the hash of the container.
Definition arrayWrapper.h:372
const size_t nbElements
Number of elements contained pointer vector.
Definition arrayWrapper.h:99
virtual size_t getLargestAddressSpace(void) const override
Inherited from DataHandler.
Definition arrayWrapper.h:366
virtual DataHandler * clone() const override
Return a PrimitiveTypeArray<T> where all data of the ArrayWrapper has been copied.
Definition arrayWrapper.h:265
virtual std::vector< size_t > getDimensionsSize() const override
Inherited from DataHandler.
Definition arrayWrapper.h:442
virtual size_t getAddressSpace(const std::type_info &type) const override
Inherited from DataHandler.
Definition arrayWrapper.h:274
virtual size_t updateHash() const override
Implementation of the updateHash method.
Definition arrayWrapper.h:407
virtual UntypedSharedPtr getDataAt(const std::type_info &type, const size_t address) const override
Inherited from DataHandler.
Definition arrayWrapper.h:331
virtual std::vector< size_t > getAddressesAccessed(const std::type_info &type, const size_t address) const override
Inherited from DataHandler.
Definition arrayWrapper.h:307
void setPointer(std::vector< T > *ptr)
Set the pointer of the ArrayWrapper.
Definition arrayWrapper.h:383
virtual const std::type_info & getNativeType() const override
Inherited from DataHandler.
Definition arrayWrapper.h:435
void checkAddressAndType(const std::type_info &type, const size_t &address) const
Definition arrayWrapper.h:232
virtual bool canHandle(const std::type_info &type) const override
Inherited from DataHandler.
Definition arrayWrapper.h:221
Base class for all sources of data to be accessed by a TPG Instruction executed within a Program.
Definition dataHandler.h:55
bool invalidCachedHash
Boolean value indicating whether the current cachedValue is valid, or not.
Definition dataHandler.h:90
size_t cachedHash
Cached value returned by the getHash() function.
Definition dataHandler.h:78
const size_t id
Identifier of each DataHandler.
Definition dataHandler.h:70
DataHandler for 2D arrays of primitive types.
Definition primitiveTypeArray2D.h:69
PrimitiveTypeArray2D(const size_t w=2, const size_t h=4)
Constructor for the 2D array.
Definition primitiveTypeArray2D.h:142
Definition primitiveTypeArray.h:55
Class behaving as a std::shared_ptr whose type is not templated.
Definition untypedSharedPtr.h:72
Definition array2DWrapper.h:44