Polygon Crucher SDK - Documentation
Documentation
Loading...
Searching...
No Matches
DataChunk.h
1#ifndef CDATACHUNK_CLASS_H
2#define CDATACHUNK_CLASS_H
3
4#ifdef _MSC_VER
5#pragma once
6#endif // _MSC_VER
7
8
9#include "ElementArray.h"
10
11BEGIN_MOOTOOLS_NAMESPACE
12
13typedef unsigned int DataChunkID;
14#define DATACHUNK_UNKNOWN ((mootools::DataChunkID)(-1))
15
16typedef enum _DATACHUNK_FLAGS
17{
18 DATACHUNK_NONE = 0x00,
19 DATACHUNK_KEEP_ON_COPY = 0x01,
20 DATACHUNK_MAIN_CHANNEL = 0x02,
21 DATACHUNK_INFO_FLAGS = 0xFF,
22
23 // These flags are used when calling CDataChunk methods. Not save in the DataChunkInfo.flags
24 DATA_CHUNK_REPLACE_DATA = 0x100, // Use in AddDataChunk to replace a given id with a new one that can have different CElementMethods
26
27class CElementMethods;
28class DLL_3DFUNCTION CDataChunk
29{
30public:
31 CDataChunk();
32 virtual ~CDataChunk();
33 unsigned int AddDataChunk(DataChunkID dataid, CElementMethods *methods, unsigned int flags);
34 void AppendDataChunks(const CDataChunk& srcdata, bool emptyData = true); // Add data chunks that are in srcdata if not already in the data chunks information
35 void InitDataChunks(const CDataChunk& src, unsigned int size = -1);
36 bool RemoveDataChunk(DataChunkID dataid);
37 bool HasDataChunk(DataChunkID dataid) const;
38
39 int SetGrowFactor(int growFaceMode);
40 void PreAllocate(int estimatedSize, bool constructAllElementsOnce = false); // Preallocate array. GetDataSize() return 0. When filling the array, SetDataSize must be called with growOnly = true, otherwise array will be resized loosing the preallocation advantage
41 void SetDataSize(unsigned int size, bool growOnly = false, unsigned int growFaceMode = CElementArray::GROW_KEEP_MODE); // Size is the data chunk size, growOnly = false means that the size fits exactly the defined size otherwise the size cannot be reduced and can only increase
42 void ExpandDataSize(unsigned int addsize); // Expand the existing size by addsize elements. The method grows the array (if needed), so PreAllocate can be used before.
43 unsigned int GetDataSize() const;
44 void FreeExtra();
45
46 void *GetMainData(unsigned int index) const; // Return data
47 void *GetData(DataChunkID id, unsigned int index) const;
48 void DeleteAll();
49 void RemoveAll();
50
51 unsigned int GetChunksNbr() const;
52 HashPos GetFirstChunk() const;
53 void GetNextChunk(HashPos& pos, DataChunkID& id) const;
54
55 const CElementArray *GetData(unsigned int dataChunkID) const;
56 SIZET GetSizeOfDataChunk(DataChunkID dataid) const;
57
58 unsigned int CopyData(unsigned int dstindex, unsigned int srcindex, const CDataChunk& srcdata);
59 unsigned int CopyData(const CDataChunk& refdata);
60
61 bool Reorder(const unsigned int *reforder, unsigned int size, bool moveToDestinationIndexes);
62
63 void Serialize(CXArchive& ar);
64
65#ifdef _DEBUG
66 void Dump(DataChunkID id, unsigned int index) const;
67#endif
68
69protected:
70 typedef struct
71 {
72 CElementArray *data;
73 unsigned int flags;
74 } DataChunkInfo;
76
77 bool constructAllOnce;
78 unsigned int preallocate;
79 unsigned int datasize, growsize;
80 CDataChunkMap chunks;
81 DataChunkID mainChunkID;
82 CElementArray *mainArray;
83
84 void UpdateMainChunk();
85};
86
87///////////////////////////////////////////////////////////////////////////////////
88// Inline implementation
89inline void *CDataChunk::GetMainData(unsigned int index) const
90{
91 XASSERT(mainArray);
92 return mainArray->ElementAt(index);
93}
94
95inline void *CDataChunk::GetData(DataChunkID id, unsigned int index) const // Return the data chunk by index
96{
97 DataChunkInfo *info = chunks.Find(id);
98 if (!info)
99 return NULL;
100
101 return info->data->ElementAt(index);
102}
103
104END_MOOTOOLS_NAMESPACE
105
106#endif // CDATACHUNK_CLASS_H
An advanced array class containing data that needs to be construct / destruct.
The class defines an x, y, z 3D point which can use int, float or double.
Definition 3DPoint.h:27
Definition DataChunk.h:29
An advanced array class containing data that needs to be construct / destruct.
Definition ElementArray.h:69
@ GROW_KEEP_MODE
Keep the default grow size (SetAtGrow, SetSize)
Definition ElementArray.h:76
CElementMethods is provided to CElementArray and give some information on the data as well as the met...
Definition ElementArray.h:22
Definition XArchive.h:17