Cumulia Illustrator Rendering Engine v1.1.0
A Rendering engine for industrial CAD/CAE model and optimized for greatest performance
 
Loading...
Searching...
No Matches
typedarray.h
1//##################################################################################################
2//
3// Copyright (c) 2024 Beijing Qiongqi Tech Co.,Ltd. All rights reserved.
4
5// This source code is confidential and proprietary to Beijing Qiongqi Tech Co.,Ltd(The Holder).
6// Any unauthorized use, copying, modification, or distribution of the code is strictly prohibited.
7// Any user shall obtain authorizaition from the Holder before modifying the source code. And the user shall not
8// sublicense, sell, distribute, or transfer the source code, whether in original or modified form, to any third party
9// without the prior written consent of the Holder.
10
11// This copyright notice and permission grant shall be included in all copies or substantial portions of the source code.
12
13// Author Cumulia Illustrator
14// Date 2024-10-31
15// Version V1.1.0
16//##################################################################################################
17
18#pragma once
19
20#include "variant.h"
21#include <cstring>
22#include <initializer_list>
23
24namespace cil
25{
26 class ArrayBuffer : public Variant
27 {
28 public:
30 virtual ~ArrayBuffer();
31 };
32
33 template <typename T>
34 class TypedArray : public ArrayBuffer
35 {
36 protected:
38 int m_size;
39
40 public:
42 {
43 this->m_size = 0;
44 this->m_data = nullptr;
45 }
46
47 virtual ~TypedArray()
48 {
49 this->clear();
50 }
51
52 const T& operator[](int index) const
53 {
54 return this->m_data[index];
55 }
56
57 T& operator[](int index)
58 {
59 return this->m_data[index];
60 }
61
62 void set(int size, T* data = nullptr, bool copy = true)
63 {
64 this->clear();
65
66 if (size > 0)
67 {
68 this->m_size = size;
69 if (data)
70 {
71 if (copy)
72 {
73 this->m_data = new T[this->m_size];
74 memcpy(this->m_data, data, this->m_size * sizeof(T));
75 }
76 else
77 {
78 this->m_data = data;
79 }
80 }
81 else
82 {
83 this->m_data = new T[this->m_size]{};
84 }
85 }
86 }
87
88 void clear()
89 {
90 if (this->m_data)
91 {
92 delete[] this->m_data;
93 this->m_data = nullptr;
94 this->m_size = 0;
95 }
96 }
97
98 int size() const
99 {
100 return this->m_size;
101 }
102
103 T* data()
104 {
105 return this->m_data;
106 }
107
108 const T* data() const
109 {
110 return this->m_data;
111 }
112 };
113
114 class Int8Array final : public TypedArray<char>
115 {
116 public:
117 Int8Array(int size = 0, char* data = nullptr, bool copy = true);
118 Int8Array(const std::initializer_list<char>& array);
119 };
120
121 class Uint8Array final : public TypedArray<unsigned char>
122 {
123 public:
124 Uint8Array(int size = 0, unsigned char* data = nullptr, bool copy = true);
125 Uint8Array(const std::initializer_list<unsigned char>& array);
126 };
127
128 class Int16Array final : public TypedArray<short>
129 {
130 public:
131 Int16Array(int size = 0, short* data = nullptr, bool copy = true);
132 Int16Array(const std::initializer_list<short>& array);
133 };
134
135 class Uint16Array final : public TypedArray<unsigned short>
136 {
137 public:
138 Uint16Array(int size = 0, unsigned short* data = nullptr, bool copy = true);
139 Uint16Array(const std::initializer_list<unsigned short>& array);
140 };
141
142 class Int32Array final : public TypedArray<int>
143 {
144 public:
145 Int32Array(int size = 0, int* data = nullptr, bool copy = true);
146 Int32Array(const std::initializer_list<int>& array);
147 };
148
149 class Uint32Array final : public TypedArray<unsigned int>
150 {
151 public:
152 Uint32Array(int size = 0, unsigned int* data = nullptr, bool copy = true);
153 Uint32Array(const std::initializer_list<unsigned int>& array);
154 };
155
156 class Float32Array final : public TypedArray<float>
157 {
158 public:
159 Float32Array(int size = 0, float* data = nullptr, bool copy = true);
160 Float32Array(const std::initializer_list<float>& array);
161 };
162
163 class Float64Array final : public TypedArray<double>
164 {
165 public:
166 Float64Array(int size = 0, double* data = nullptr, bool copy = true);
167 Float64Array(const std::initializer_list<double>& array);
168 };
169
178}
Definition typedarray.h:27
virtual ~ArrayBuffer()
Definition typedarray.h:157
Float32Array(const std::initializer_list< float > &array)
Float32Array(int size=0, float *data=nullptr, bool copy=true)
Definition typedarray.h:164
Float64Array(const std::initializer_list< double > &array)
Float64Array(int size=0, double *data=nullptr, bool copy=true)
Definition typedarray.h:129
Int16Array(const std::initializer_list< short > &array)
Int16Array(int size=0, short *data=nullptr, bool copy=true)
Definition typedarray.h:143
Int32Array(int size=0, int *data=nullptr, bool copy=true)
Int32Array(const std::initializer_list< int > &array)
Definition typedarray.h:115
Int8Array(const std::initializer_list< char > &array)
Int8Array(int size=0, char *data=nullptr, bool copy=true)
Definition typedarray.h:35
int m_size
Definition typedarray.h:38
const T & operator[](int index) const
Definition typedarray.h:52
void clear()
Definition typedarray.h:88
T & operator[](int index)
Definition typedarray.h:57
const T * data() const
Definition typedarray.h:108
void set(int size, T *data=nullptr, bool copy=true)
Definition typedarray.h:62
T * m_data
Definition typedarray.h:37
T * data()
Definition typedarray.h:103
virtual ~TypedArray()
Definition typedarray.h:47
int size() const
Definition typedarray.h:98
TypedArray()
Definition typedarray.h:41
Definition typedarray.h:136
Uint16Array(const std::initializer_list< unsigned short > &array)
Uint16Array(int size=0, unsigned short *data=nullptr, bool copy=true)
Definition typedarray.h:150
Uint32Array(const std::initializer_list< unsigned int > &array)
Uint32Array(int size=0, unsigned int *data=nullptr, bool copy=true)
Definition typedarray.h:122
Uint8Array(int size=0, unsigned char *data=nullptr, bool copy=true)
Uint8Array(const std::initializer_list< unsigned char > &array)
The Variant class is the most basic class of other mathamatic classes.
Definition variant.h:26
Definition decal.h:23