diff options
author | dan miller | 2007-10-19 05:20:48 +0000 |
---|---|---|
committer | dan miller | 2007-10-19 05:20:48 +0000 |
commit | d48ea5bb797037069d641da41da0f195f0124491 (patch) | |
tree | 40ff433d94859d629aac933d5ec73b382f62ba1a /libraries/ode-0.9/ode/src/array.cpp | |
parent | dont ask (diff) | |
download | opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.zip opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.tar.gz opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.tar.bz2 opensim-SC_OLD-d48ea5bb797037069d641da41da0f195f0124491.tar.xz |
one more for the gipper
Diffstat (limited to 'libraries/ode-0.9/ode/src/array.cpp')
-rw-r--r-- | libraries/ode-0.9/ode/src/array.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/libraries/ode-0.9/ode/src/array.cpp b/libraries/ode-0.9/ode/src/array.cpp new file mode 100644 index 0000000..cbb1a6e --- /dev/null +++ b/libraries/ode-0.9/ode/src/array.cpp | |||
@@ -0,0 +1,80 @@ | |||
1 | /************************************************************************* | ||
2 | * * | ||
3 | * Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. * | ||
4 | * All rights reserved. Email: russ@q12.org Web: www.q12.org * | ||
5 | * * | ||
6 | * This library is free software; you can redistribute it and/or * | ||
7 | * modify it under the terms of EITHER: * | ||
8 | * (1) The GNU Lesser General Public License as published by the Free * | ||
9 | * Software Foundation; either version 2.1 of the License, or (at * | ||
10 | * your option) any later version. The text of the GNU Lesser * | ||
11 | * General Public License is included with this library in the * | ||
12 | * file LICENSE.TXT. * | ||
13 | * (2) The BSD-style license that is included with this library in * | ||
14 | * the file LICENSE-BSD.TXT. * | ||
15 | * * | ||
16 | * This library is distributed in the hope that it will be useful, * | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files * | ||
19 | * LICENSE.TXT and LICENSE-BSD.TXT for more details. * | ||
20 | * * | ||
21 | *************************************************************************/ | ||
22 | |||
23 | #include <ode/config.h> | ||
24 | #include <ode/memory.h> | ||
25 | #include <ode/error.h> | ||
26 | #include "array.h" | ||
27 | |||
28 | |||
29 | static inline int roundUpToPowerOfTwo (int x) | ||
30 | { | ||
31 | int i = 1; | ||
32 | while (i < x) i <<= 1; | ||
33 | return i; | ||
34 | } | ||
35 | |||
36 | |||
37 | void dArrayBase::_freeAll (int sizeofT) | ||
38 | { | ||
39 | if (_data) { | ||
40 | if (_data == this+1) return; // if constructLocalArray() was called | ||
41 | dFree (_data,_anum * sizeofT); | ||
42 | } | ||
43 | } | ||
44 | |||
45 | |||
46 | void dArrayBase::_setSize (int newsize, int sizeofT) | ||
47 | { | ||
48 | if (newsize < 0) return; | ||
49 | if (newsize > _anum) { | ||
50 | if (_data == this+1) { | ||
51 | // this is a no-no, because constructLocalArray() was called | ||
52 | dDebug (0,"setSize() out of space in LOCAL array"); | ||
53 | } | ||
54 | int newanum = roundUpToPowerOfTwo (newsize); | ||
55 | if (_data) _data = dRealloc (_data, _anum*sizeofT, newanum*sizeofT); | ||
56 | else _data = dAlloc (newanum*sizeofT); | ||
57 | _anum = newanum; | ||
58 | } | ||
59 | _size = newsize; | ||
60 | } | ||
61 | |||
62 | |||
63 | void * dArrayBase::operator new (size_t size) | ||
64 | { | ||
65 | return dAlloc (size); | ||
66 | } | ||
67 | |||
68 | |||
69 | void dArrayBase::operator delete (void *ptr, size_t size) | ||
70 | { | ||
71 | dFree (ptr,size); | ||
72 | } | ||
73 | |||
74 | |||
75 | void dArrayBase::constructLocalArray (int __anum) | ||
76 | { | ||
77 | _size = 0; | ||
78 | _anum = __anum; | ||
79 | _data = this+1; | ||
80 | } | ||