1 
2 #include <memory.h>
3 #include <math.h>
4 
5 #include <sdai.h>
6 #include "sc_memmgr.h"
7 
8 // to help ObjectCenter
9 #ifndef HAVE_MEMMOVE
10 extern "C"
11 {
12     void * memmove( void * __s1, const void * __s2, size_t __n );
13 }
14 #endif
15 
16 
SDAI_PID()17 SDAI_PID::SDAI_PID() {
18 }
19 
~SDAI_PID()20 SDAI_PID::~SDAI_PID() {
21 }
22 
SDAI_PID_DA()23 SDAI_PID_DA::SDAI_PID_DA() {
24 }
25 
~SDAI_PID_DA()26 SDAI_PID_DA::~SDAI_PID_DA() {
27 }
28 
SDAI_PID_SDAI()29 SDAI_PID_SDAI::SDAI_PID_SDAI() {
30 }
31 
~SDAI_PID_SDAI()32 SDAI_PID_SDAI::~SDAI_PID_SDAI() {
33 }
34 
SDAI_DAObject()35 SDAI_DAObject::SDAI_DAObject() {
36 }
37 
~SDAI_DAObject()38 SDAI_DAObject::~SDAI_DAObject() {
39 }
40 
SDAI_DAObject_SDAI()41 SDAI_DAObject_SDAI::SDAI_DAObject_SDAI() {
42 }
43 
44 /*
45 SDAI_DAObject_SDAI::SDAI_DAObject_SDAI(const DAObject_SDAI&)
46 {
47 }
48 */
49 
~SDAI_DAObject_SDAI()50 SDAI_DAObject_SDAI::~SDAI_DAObject_SDAI() {
51 }
52 
53 /*
54  * Copyright (c) 1990, 1991 Stanford University
55  *
56  * Permission to use, copy, modify, distribute, and sell this software and its
57  * documentation for any purpose is hereby granted without fee, provided
58  * that the above copyright notice appear in all copies and that both that
59  * copyright notice and this permission notice appear in supporting
60  * documentation, and that the name of Stanford not be used in advertising or
61  * publicity pertaining to distribution of the software without specific,
62  * written prior permission.  Stanford makes no representations about
63  * the suitability of this software for any purpose.  It is provided "as is"
64  * without express or implied warranty.
65  *
66  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
67  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
68  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
69  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
70  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
71  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
72  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
73  */
74 
75 /*
76  * UArray implementation.
77  */
78 
79 /*****************************************************************************/
80 
SDAI_DAObject__set(int defaultSize)81 SDAI_DAObject__set::SDAI_DAObject__set( int defaultSize ) {
82     _bufsize = defaultSize;
83     _buf = new SDAI_DAObject_ptr[_bufsize];
84     _count = 0;
85 }
86 
~SDAI_DAObject__set()87 SDAI_DAObject__set::~SDAI_DAObject__set() {
88     delete _buf;
89 }
90 
Check(int index)91 void SDAI_DAObject__set::Check( int index ) {
92 
93     SDAI_DAObject_ptr * newbuf;
94 
95     if( index >= _bufsize ) {
96         _bufsize = ( index + 1 ) * 2;
97         newbuf = new SDAI_DAObject_ptr[_bufsize];
98         memmove( newbuf, _buf, _count * sizeof( SDAI_DAObject_ptr ) );
99         delete _buf;
100         _buf = newbuf;
101     }
102 }
103 
104 void
Insert(SDAI_DAObject_ptr v,int index)105 SDAI_DAObject__set::Insert( SDAI_DAObject_ptr v, int index ) {
106 
107     SDAI_DAObject_ptr * spot;
108     index = ( index < 0 ) ? _count : index;
109 
110     if( index < _count ) {
111         Check( _count + 1 );
112         spot = &_buf[index];
113         memmove( spot + 1, spot, ( _count - index )*sizeof( SDAI_DAObject_ptr ) );
114 
115     } else {
116         Check( index );
117         spot = &_buf[index];
118     }
119     *spot = v;
120     ++_count;
121 }
122 
Append(SDAI_DAObject_ptr v)123 void SDAI_DAObject__set::Append( SDAI_DAObject_ptr v ) {
124 
125     int index = _count;
126     SDAI_DAObject_ptr * spot;
127 
128     if( index < _count ) {
129         Check( _count + 1 );
130         spot = &_buf[index];
131         memmove( spot + 1, spot, ( _count - index )*sizeof( SDAI_DAObject_ptr ) );
132 
133     } else {
134         Check( index );
135         spot = &_buf[index];
136     }
137     *spot = v;
138     ++_count;
139 }
140 
Remove(int index)141 void SDAI_DAObject__set::Remove( int index ) {
142 
143     if( 0 <= index && index < _count ) {
144         --_count;
145         SDAI_DAObject_ptr * spot = &_buf[index];
146         memmove( spot, spot + 1, ( _count - index )*sizeof( SDAI_DAObject_ptr ) );
147     }
148 }
149 
Index(SDAI_DAObject_ptr v)150 int SDAI_DAObject__set::Index( SDAI_DAObject_ptr v ) {
151 
152     for( int i = 0; i < _count; ++i ) {
153         if( _buf[i] == v ) {
154             return i;
155         }
156     }
157     return -1;
158 }
159 
160 SDAI_DAObject_ptr
retrieve(int index)161 SDAI_DAObject__set::retrieve( int index ) {
162     return operator[]( index );
163 }
164 
operator [](int index)165 SDAI_DAObject_ptr & SDAI_DAObject__set::operator[]( int index ) {
166 
167     Check( index );
168 //    _count = max(_count, index+1);
169     _count = ( ( _count > index + 1 ) ? _count : ( index + 1 ) );
170     return _buf[index];
171 }
172 
173 int
Count()174 SDAI_DAObject__set::Count() {
175     return _count;
176 }
177 
178 int
is_empty()179 SDAI_DAObject__set::is_empty() {
180     return _count;
181 }
182 
183 void
Clear()184 SDAI_DAObject__set::Clear() {
185     _count = 0;
186 }
187