#include <ps_attrib.h>
Definition at line 45 of file ps_attrib.h.
Public Types | |
| typedef const T * | const_iterator |
| typedef T * | iterator |
| typedef T | value_type |
Public Member Functions | |
| const T & | back () const |
| T & | back () |
| const_iterator | begin (void) const |
| iterator | begin (void) |
| uint | capacity () const |
| void | clear () |
| CSnappedVector () | |
| bool | empty () const |
| const_iterator | end (void) const |
| iterator | end (void) |
| const T & | operator[] (uint index) const |
| T & | operator[] (uint index) |
| void | pop_back () |
| void | push_back (const T &t) |
| void | reserve (uint capacity) |
| set a new usable size | |
| void | resize (uint size) |
| void | serial (NLMISC::IStream &f) throw (NLMISC::EStream) |
| serialization | |
| uint | size () const |
| ~CSnappedVector () | |
Protected Attributes | |
| uint32 | _Capacity |
| uint32 | _Size |
| uint8 * | _Start |
| T * | _Tab |
|
|||||
|
Definition at line 49 of file ps_attrib.h. Referenced by NL3D::CSnappedVector< T, snapPower >::begin(), and NL3D::CSnappedVector< T, snapPower >::end(). |
|
|||||
|
|||||
|
Definition at line 50 of file ps_attrib.h. |
|
|||||||||
|
Definition at line 52 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Start, and NL3D::CSnappedVector< T, snapPower >::_Tab.
|
|
|||||||||
|
Definition at line 53 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Start, NL3D::CSnappedVector< T, snapPower >::_Tab, NL3D::CSnappedVector< T, snapPower >::iterator, and nlassert.
|
|
|||||||||
|
Definition at line 90 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and nlassert.
|
|
|||||||||
|
Definition at line 82 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and nlassert.
|
|
||||||||||
|
Definition at line 63 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and NL3D::CSnappedVector< T, snapPower >::const_iterator.
00063 { return _Tab; }
|
|
||||||||||
|
Definition at line 62 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and NL3D::CSnappedVector< T, snapPower >::iterator.
00062 { return _Tab; }
|
|
|||||||||
|
Definition at line 210 of file ps_attrib.h. References uint.
00210 { return _Capacity; }
|
|
|||||||||
|
Definition at line 240 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::resize(). Referenced by NL3D::CSnappedVector< T, snapPower >::serial().
00240 { resize(0); }
|
|
|||||||||
|
Definition at line 98 of file ps_attrib.h.
00098 { return _Size == 0; }
|
|
||||||||||
|
Definition at line 65 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and NL3D::CSnappedVector< T, snapPower >::const_iterator.
|
|
||||||||||
|
Definition at line 64 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and NL3D::CSnappedVector< T, snapPower >::iterator.
|
|
||||||||||
|
Definition at line 74 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, index, nlassert, and uint.
|
|
||||||||||
|
Definition at line 67 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, index, nlassert, and uint.
|
|
|||||||||
|
Definition at line 202 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, and nlassert.
|
|
||||||||||
|
Definition at line 171 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, nlassert, NL3D::CSnappedVector< T, snapPower >::reserve(), and t. Referenced by NL3D::CSnappedVector< T, snapPower >::serial().
00172 {
00173 if (!_Size)
00174 {
00175 reserve(2);
00176 new ((void *) _Tab) T(t);
00177 _Size = 1;
00178 }
00179 else
00180 if (_Size < _Capacity)
00181 {
00182 new ((void *) (_Tab + _Size)) T(t);
00183 ++_Size;
00184 }
00185 else
00186 if (_Size == _Capacity)
00187 {
00188 if (_Capacity == 1)
00189 {
00190 reserve(2);
00191 }
00192 else
00193 {
00194 reserve(_Capacity + (_Capacity>>1));
00195 }
00196 nlassert(_Size <= _Capacity);
00197 new ((void *) (_Tab + _Size)) T(t);
00198 ++_Size;
00199 }
00200 }
|
|
||||||||||
|
set a new usable size
Definition at line 101 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Start, NL3D::CSnappedVector< T, snapPower >::_Tab, NL3D::CSnappedVector< T, snapPower >::iterator, nlassert, src, uint, and uint8. Referenced by NL3D::CSnappedVector< T, snapPower >::push_back(), NL3D::CSnappedVector< T, snapPower >::resize(), and NL3D::CSnappedVector< T, snapPower >::serial().
00102 {
00103 if (capacity < _Capacity) return;
00104 uint8 *newStart = NULL;
00105 try
00106 {
00107 newStart = new uint8[sizeof(T) * capacity + (1 << snapPower)];
00108 T *newTab = (T *) ( (uint) (newStart + (1 << snapPower)) & ~((1 << snapPower) - 1)); // snap to a page
00109
00110
00111
00112 for (iterator src = _Tab, end = _Tab + (capacity < _Size ? capacity : _Size), dest = newTab;
00113 src != end;
00114 ++ src, ++dest)
00115 {
00116 new ((void *) dest) T(*src); // copy object
00117 }
00118
00119 // swap datas
00120 std::swap(_Start, newStart);
00121 std::swap(_Tab, newTab);
00122
00123 // destroy previous objects. We assume that we can't have exceptions raised from destructors
00124 for (iterator it = newTab /* old tab */, endIt = newTab + _Size; it != endIt; ++ it)
00125 {
00126 it->~T();
00127 }
00128
00129 // set new size
00130 _Capacity = capacity;
00131 _Size = capacity < _Size ? capacity : _Size;
00132
00133
00134 // delete old vect (that was swapped with the new one)
00135 delete [] newStart;
00136 nlassert(_Size <= _Capacity);
00137 }
00138 catch (...)
00139 {
00140 delete [] newStart;
00141 throw;
00142 }
00143
00144 }
|
|
||||||||||
|
Definition at line 145 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, NL3D::CSnappedVector< T, snapPower >::iterator, nlassert, NL3D::CSnappedVector< T, snapPower >::reserve(), size, and uint. Referenced by NL3D::CSnappedVector< T, snapPower >::clear().
00146 {
00147 nlassert(size < (1 << 16));
00148 if (size < _Size)
00149 {
00150 for (iterator it = _Tab + size, endIt = _Tab + _Size; it != endIt; ++it)
00151 {
00152 it->~T();
00153 }
00154 }
00155 else
00156 {
00157 if (size > _Capacity)
00158 {
00159 reserve(size);
00160 }
00161 for (iterator it = _Tab + _Size, endIt = _Tab + size; it != endIt; ++it)
00162 {
00163 new ((void *) it) T();
00164 }
00165 }
00166
00167 _Size = size;
00168 nlassert(_Size <= _Capacity);
00169 }
|
|
||||||||||
|
serialization
Definition at line 214 of file ps_attrib.h. References NL3D::CSnappedVector< T, snapPower >::_Tab, NL3D::CSnappedVector< T, snapPower >::clear(), NL3D::CSnappedVector< T, snapPower >::push_back(), NL3D::CSnappedVector< T, snapPower >::reserve(), size, uint, and uint32.
00215 {
00216 if (f.isReading())
00217 {
00218 clear();
00219 uint32 size, maxsize;
00220 f.serial(size, maxsize);
00221 reserve(maxsize);
00222 for (uint k = 0; k < size; ++k)
00223 {
00224 T tmp;
00225 f.serial(tmp);
00226 push_back(tmp);
00227 }
00228 }
00229 else
00230 {
00231 f.serial(_Size, _Capacity);
00232 for (uint k = 0; k < _Size; ++k)
00233 {
00234 f.serial(_Tab[k]);
00235 }
00236 }
00237 }
|
|
|||||||||
|
Definition at line 211 of file ps_attrib.h. References uint.
00211 { return _Size; }
|
|
|||||
|
Definition at line 247 of file ps_attrib.h. |
|
|||||
|
Definition at line 246 of file ps_attrib.h. |
|
|||||
|
Definition at line 244 of file ps_attrib.h. Referenced by NL3D::CSnappedVector< T, snapPower >::CSnappedVector(), NL3D::CSnappedVector< T, snapPower >::reserve(), and NL3D::CSnappedVector< T, snapPower >::~CSnappedVector(). |
|
|||||
1.3.6