40#include "../../misc/fileIo.hpp"
90 template<
typename... Data>
94 template<
typename... Pointers>
96 Pointers*&... pointers);
99 virtual void erase(
size_t const& start,
size_t const& end) = 0;
184 template<
typename Data1>
214 if (
nullptr == data1) {
215 data1 =
new Data1[
size];
222 pointer1 = &data1[index];
227 if (
nullptr != data1) {
234 void erase(
size_t const& start,
size_t const& end) {
240 for (
size_t i = 0; i <
usedSize - end; ++i) {
241 data1[start + i] = data1[end + i];
265 std::swap(data1, other.data1);
282 template<
typename Data1,
typename Data2>
309 static size_t constexpr EntrySize =
sizeof(Data1) +
sizeof(Data2);
313 if (
nullptr == data1) {
314 data1 =
new Data1[
size];
317 if (
nullptr == data2) {
318 data2 =
new Data2[
size];
325 pointer1 = &data1[index];
326 pointer2 = &data2[index];
331 if (
nullptr != data1) {
336 if (
nullptr != data2) {
343 void erase(
size_t const& start,
size_t const& end) {
349 for (
size_t i = 0; i <
usedSize - end; ++i) {
350 data1[start + i] = data1[end + i];
352 for (
size_t i = 0; i <
usedSize - end; ++i) {
353 data2[start + i] = data2[end + i];
379 std::swap(data1, other.data1);
380 std::swap(data2, other.data2);
399 template<
typename Data1,
typename Data2,
typename Data3>
428 sizeof(Data1) +
sizeof(Data2) +
sizeof(Data3);
432 if (
nullptr == data1) {
433 data1 =
new Data1[
size];
436 if (
nullptr == data2) {
437 data2 =
new Data2[
size];
440 if (
nullptr == data3) {
441 data3 =
new Data3[
size];
448 pointer1 = &data1[index];
449 pointer2 = &data2[index];
450 pointer3 = &data3[index];
455 if (
nullptr != data1) {
460 if (
nullptr != data2) {
465 if (
nullptr != data3) {
472 void erase(
size_t const& start,
size_t const& end) {
478 for (
size_t i = 0; i <
usedSize - end; ++i) {
479 data1[start + i] = data1[end + i];
481 for (
size_t i = 0; i <
usedSize - end; ++i) {
482 data2[start + i] = data2[end + i];
484 for (
size_t i = 0; i <
usedSize - end; ++i) {
485 data3[start + i] = data3[end + i];
513 std::swap(data1, other.data1);
514 std::swap(data2, other.data2);
515 std::swap(data3, other.data3);
536 template<
typename Data1,
typename Data2,
typename Data3,
typename Data4>
553 :
ChunkBase(
size), data1(nullptr), data2(nullptr), data3(nullptr), data4(nullptr) {
567 sizeof(Data1) +
sizeof(Data2) +
sizeof(Data3) +
sizeof(Data4);
571 if (
nullptr == data1) {
572 data1 =
new Data1[
size];
575 if (
nullptr == data2) {
576 data2 =
new Data2[
size];
579 if (
nullptr == data3) {
580 data3 =
new Data3[
size];
583 if (
nullptr == data4) {
584 data4 =
new Data4[
size];
592 pointer1 = &data1[index];
593 pointer2 = &data2[index];
594 pointer3 = &data3[index];
595 pointer4 = &data4[index];
600 if (
nullptr != data1) {
605 if (
nullptr != data2) {
610 if (
nullptr != data3) {
615 if (
nullptr != data4) {
622 void erase(
size_t const& start,
size_t const& end) {
628 for (
size_t i = 0; i <
usedSize - end; ++i) {
629 data1[start + i] = data1[end + i];
631 for (
size_t i = 0; i <
usedSize - end; ++i) {
632 data2[start + i] = data2[end + i];
634 for (
size_t i = 0; i <
usedSize - end; ++i) {
635 data3[start + i] = data3[end + i];
637 for (
size_t i = 0; i <
usedSize - end; ++i) {
638 data4[start + i] = data4[end + i];
645 CODI_INLINE void pushData(Data1
const& value1, Data2
const& value2, Data3
const& value3, Data4
const& value4) {
668 std::swap(data1, other.data1);
669 std::swap(data2, other.data2);
670 std::swap(data3, other.data3);
671 std::swap(data4, other.data4);
#define CODI_INLINE
See codi::Config::ForcedInlines.
Definition config.h:457
#define codiAssert(x)
See codi::Config::EnableAssert.
Definition config.h:432
#define CODI_IMPLEMENTATION
Used in interface declarations to indicate the type of the implementing class.
Definition macros.hpp:105
#define CODI_UNDEFINED_VALUE
Used in interface declarations for variables that have to be defined in the specializations.
Definition macros.hpp:117
CoDiPack - Code Differentiation Package.
Definition codi.hpp:90
static size_t constexpr EntrySize
Total size of all data in one entry.
Definition chunk.hpp:210
~Chunk1()
Destructor.
Definition chunk.hpp:202
void pushData(Data1 const &value1)
provided.
Definition chunk.hpp:248
void erase(size_t const &start, size_t const &end)
Erase data items start, ..., end - 1.
Definition chunk.hpp:234
void writeData(FileIo &handle) const
Write data to the FileIo handle.
Definition chunk.hpp:269
void swap(Chunk1< Data1 > &other)
Swap data with other chunk of the same type.
Definition chunk.hpp:262
void readData(FileIo &handle)
Read data from the FileIo handle.
Definition chunk.hpp:255
void deleteData()
Delete the allocated data.
Definition chunk.hpp:226
void dataPointer(size_t const &index, Data1 *&pointer1)
Definition chunk.hpp:220
Chunk1(size_t const &size)
Constructor.
Definition chunk.hpp:197
void allocateData()
Allocated the data if it was deallocated before.
Definition chunk.hpp:213
void writeData(FileIo &handle) const
Write data to the FileIo handle.
Definition chunk.hpp:384
void swap(Chunk2< Data1, Data2 > &other)
Swap data with other chunk of the same type.
Definition chunk.hpp:376
void dataPointer(size_t const &index, Data1 *&pointer1, Data2 *&pointer2)
Definition chunk.hpp:323
~Chunk2()
Destructor.
Definition chunk.hpp:301
void deleteData()
Delete the allocated data.
Definition chunk.hpp:330
Chunk2(size_t const &size)
Constructor.
Definition chunk.hpp:296
static size_t constexpr EntrySize
Total size of all data in one entry.
Definition chunk.hpp:309
void pushData(Data1 const &value1, Data2 const &value2)
provided.
Definition chunk.hpp:360
void readData(FileIo &handle)
Read data from the FileIo handle.
Definition chunk.hpp:368
void allocateData()
Allocated the data if it was deallocated before.
Definition chunk.hpp:312
void erase(size_t const &start, size_t const &end)
Erase data items start, ..., end - 1.
Definition chunk.hpp:343
void dataPointer(size_t const &index, Data1 *&pointer1, Data2 *&pointer2, Data3 *&pointer3)
Definition chunk.hpp:446
void readData(FileIo &handle)
Read data from the FileIo handle.
Definition chunk.hpp:501
void erase(size_t const &start, size_t const &end)
Erase data items start, ..., end - 1.
Definition chunk.hpp:472
void pushData(Data1 const &value1, Data2 const &value2, Data3 const &value3)
provided.
Definition chunk.hpp:492
void writeData(FileIo &handle) const
Write data to the FileIo handle.
Definition chunk.hpp:519
void swap(Chunk3< Data1, Data2, Data3 > &other)
Swap data with other chunk of the same type.
Definition chunk.hpp:510
void deleteData()
Delete the allocated data.
Definition chunk.hpp:454
static size_t constexpr EntrySize
Total size of all data in one entry.
Definition chunk.hpp:427
Chunk3(size_t const &size)
Constructor.
Definition chunk.hpp:414
~Chunk3()
Destructor.
Definition chunk.hpp:419
void allocateData()
Allocated the data if it was deallocated before.
Definition chunk.hpp:431
void readData(FileIo &handle)
Read data from the FileIo handle.
Definition chunk.hpp:655
static size_t constexpr EntrySize
Total size of all data in one entry.
Definition chunk.hpp:566
void deleteData()
Delete the allocated data.
Definition chunk.hpp:599
void writeData(FileIo &handle) const
Write data to the FileIo handle.
Definition chunk.hpp:675
void pushData(Data1 const &value1, Data2 const &value2, Data3 const &value3, Data4 const &value4)
provided.
Definition chunk.hpp:645
void swap(Chunk4< Data1, Data2, Data3, Data4 > &other)
Swap data with other chunk of the same type.
Definition chunk.hpp:665
void dataPointer(size_t const &index, Data1 *&pointer1, Data2 *&pointer2, Data3 *&pointer3, Data4 *&pointer4)
Definition chunk.hpp:589
~Chunk4()
Destructor.
Definition chunk.hpp:558
void erase(size_t const &start, size_t const &end)
Erase data items start, ..., end - 1.
Definition chunk.hpp:622
Chunk4(size_t const &size)
Constructor.
Definition chunk.hpp:552
void allocateData()
Allocated the data if it was deallocated before.
Definition chunk.hpp:570
A chunk stores a contiguous block of data in CoDiPack.
Definition chunk.hpp:76
size_t size
Maximum size of arrays.
Definition chunk.hpp:120
size_t usedSize
Currently used size.
Definition chunk.hpp:121
virtual void allocateData()=0
Allocated the data if it was deallocated before.
virtual void deleteData()=0
Delete the allocated data.
ChunkBase(size_t const &size)
Constructor.
Definition chunk.hpp:126
virtual void readData(FileIo &handle)=0
Read data from the FileIo handle.
virtual void erase(size_t const &start, size_t const &end)=0
Erase data items start, ..., end - 1.
size_t getUnusedSize() const
Number of unused data items.
Definition chunk.hpp:141
void swap(ChunkBase &other)
Swap the entries of this base class.
Definition chunk.hpp:173
virtual void writeData(FileIo &handle) const =0
Write data to the FileIo handle.
void setUsedSize(size_t const &usage)
Set the used size.
Definition chunk.hpp:164
virtual ~ChunkBase()
Destructor.
Definition chunk.hpp:129
void swap(ImplProxy &other)
Swap data with other chunk of the same type.
void resize(size_t newSize)
Resize the allocated data. Stored data is lost. Used size is set to zero.
Definition chunk.hpp:156
static size_t constexpr EntrySize
Total size of all data in one entry.
Definition chunk.hpp:83
void pushData(Data &&... dataEntries)
provided.
size_t getSize() const
Get the allocated size.
Definition chunk.hpp:136
void dataPointer(size_t const &index, Pointers *&... pointers)
void reset()
Sets the number of used items to zero.
Definition chunk.hpp:151
size_t getUsedSize() const
Number of used data items.
Definition chunk.hpp:146
Helper structure for writing binary data.
Definition fileIo.hpp:84
void writeData(Data const *data, size_t const length)
Definition fileIo.hpp:119
void readData(Data *data, size_t const length)
Definition fileIo.hpp:134