14
14
15
15
namespace Slang
16
16
{
17
-
18
- template <typename T, int isPOD>
19
- class Initializer
20
- {
21
-
22
- };
23
-
24
- template <typename T>
25
- class Initializer <T, 0 >
26
- {
27
- public:
28
- static void initialize (T* buffer, int size)
29
- {
30
- for (int i = 0 ; i<size; i++)
31
- new (buffer + i) T ();
32
- }
33
- };
34
- template <typename T>
35
- class Initializer <T, 1 >
36
- {
37
- public:
38
- static void initialize (T* buffer, int size)
39
- {
40
- // It's pod so no initialization required
41
- // for (int i = 0; i < size; i++)
42
- // new (buffer + i) T;
43
- }
44
- };
45
-
46
- template <typename T, typename TAllocator>
47
- class AllocateMethod
48
- {
49
- public:
50
- static inline T* allocateArray (Index count)
51
- {
52
- TAllocator allocator;
53
- T * rs = (T*)allocator.allocate (count * sizeof (T));
54
- Initializer<T, std::is_pod<T>::value>::initialize (rs, count);
55
- return rs;
56
- }
57
- static inline void deallocateArray (T* ptr, Index count)
58
- {
59
- TAllocator allocator;
60
- if (!std::is_trivially_destructible<T>::value)
61
- {
62
- for (Index i = 0 ; i < count; i++)
63
- ptr[i].~T ();
64
- }
65
- allocator.deallocate (ptr);
66
- }
67
- };
68
-
69
- template <typename T>
70
- class AllocateMethod <T, StandardAllocator>
71
- {
72
- public:
73
- static inline T* allocateArray (Index count)
74
- {
75
- return new T[count];
76
- }
77
- static inline void deallocateArray (T* ptr, Index /* bufferSize*/ )
78
- {
79
- delete [] ptr;
80
- }
81
- };
82
-
83
17
// List is container of values of a type held consecutively in memory (much like std::vector)
84
18
//
85
19
// Note that in this implementation, the underlying memory is backed via an allocation of T[capacity]
@@ -102,6 +36,7 @@ namespace Slang
102
36
}
103
37
template <typename ... Args>
104
38
List (const T& val, Args... args)
39
+ : m_buffer(nullptr ), m_count(0 ), m_capacity(0 )
105
40
{
106
41
_init (val, args...);
107
42
}
@@ -611,13 +546,19 @@ namespace Slang
611
546
{
612
547
return AllocateMethod<T, TAllocator>::allocateArray (count);
613
548
}
549
+ static void _free (T* buffer, Index count)
550
+ {
551
+ return AllocateMethod<T, TAllocator>::deallocateArray (buffer, count);
552
+ }
614
553
615
554
template <typename ... Args>
616
555
void _init (const T& val, Args... args)
617
556
{
618
557
add (val);
619
558
_init (args...);
620
559
}
560
+
561
+ void _init () {}
621
562
};
622
563
623
564
template <typename T>
0 commit comments