~ubuntu-branches/ubuntu/maverick/blender/maverick

« back to all changes in this revision

Viewing changes to extern/bullet2/src/LinearMath/btAlignedObjectArray.h

  • Committer: Bazaar Package Importer
  • Author(s): Khashayar Naderehvandi, Khashayar Naderehvandi, Alessio Treglia
  • Date: 2009-01-22 16:53:59 UTC
  • mfrom: (14.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090122165359-v0996tn7fbit64ni
Tags: 2.48a+dfsg-1ubuntu1
[ Khashayar Naderehvandi ]
* Merge from debian experimental (LP: #320045), Ubuntu remaining changes:
  - Add patch correcting header file locations.
  - Add libvorbis-dev and libgsm1-dev to Build-Depends.
  - Use avcodec_decode_audio2() in source/blender/src/hddaudio.c

[ Alessio Treglia ]
* Add missing previous changelog entries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#endif //BT_USE_PLACEMENT_NEW
40
40
 
41
41
 
42
 
///btAlignedObjectArray uses a subset of the stl::vector interface for its methods
43
 
///It is developed to replace stl::vector to avoid STL alignment issues to add SIMD/SSE data
 
42
///The btAlignedObjectArray template class uses a subset of the stl::vector interface for its methods
 
43
///It is developed to replace stl::vector to avoid portability issues, including STL alignment issues to add SIMD/SSE data
44
44
template <typename T> 
45
45
//template <class T> 
46
46
class btAlignedObjectArray
50
50
        int                                     m_size;
51
51
        int                                     m_capacity;
52
52
        T*                                      m_data;
 
53
        //PCK: added this line
 
54
        bool                            m_ownsMemory;
53
55
 
54
56
        protected:
55
57
                SIMD_FORCE_INLINE       int     allocSize(int size)
69
71
 
70
72
                SIMD_FORCE_INLINE       void    init()
71
73
                {
 
74
                        //PCK: added this line
 
75
                        m_ownsMemory = true;
72
76
                        m_data = 0;
73
77
                        m_size = 0;
74
78
                        m_capacity = 0;
92
96
                SIMD_FORCE_INLINE       void    deallocate()
93
97
                {
94
98
                        if(m_data)      {
95
 
                                m_allocator.deallocate(m_data);
 
99
                                //PCK: enclosed the deallocation in this block
 
100
                                if (m_ownsMemory)
 
101
                                {
 
102
                                        m_allocator.deallocate(m_data);
 
103
                                }
96
104
                                m_data = 0;
97
105
                        }
98
106
                }
223
231
                                destroy(0,size());
224
232
 
225
233
                                deallocate();
 
234
                                
 
235
                                //PCK: added this line
 
236
                                m_ownsMemory = true;
226
237
 
227
238
                                m_data = s;
228
239
                                
242
253
                                }
243
254
                };
244
255
        
 
256
                template <typename L>
 
257
                void quickSortInternal(L CompareFunc,int lo, int hi)
 
258
                {
 
259
                //  lo is the lower index, hi is the upper index
 
260
                //  of the region of array a that is to be sorted
 
261
                        int i=lo, j=hi;
 
262
                        T x=m_data[(lo+hi)/2];
 
263
 
 
264
                        //  partition
 
265
                        do
 
266
                        {    
 
267
                                while (CompareFunc(m_data[i],x)) 
 
268
                                        i++; 
 
269
                                while (CompareFunc(x,m_data[j])) 
 
270
                                        j--;
 
271
                                if (i<=j)
 
272
                                {
 
273
                                        swap(i,j);
 
274
                                        i++; j--;
 
275
                                }
 
276
                        } while (i<=j);
 
277
 
 
278
                        //  recursion
 
279
                        if (lo<j) 
 
280
                                quickSortInternal( CompareFunc, lo, j);
 
281
                        if (i<hi) 
 
282
                                quickSortInternal( CompareFunc, i, hi);
 
283
                }
 
284
 
 
285
 
 
286
                template <typename L>
 
287
                void quickSort(L CompareFunc)
 
288
                {
 
289
                        //don't sort 0 or 1 elements
 
290
                        if (size()>1)
 
291
                        {
 
292
                                quickSortInternal(CompareFunc,0,size()-1);
 
293
                        }
 
294
                }
 
295
 
245
296
 
246
297
                ///heap sort from http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Sort/Heap/
247
298
                template <typename L>
360
411
                }
361
412
        }
362
413
 
 
414
        //PCK: whole function
 
415
        void initializeFromBuffer(void *buffer, int size, int capacity)
 
416
        {
 
417
                clear();
 
418
                m_ownsMemory = false;
 
419
                m_data = (T*)buffer;
 
420
                m_size = size;
 
421
                m_capacity = capacity;
 
422
        }
 
423
 
363
424
};
364
425
 
365
426
#endif //BT_OBJECT_ARRAY__
366
 
 
367