00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 ** Modified by : Nick Thompson (MMM yyyy) 00026 ** Modified by : Gavin Bell (MMM yyyy) 00027 **=======================================================================*/ 00028 /*======================================================================= 00029 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00030 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00031 *** *** 00032 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00033 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00034 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00035 *** *** 00036 *** RESTRICTED RIGHTS LEGEND *** 00037 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00038 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00039 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00040 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00041 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00042 *** *** 00043 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, *** 00044 *** BORDEAUX, FRANCE *** 00045 *** ALL RIGHTS RESERVED *** 00046 **=======================================================================*/ 00047 /*======================================================================= 00048 ** Modified by : VSG (MMM YYYY) 00049 **=======================================================================*/ 00050 00051 00052 #ifndef _SB_PLIST_ 00053 #define _SB_PLIST_ 00054 00055 #include <Inventor/SbBase.h> 00056 #include <Inventor/STL/cassert> 00057 00058 class SbVec3f; 00059 00076 class SbPList 00077 { 00078 public: 00079 00083 SbPList(); 00084 00090 SbPList(int initSize); 00091 00095 SbPList(const SbPList &pl); 00096 00100 virtual ~SbPList(); 00101 00105 void append(void* ptr); 00106 00110 int find(const void* ptr) const; 00111 00115 void insert(void* ptr, int addBefore); 00116 00120 virtual void remove(int which); 00121 00125 inline int getLength() const 00126 { return nPtrs; } 00127 00131 virtual void truncate(int start); 00132 00136 void copy(const SbPList &pl); 00137 00141 SbPList &operator =(const SbPList &pl); 00142 00147 void *&operator [](const int index) const; 00148 00152 int operator ==(const SbPList &pl) const; 00153 00157 int operator !=(const SbPList &pl) const; 00158 00162 void swap( int index1, int index2 ); 00163 00164 private: 00165 00167 void *get(int i) const; 00168 void set(int i, void *j); 00169 00170 void **getArray() 00171 { return ptrs; } 00172 00173 // internal public call to expand function (see below) in order to reserve more memory in the list. 00174 // same name than stl reserve function 00175 void reserve(int size) 00176 { expand(size); } 00177 00178 private: 00179 // Number of pointers used 00180 int nPtrs; 00181 00182 // There are three(!) methods to expand the list. grow() is used 00183 // when space is dynamically created, and needs to be initialized 00184 // to NULL: 00185 void grow(int max) const; 00186 00187 // setSize is used by grow and in other places internally where we 00188 // know that nothing needs to be initialized to NULL. 00189 void setSize(int size); 00190 00191 private: 00192 00193 // NOTE: this must be called only if the number of elements in the two 00194 // lists is the same, otherwise badness could result 00195 int compare(const SbPList &pl) const; 00196 00197 // The collection of pointers 00198 void **ptrs; 00199 00200 // Number of pointers allocated 00201 int ptrsSize; 00202 00203 // expand is the lowest level routine. It just reallocates the 00204 // array and copies over the old values. 00205 void expand(int size); 00206 00207 }; 00208 00209 inline void* SbPList::get(int i) const 00210 { 00211 assert(i>=0); 00212 return ((i>=0)&&(i<nPtrs))?ptrs[i]:NULL; 00213 } 00214 00215 inline void SbPList::truncate(int start) 00216 { 00217 assert(start>=0); 00218 nPtrs = (start>=0)?start:0; 00219 } 00220 00221 inline void SbPList::append(void * ptr) 00222 { 00223 if (nPtrs + 1 > ptrsSize) 00224 expand(nPtrs + 1); 00225 ptrs[nPtrs++] = ptr; 00226 } 00227 00228 inline void*& SbPList::operator[](const int index) const 00229 { 00230 assert(index>=0); 00231 if (index>= nPtrs) 00232 grow(index); 00233 return ptrs[index]; 00234 } 00235 00236 00237 // Keep include for compatibility 00238 #include <Inventor/lists/SbIntList.h> 00239 #include <Inventor/lists/SbVec3fList.h> 00240 #include <Inventor/lists/SbStringList.h> 00241 00242 #endif 00243