/src/assimp/contrib/Open3DGC/o3dgcVector.h
Line | Count | Source |
1 | | /* |
2 | | Copyright (c) 2013 Khaled Mammou - Advanced Micro Devices, Inc. |
3 | | |
4 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | | of this software and associated documentation files (the "Software"), to deal |
6 | | in the Software without restriction, including without limitation the rights |
7 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
8 | | copies of the Software, and to permit persons to whom the Software is |
9 | | furnished to do so, subject to the following conditions: |
10 | | |
11 | | The above copyright notice and this permission notice shall be included in |
12 | | all copies or substantial portions of the Software. |
13 | | |
14 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
15 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
16 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
17 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
18 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
19 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20 | | THE SOFTWARE. |
21 | | */ |
22 | | |
23 | | #pragma once |
24 | | #ifndef O3DGC_VECTOR_H |
25 | | #define O3DGC_VECTOR_H |
26 | | |
27 | | #include "o3dgcCommon.h" |
28 | | |
29 | | namespace o3dgc |
30 | | { |
31 | | const unsigned long O3DGC_DEFAULT_VECTOR_SIZE = 32; |
32 | | |
33 | | //! |
34 | | template < typename T > class Vector |
35 | | { |
36 | | public: |
37 | | //! Constructor. |
38 | | Vector() |
39 | 0 | { |
40 | 0 | m_allocated = 0; |
41 | 0 | m_size = 0; |
42 | 0 | m_buffer = 0; |
43 | 0 | }; Unexecuted instantiation: o3dgc::Vector<unsigned char>::Vector() Unexecuted instantiation: o3dgc::Vector<long>::Vector() Unexecuted instantiation: o3dgc::Vector<char>::Vector() |
44 | | //! Destructor. |
45 | | ~Vector(void) |
46 | 0 | { |
47 | 0 | delete [] m_buffer; |
48 | 0 | }; Unexecuted instantiation: o3dgc::Vector<unsigned char>::~Vector() Unexecuted instantiation: o3dgc::Vector<long>::~Vector() Unexecuted instantiation: o3dgc::Vector<char>::~Vector() |
49 | | T & operator[](unsigned long i) |
50 | 0 | { |
51 | 0 | return m_buffer[i]; |
52 | 0 | } Unexecuted instantiation: o3dgc::Vector<char>::operator[](unsigned long) Unexecuted instantiation: o3dgc::Vector<long>::operator[](unsigned long) Unexecuted instantiation: o3dgc::Vector<unsigned char>::operator[](unsigned long) |
53 | | const T & operator[](unsigned long i) const |
54 | 0 | { |
55 | 0 | return m_buffer[i]; |
56 | 0 | } Unexecuted instantiation: o3dgc::Vector<unsigned char>::operator[](unsigned long) const Unexecuted instantiation: o3dgc::Vector<long>::operator[](unsigned long) const |
57 | | void Allocate(unsigned long size) |
58 | 0 | { |
59 | 0 | if (size > m_allocated) |
60 | 0 | { |
61 | 0 | m_allocated = size; |
62 | 0 | T * tmp = new T [m_allocated]; |
63 | 0 | if (m_size > 0) |
64 | 0 | { |
65 | 0 | memcpy(tmp, m_buffer, m_size * sizeof(T) ); |
66 | 0 | delete [] m_buffer; |
67 | 0 | } |
68 | 0 | m_buffer = tmp; |
69 | 0 | } |
70 | 0 | }; Unexecuted instantiation: o3dgc::Vector<unsigned char>::Allocate(unsigned long) Unexecuted instantiation: o3dgc::Vector<long>::Allocate(unsigned long) Unexecuted instantiation: o3dgc::Vector<char>::Allocate(unsigned long) |
71 | | void PushBack(const T & value) |
72 | 0 | { |
73 | 0 | if (m_size == m_allocated) |
74 | 0 | { |
75 | 0 | m_allocated *= 2; |
76 | 0 | if (m_allocated < O3DGC_DEFAULT_VECTOR_SIZE) |
77 | 0 | { |
78 | 0 | m_allocated = O3DGC_DEFAULT_VECTOR_SIZE; |
79 | 0 | } |
80 | 0 | T * tmp = new T [m_allocated]; |
81 | 0 | if (m_size > 0) |
82 | 0 | { |
83 | 0 | memcpy(tmp, m_buffer, m_size * sizeof(T) ); |
84 | 0 | delete [] m_buffer; |
85 | 0 | } |
86 | 0 | m_buffer = tmp; |
87 | 0 | } |
88 | 0 | assert(m_size < m_allocated); |
89 | 0 | m_buffer[m_size++] = value; |
90 | 0 | } Unexecuted instantiation: o3dgc::Vector<char>::PushBack(char const&) Unexecuted instantiation: o3dgc::Vector<unsigned char>::PushBack(unsigned char const&) Unexecuted instantiation: o3dgc::Vector<long>::PushBack(long const&) |
91 | 0 | const T * GetBuffer() const { return m_buffer;}; |
92 | 0 | T * GetBuffer() { return m_buffer;}; |
93 | 0 | unsigned long GetSize() const { return m_size;};Unexecuted instantiation: o3dgc::Vector<unsigned char>::GetSize() const Unexecuted instantiation: o3dgc::Vector<long>::GetSize() const |
94 | | void SetSize(unsigned long size) |
95 | 0 | { |
96 | 0 | assert(size <= m_allocated); |
97 | 0 | m_size = size; |
98 | 0 | }; |
99 | | unsigned long GetAllocatedSize() const { return m_allocated;}; |
100 | 0 | void Clear(){ m_size = 0;};Unexecuted instantiation: o3dgc::Vector<long>::Clear() Unexecuted instantiation: o3dgc::Vector<char>::Clear() |
101 | | |
102 | | private: |
103 | | T * m_buffer; |
104 | | unsigned long m_allocated; |
105 | | unsigned long m_size; |
106 | | }; |
107 | | |
108 | | |
109 | | |
110 | | |
111 | | //! Vector dim 3. |
112 | | template < typename T > class Vec3 |
113 | | { |
114 | | public: |
115 | | T & operator[](unsigned long i) { return m_data[i];} |
116 | | const T & operator[](unsigned long i) const { return m_data[i];} |
117 | | T & X(); |
118 | | T & Y(); |
119 | | T & Z(); |
120 | | const T & X() const; |
121 | | const T & Y() const; |
122 | | const T & Z() const; |
123 | | double GetNorm() const; |
124 | | void operator= (const Vec3 & rhs); |
125 | | void operator+=(const Vec3 & rhs); |
126 | | void operator-=(const Vec3 & rhs); |
127 | | void operator-=(T a); |
128 | | void operator+=(T a); |
129 | | void operator/=(T a); |
130 | | void operator*=(T a); |
131 | | Vec3 operator^ (const Vec3 & rhs) const; |
132 | | T operator* (const Vec3 & rhs) const; |
133 | | Vec3 operator+ (const Vec3 & rhs) const; |
134 | | Vec3 operator- (const Vec3 & rhs) const; |
135 | | Vec3 operator- () const; |
136 | | Vec3 operator* (T rhs) const; |
137 | | Vec3 operator/ (T rhs) const; |
138 | | Vec3(); |
139 | | Vec3(T a); |
140 | | Vec3(T x, T y, T z); |
141 | | Vec3(const Vec3 & rhs); |
142 | | ~Vec3(void); |
143 | | |
144 | | private: |
145 | | T m_data[3]; |
146 | | }; |
147 | | //! Vector dim 2. |
148 | | template < typename T > class Vec2 |
149 | | { |
150 | | public: |
151 | | T & operator[](unsigned long i) { return m_data[i];} |
152 | | const T & operator[](unsigned long i) const { return m_data[i];} |
153 | | T & X(); |
154 | | T & Y(); |
155 | | const T & X() const; |
156 | | const T & Y() const; |
157 | | double GetNorm() const; |
158 | | void operator= (const Vec2 & rhs); |
159 | | void operator+=(const Vec2 & rhs); |
160 | | void operator-=(const Vec2 & rhs); |
161 | | void operator-=(T a); |
162 | | void operator+=(T a); |
163 | | void operator/=(T a); |
164 | | void operator*=(T a); |
165 | | T operator^ (const Vec2 & rhs) const; |
166 | | T operator* (const Vec2 & rhs) const; |
167 | | Vec2 operator+ (const Vec2 & rhs) const; |
168 | | Vec2 operator- (const Vec2 & rhs) const; |
169 | | Vec2 operator- () const; |
170 | | Vec2 operator* (T rhs) const; |
171 | | Vec2 operator/ (T rhs) const; |
172 | | Vec2(); |
173 | | Vec2(T a); |
174 | | Vec2(T x, T y); |
175 | | Vec2(const Vec2 & rhs); |
176 | | ~Vec2(void); |
177 | | |
178 | | private: |
179 | | T m_data[2]; |
180 | | }; |
181 | | } |
182 | | #include "o3dgcVector.inl" // template implementation |
183 | | #endif // O3DGC_VECTOR_H |
184 | | |