-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathaccel.h
More file actions
1240 lines (1029 loc) · 29.4 KB
/
accel.h
File metadata and controls
1240 lines (1029 loc) · 29.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef INC_ACCEL_ACCEL_H__
#define INC_ACCEL_ACCEL_H__
/**
@file accel.h
@author t-sakai
@date 2018/01/22 create
*/
#include <assert.h>
#include <malloc.h>
#include <new>
#define _USE_MATH_DEFINES
#include <math.h>
#include <limits>
//#include <mmintrin.h> //MMX命令セット
#include <xmmintrin.h> //SSE命令セット
#include <emmintrin.h> //SSE2命令セット
#define NOMINMAX
#include <Windows.h>
#include <sstream>
#include <utility>
//C++98 199711L
//C++11 201103L
#ifdef __cplusplus
# if 201103L<=__cplusplus || 1900<=_MSC_VER
# define ACC_CPP11 1
# endif
#endif
#ifdef NULL
# ifdef __cplusplus
# ifdef ACC_CPP11
# undef NULL
# define NULL nullptr
# endif
# endif
#else
# ifdef __cplusplus
# ifdef ACC_CPP11
# define NULL nullptr
# else
# define NULL 0
# endif
# else
# define NULL ((void*)0)
# endif
#endif
/// 16バイトアライメント変数指定
#ifdef _MSC_VER
#define ACC_ALIGN16 __declspec(align(16))
#define ACC_ALIGN(x) __declspec(align(x))
#else
#define ACC_ALIGN16 __attribute__((align(16)))
#define ACC_ALIGN(x) __attribute__((align(x)))
#endif
#define ACC_PLACEMENT_NEW(ptr) new(ptr)
#define ACC_DELETE(p) delete p; (p)=NULL
#define ACC_DELETE_NONULL(p) delete p
#define ACC_DELETE_ARRAY(p) delete[] (p); (p)=NULL
#define ACC_MALLOC(size) (::malloc(size))
#define ACC_FREE(mem) ::free(mem); (mem)=NULL
#define ACC_ALIGNED_MALLOC(size, align) (_aligned_malloc(size, align))
#define ACC_ALIGNED_FREE(mem, align) _aligned_free(mem); (mem)=NULL
// Assertion
//-------------------
#if defined(_DEBUG)
#if defined(ANDROID)
#define ACC_ASSERT(expression) {if((expression)==false){__android_log_assert("assert", "lime", "%s (%d)", __FILE__, __LINE__);}}while(0)
#elif defined(__GNUC__)
#define ACC_ASSERT(expression) ( assert(expression) )
#else
#define ACC_ASSERT(expression) ( assert(expression) )
#endif
#else
#define ACC_ASSERT(expression)
#endif
namespace accel
{
typedef char Char;
typedef unsigned char UChar;
typedef char16_t Char16;
typedef wchar_t WChar;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef float f32;
typedef double f64;
typedef intptr_t intptr_t;
typedef uintptr_t uintptr_t;
typedef ptrdiff_t ptrdiff_t;
typedef size_t size_t;
typedef __m128 lm128; /// XMMレジスタに対応した単精度浮動小数点型
typedef __m128i lm128i;
typedef __m64 lm64;
#if defined(ANDROID)
static constexpr f32 F32_EPSILON = 1.192092896e-07F;
static constexpr f32 F64_EPSILON = 2.2204460492503131e-016;
#else
static constexpr f32 F32_EPSILON = FLT_EPSILON;
static constexpr f32 F64_EPSILON = DBL_EPSILON;
#endif
static constexpr f32 F32_HITEPSILON = 1.0e-5f;
enum Result
{
Result_Fail = 0,
Result_Success = (0x01U<<0),
Result_Front = (0x01U<<0)|(0x01U<<1),
Result_Back = (0x01U<<0)|(0x01U<<2),
};
using std::move;
template<class T>
inline T absolute(const T x)
{
return abs(x);
}
template<class T>
void swap(T& x0, T& x1)
{
T tmp = x0;
x0 = x1;
x1 = tmp;
}
template<class T>
T minimum(const T& x0, const T& x1)
{
return (x0<x1)? x0 : x1;
}
template<class T>
T maximum(const T& x0, const T& x1)
{
return (x0<x1)? x1 : x0;
}
inline bool isEqual(f32 x0, f32 x1)
{
return (absolute(x0-x1) < F32_EPSILON);
}
inline bool isZero(f32 x)
{
return (absolute(x) < F32_EPSILON);
}
inline bool isZeroPositive(f32 x)
{
return (x < F32_EPSILON);
}
inline bool isZeroNegative(f32 x)
{
return (-F32_EPSILON < x);
}
template<class T>
inline T clamp(T val, T low, T high)
{
if (val <= low) return low;
else if (val >= high) return high;
else return val;
}
f32 clamp01(f32 v);
// Returned value is undefined, if x==0
u32 leadingzero(u32 x);
struct RGB
{
f32 r_;
f32 g_;
f32 b_;
f32 x_;
};
void printImage(const char* filename, RGB* rgb, s32 width, s32 height);
//--- Vector3
//--------------------------------------------------------------
class Vector3
{
public:
Vector3()
{}
Vector3(f32 x, f32 y, f32 z)
:x_(x)
,y_(y)
,z_(z)
{}
void zero()
{
x_ = y_ = z_ = 0.0f;
}
f32 operator[](s32 index) const
{
return reinterpret_cast<const f32*>(this)[index];
}
f32& operator[](s32 index)
{
return reinterpret_cast<f32*>(this)[index];
}
f32 length() const
{
return ::sqrtf(x_*x_ + y_*y_ + z_*z_);
}
f32 halfArea() const
{
return x_*y_ + y_*z_ + z_*x_;
}
Vector3& operator*=(f32 a)
{
x_ *= a;
y_ *= a;
z_ *= a;
return *this;
}
Vector3& operator*=(const Vector3& v)
{
x_ *= v.x_;
y_ *= v.y_;
z_ *= v.z_;
return *this;
}
friend static Vector3 operator+(const Vector3& v0, const Vector3& v1)
{
return Vector3(v0.x_+v1.x_, v0.y_+v1.y_, v0.z_+v1.z_);
}
friend static Vector3 operator-(const Vector3& v0, const Vector3& v1)
{
return Vector3(v0.x_-v1.x_, v0.y_-v1.y_, v0.z_-v1.z_);
}
friend static Vector3 operator*(const Vector3& v, f32 a)
{
return Vector3(a*v.x_, a*v.y_, a*v.z_);
}
friend static Vector3 operator*(f32 a, const Vector3& v)
{
return Vector3(a*v.x_, a*v.y_, a*v.z_);
}
f32 x_, y_, z_;
};
Vector3 normalize(const Vector3& v);
f32 dot(const Vector3& v0, const Vector3& v1);
Vector3 cross(const Vector3& v0, const Vector3& v1);
//--- Vector4
//--------------------------------------------------------------
class Vector4
{
public:
f32 x_, y_, z_, w_;
};
//--- Morton Code
//--------------------------------------------------------------
/**
@brief Generate morton code 10 bits for each axis
*/
s32 mortonCode3(s32 x, s32 y, s32 z);
/**
@brief Reconstruct each axis' values from morton code
*/
void rmortonCode3(s32& x, s32& y, s32& z, s32 w);
class Ray;
//--- AABB
//--------------------------------------------------------------
struct AABB
{
AABB()
{}
AABB(const Vector3& bmin, const Vector3& bmax)
:bmin_(bmin)
,bmax_(bmax)
{}
void zero()
{
bmin_.zero();
bmax_.zero();
}
void setInvalid()
{
bmin_.x_ = bmin_.y_ = bmin_.z_ = FLT_MAX;
bmax_.x_ = bmax_.y_ = bmax_.z_ = -FLT_MAX;
}
Vector3 extent() const
{
return bmax_ - bmin_;
}
Vector3 diagonal() const
{
return Vector3(
bmax_.x_-bmin_.x_,
bmax_.y_-bmin_.y_,
bmax_.z_-bmin_.z_);
}
void extend(const AABB& bbox);
s32 maxExtentAxis() const;
f32 halfArea() const;
bool testRay(f32& tmin, f32& tmax, const Ray& ray) const;
Vector3 bmin_;
Vector3 bmax_;
};
#ifdef _DEBUG
inline bool operator==(const AABB& b0, const AABB& b1)
{
for(int i=0; i<3; ++i){
if(!isEqual(b0.bmin_[i], b1.bmin_[i])){
return false;
}
if(!isEqual(b0.bmax_[i], b1.bmax_[i])){
return false;
}
}
return true;
}
#endif
//--- PrimitiveType
//--------------------------------------------------------------
enum PrimitiveType
{
Primitive_Point,
Primitive_Face,
Primitive_Sphere,
};
//--- Point
//--------------------------------------------------------------
class Point
{
public:
static const s32 Type = Primitive_Point;
f32 getCentroidX() const;
f32 getCentroidY() const;
f32 getCentroidZ() const;
Vector3 getCentroid() const;
f32 getCentroid(s32 axis) const;
AABB getBBox() const;
Vector3 position_;
};
//--- Face
//--------------------------------------------------------------
class Face
{
public:
static const s32 Type = Primitive_Face;
f32 getCentroidX() const;
f32 getCentroidY() const;
f32 getCentroidZ() const;
Vector3 getCentroid() const;
f32 getCentroid(s32 axis) const;
AABB getBBox() const;
bool testRay(f32& t, const Ray& ray) const;
Vector3 getNormal() const;
Vector3 point_[3];
};
//--- Sphere
//--------------------------------------------------------------
class Sphere
{
public:
static const s32 Type = Primitive_Sphere;
Sphere()
{}
Sphere(const Vector3& position, f32 radius)
:position_(position)
,radius_(radius)
{}
f32 getCentroidX() const;
f32 getCentroidY() const;
f32 getCentroidZ() const;
Vector3 getCentroid() const;
f32 getCentroid(s32 axis) const;
AABB getBBox() const;
bool testRay(f32& t, const Ray& ray) const;
Vector3 position_;
f32 radius_;
};
//--- Ray
//--------------------------------------------------------------
class Ray
{
public:
Ray()
{}
Ray(const Vector3& origin,
const Vector3& direction,
f32 t);
void invertDirection();
void setDirection(const Vector3& direction);
void setDirection(const Vector3& direction, const Vector3& invDirection);
Vector3 origin_;
Vector3 direction_;
Vector3 invDirection_;
f32 t_;
};
//--- HitRecord
//--------------------------------------------------------------
struct HitRecord
{
f32 t_; //光線の半直線距離パラメータ
const void* primitive_;
};
template<s32 size=16>
struct ArrayStaticCapacityIncrement
{
static const s32 IncrementSize = size;
static s32 getInitCapacity(s32 capacity)
{
return (capacity + (IncrementSize-1)) & ~(IncrementSize-1);
}
static s32 getNewCapacity(s32 capacity)
{
return capacity + IncrementSize;
}
};
//-------------------------------------------------------
//---
//---
//---
//-------------------------------------------------------
template<class T, class CapacityIncrement, class isTriviallyCopyable>
class ArrayBuffer
{
protected:
typedef ArrayBuffer<T, CapacityIncrement, isTriviallyCopyable> this_type;
typedef T value_type;
typedef s32 size_type;
typedef CapacityIncrement capacity_increment_type;
ArrayBuffer(const this_type&) = delete;
this_type& operator=(const this_type&) = delete;
ArrayBuffer()
:capacity_(0)
,size_(0)
,items_(NULL)
{}
ArrayBuffer(this_type&& rhs)
:capacity_(rhs.capacity_)
,size_(rhs.size_)
,items_(rhs.items_)
{
rhs.capacity_ = 0;
rhs.size_ = 0;
rhs.items_ = NULL;
}
explicit ArrayBuffer(size_type capacity)
:capacity_(capacity_increment_type::getInitCapacity(capacity))
,size_(0)
,items_(NULL)
{
ACC_ASSERT(0<=capacity_);
items_ = reinterpret_cast<T*>(ACC_ALIGNED_MALLOC(capacity_*sizeof(T), 16));
}
~ArrayBuffer()
{
for(s32 i = 0; i<size_; ++i){
items_[i].~value_type();
}
ACC_ALIGNED_FREE(items_, 16);
}
void helper_push_back(const value_type& t)
{
if(capacity_<=size_){
helper_reserve(capacity_increment_type::getNewCapacity(capacity_));
}
ACC_PLACEMENT_NEW(&items_[size_]) value_type(t);
++size_;
}
void helper_push_back(value_type&& t)
{
if(capacity_<=size_){
helper_reserve(capacity_increment_type::getNewCapacity(capacity_));
}
ACC_PLACEMENT_NEW(&items_[size_]) value_type(move(t));
++size_;
}
void helper_pop_back()
{
ACC_ASSERT(0<size_);
--size_;
items_[size_].~value_type();
}
void helper_clear()
{
for(s32 i = 0; i<size_; ++i){
items_[i].~value_type();
}
size_ = 0;
}
void helper_reserve(size_type capacity)
{
if(capacity<=capacity_){
return;
}
capacity = capacity_increment_type::getInitCapacity(capacity);
value_type* newItems = reinterpret_cast<value_type*>(ACC_ALIGNED_MALLOC(capacity*sizeof(value_type), 16));
//Copy, and destruct
for(s32 i = 0; i<size_; ++i){
ACC_PLACEMENT_NEW(&newItems[i]) value_type(move(items_[i]));
items_[i].~value_type();
}
ACC_ALIGNED_FREE(items_, 16);
items_ = newItems;
capacity_ = capacity;
}
void helper_resize(size_type size)
{
if(size < size_){
//Destruct redundant items
for(s32 i = size; i<size_; ++i){
items_[i].~value_type();
}
} else{
//Construct new items by default constructor
helper_reserve(size);
for(s32 i = size_; i<size; ++i){
ACC_PLACEMENT_NEW(&items_[i]) value_type;
}
}
size_ = size;
}
void helper_removeAt(s32 index)
{
ACC_ASSERT(0<=index && index<size_);
for(s32 i = index+1; i<size_; ++i){
items_[i-1] = move(items_[i]);
}
--size_;
items_[size_].~value_type();
}
size_type capacity_;
size_type size_;
value_type* items_;
};
template<class T, class CapacityIncrement>
class ArrayBuffer<T, CapacityIncrement, std::true_type>
{
protected:
typedef ArrayBuffer<T, CapacityIncrement, std::true_type> this_type;
typedef T value_type;
typedef s32 size_type;
typedef CapacityIncrement capacity_increment_type;
ArrayBuffer(const this_type&) = delete;
this_type& operator=(const this_type&) = delete;
ArrayBuffer()
:capacity_(0)
,size_(0)
,items_(NULL)
{}
ArrayBuffer(this_type&& rhs)
:capacity_(rhs.capacity_)
,size_(rhs.size_)
,items_(rhs.items_)
{
rhs.capacity_ = 0;
rhs.size_ = 0;
rhs.items_ = NULL;
}
explicit ArrayBuffer(size_type capacity)
:capacity_(capacity_increment_type::getInitCapacity(capacity))
,size_(0)
,items_(NULL)
{
ACC_ASSERT(0<=capacity_);
items_ = reinterpret_cast<T*>(ACC_ALIGNED_MALLOC(capacity_*sizeof(T), 16));
}
~ArrayBuffer()
{
for(s32 i = 0; i<size_; ++i){
items_[i].~value_type();
}
ACC_ALIGNED_FREE(items_, 16);
}
void helper_push_back(const value_type& t)
{
if(capacity_<=size_){
helper_reserve(capacity_increment_type::getNewCapacity(capacity_));
}
ACC_PLACEMENT_NEW(&items_[size_]) value_type(t);
++size_;
}
void helper_push_back(value_type&& t)
{
if(capacity_<=size_){
helper_reserve(capacity_increment_type::getNewCapacity(capacity_));
}
ACC_PLACEMENT_NEW(&items_[size_]) value_type(move(t));
++size_;
}
void helper_pop_back()
{
ACC_ASSERT(0<size_);
--size_;
items_[size_].~value_type();
}
void helper_clear()
{
for(s32 i = 0; i<size_; ++i){
items_[i].~value_type();
}
size_ = 0;
}
void helper_reserve(size_type capacity)
{
if(capacity<=capacity_){
return;
}
capacity = capacity_increment_type::getInitCapacity(capacity);
value_type* newItems = reinterpret_cast<value_type*>(ACC_ALIGNED_MALLOC(capacity*sizeof(value_type), 16));
//Copy, and destruct
for(s32 i = 0; i<size_; ++i){
ACC_PLACEMENT_NEW(&newItems[i]) value_type(items_[i]);
items_[i].~value_type();
}
ACC_ALIGNED_FREE(items_, 16);
items_ = newItems;
capacity_ = capacity;
}
void helper_resize(size_type size)
{
if(size < size_){
//Destruct redundant items
for(s32 i = size; i<size_; ++i){
items_[i].~value_type();
}
} else{
//Construct new items by default constructor
helper_reserve(size);
for(s32 i = size_; i<size; ++i){
ACC_PLACEMENT_NEW(&items_[i]) value_type;
}
}
size_ = size;
}
void helper_removeAt(s32 index)
{
ACC_ASSERT(0<=index && index<size_);
for(s32 i = index+1; i<size_; ++i){
items_[i-1] = move(items_[i]);
}
--size_;
items_[size_].~value_type();
}
size_type capacity_;
size_type size_;
value_type* items_;
};
//-------------------------------------------------------
//---
//---
//---
//-------------------------------------------------------
template<class T, class CapacityIncrement=ArrayStaticCapacityIncrement<> >
class Array : public ArrayBuffer<T, CapacityIncrement, typename std::is_trivially_copyable<T>::type>
{
public:
typedef Array<T, CapacityIncrement> this_type;
typedef ArrayBuffer<T, CapacityIncrement, typename std::is_trivially_copyable<T>::type> parent_type;
typedef T value_type;
typedef T* iterator;
typedef const T* const_iterator;
typedef s32 size_type;
typedef CapacityIncrement capacity_increment_type;
/**
@return if lhs<rhs then true else false
*/
typedef bool(*SortCmp)(const T& lhs, const T& rhs);
Array();
Array(this_type&& rhs);
explicit Array(size_type capacity);
~Array();
inline size_type capacity() const;
inline size_type size() const;
inline T& operator[](s32 index);
inline const T& operator[](s32 index) const;
inline T& front();
inline const T& front() const;
inline T& back();
inline const T& back() const;
void push_back(const T& t);
void push_back(T&& t);
void pop_back();
inline iterator begin();
inline const_iterator begin() const;
inline iterator end();
inline const_iterator end() const;
void clear();
void reserve(size_type capacity);
void resize(size_type size);
void removeAt(s32 index);
void swap(this_type& rhs);
this_type& operator=(this_type&& rhs);
s32 find(const T& ptr) const;
void insertionsort(const T& t, SortCmp cmp);
private:
Array(const this_type&) = delete;
this_type& operator=(const this_type&) = delete;
};
template<class T, class CapacityIncrement>
Array<T, CapacityIncrement>::Array()
{
}
template<class T, class CapacityIncrement>
Array<T, CapacityIncrement>::Array(this_type&& rhs)
:parent_type(rhs)
{
}
template<class T, class CapacityIncrement>
Array<T, CapacityIncrement>::Array(size_type capacity)
:parent_type(capacity)
{
}
template<class T, class CapacityIncrement>
Array<T, CapacityIncrement>::~Array()
{
}
template<class T, class CapacityIncrement>
inline typename Array<T, CapacityIncrement>::size_type
Array<T, CapacityIncrement>::capacity() const
{
return capacity_;
}
template<class T, class CapacityIncrement>
inline typename Array<T, CapacityIncrement>::size_type
Array<T, CapacityIncrement>::size() const
{
return size_;
}
template<class T, class CapacityIncrement>
inline T& Array<T, CapacityIncrement>::operator[](s32 index)
{
ACC_ASSERT(0<=index && index<size_);
return items_[index];
}
template<class T, class CapacityIncrement>
inline const T& Array<T, CapacityIncrement>::operator[](s32 index) const
{
ACC_ASSERT(0<=index && index<size_);
return items_[index];
}
template<class T, class CapacityIncrement>
inline T& Array<T, CapacityIncrement>::front()
{
ACC_ASSERT(0<size_);
return items_[0];
}
template<class T, class CapacityIncrement>
inline const T& Array<T, CapacityIncrement>::front() const
{
ACC_ASSERT(0<size_);
return items_[0];
}
template<class T, class CapacityIncrement>
inline T& Array<T, CapacityIncrement>::back()
{
ACC_ASSERT(0<size_);
return items_[size_-1];
}
template<class T, class CapacityIncrement>
inline const T& Array<T, CapacityIncrement>::back() const
{
ACC_ASSERT(0<size_);
return items_[size_-1];
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::push_back(const T& t)
{
helper_push_back(t);
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::push_back(T&& t)
{
helper_push_back(move(t));
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::pop_back()
{
helper_pop_back();
}
template<class T, class CapacityIncrement>
inline typename Array<T, CapacityIncrement>::iterator Array<T, CapacityIncrement>::begin()
{
return items_;
}
template<class T, class CapacityIncrement>
inline typename Array<T, CapacityIncrement>::const_iterator Array<T, CapacityIncrement>::begin() const
{
return items_;
}
template<class T, class CapacityIncrement>
inline typename Array<T, CapacityIncrement>::iterator Array<T, CapacityIncrement>::end()
{
return items_ + size_;
}
template<class T, class CapacityIncrement>
inline typename Array<T, CapacityIncrement>::const_iterator Array<T, CapacityIncrement>::end() const
{
return items_ + size_;
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::clear()
{
helper_clear();
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::reserve(size_type capacity)
{
helper_reserve(capacity);
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::resize(size_type size)
{
helper_resize(size);
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::removeAt(s32 index)
{
helper_removeAt(index);
}
template<class T, class CapacityIncrement>
void Array<T, CapacityIncrement>::swap(this_type& rhs)
{
accel::swap(capacity_, rhs.capacity_);
accel::swap(size_, rhs.size_);
accel::swap(items_, rhs.items_);
}
template<class T, class CapacityIncrement>
typename Array<T, CapacityIncrement>::this_type& Array<T, CapacityIncrement>::operator=(this_type&& rhs)
{
if(this == &rhs){
return;
}
for(s32 i = 0; i<size_; ++i){
items_[i].~value_type();
}
ACC_ALIGNED_FREE(items_, 16);
capacity_ = rhs.capacity_;
size_ = rhs.size_;
items_ = rhs.items_;
rhs.capacity_ = 0;
rhs.size_ = 0;
rhs.items_ = NULL;
}