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-2020 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 00077 class SbPList 00078 { 00079 public: 00080 00084 SbPList(); 00085 00091 SbPList(int initSize); 00092 00096 SbPList(const SbPList &pl); 00097 00101 virtual ~SbPList(); 00102 00106 void append(void* ptr); 00107 00111 int find(const void* ptr) const; 00112 00116 void insert(void* ptr, int addBefore); 00117 00121 virtual void remove(int which); 00122 00126 inline int getLength() const 00127 { return nPtrs; } 00128 00132 virtual void truncate(int start); 00133 00137 void copy(const SbPList &pl); 00138 00142 SbPList &operator =(const SbPList &pl); 00143 00148 void *&operator [](const int index) const; 00149 00153 int operator ==(const SbPList &pl) const; 00154 00158 int operator !=(const SbPList &pl) const; 00159 00163 void swap( int index1, int index2 ); 00164 00165 private: 00166 00168 void *get(int i) const; 00169 void set(int i, void *j); 00170 00171 void **getArray() 00172 { return ptrs; } 00173 00174 // internal public call to expand function (see below) in order to reserve more memory in the list. 00175 // same name than stl reserve function 00176 void reserve(int size) 00177 { expand(size); } 00178 00179 private: 00180 // Number of pointers used 00181 int nPtrs; 00182 00183 // There are three(!) methods to expand the list. grow() is used 00184 // when space is dynamically created, and needs to be initialized 00185 // to NULL: 00186 void grow(int max) const; 00187 00188 // setSize is used by grow and in other places internally where we 00189 // know that nothing needs to be initialized to NULL. 00190 void setSize(int size); 00191 00192 private: 00193 00194 // NOTE: this must be called only if the number of elements in the two 00195 // lists is the same, otherwise badness could result 00196 int compare(const SbPList &pl) const; 00197 00198 // The collection of pointers 00199 void **ptrs; 00200 00201 // Number of pointers allocated 00202 int ptrsSize; 00203 00204 // expand is the lowest level routine. It just reallocates the 00205 // array and copies over the old values. 00206 void expand(int size); 00207 00208 }; 00209 00210 inline void* SbPList::get(int i) const 00211 { 00212 assert(i>=0); 00213 return ((i>=0)&&(i<nPtrs))?ptrs[i]:NULL; 00214 } 00215 00216 inline void SbPList::truncate(int start) 00217 { 00218 assert(start>=0); 00219 nPtrs = (start>=0)?start:0; 00220 } 00221 00222 inline void SbPList::append(void * ptr) 00223 { 00224 if (nPtrs + 1 > ptrsSize) 00225 expand(nPtrs + 1); 00226 ptrs[nPtrs++] = ptr; 00227 } 00228 00229 inline void*& SbPList::operator[](const int index) const 00230 { 00231 assert(index>=0); 00232 if (index>= nPtrs) 00233 grow(index); 00234 return ptrs[index]; 00235 } 00236 00237 00238 // Keep include for compatibility 00239 #include <Inventor/lists/SbIntList.h> 00240 #include <Inventor/lists/SbVec3fList.h> 00241 #include <Inventor/lists/SbStringList.h> 00242 00243 #endif 00244