Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/SbPList.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.3 $
00045  |
00046  |   Description:
00047  |      This contains the definition of the SbPList generic pointer
00048  |      list class. An SbPList is a list of (void *) pointers that
00049  |      allows easy insertion, removal, and other operations.
00050  |
00051  |      The SbIntList class allows lists of integers to be created.
00052  |
00053  |   Author(s)          : Paul S. Strauss, Nick Thompson, Gavin Bell
00054  |
00055  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00056  _______________________________________________________________________
00057  */
00058 
00059 #ifndef _SB_PLIST_
00060 #define _SB_PLIST_
00061 
00062 #include <Inventor/system/SbSystem.h>
00063 #include <Inventor/SbBasic.h>
00064 #include <Inventor/SbLinear.h>
00065 
00066 
00069 
00076 
00077 
00078 class INVENTOR_API SbPList {
00079   public:
00080 
00082     SbPList();
00083 
00087     SbPList(int initSize);
00088 
00090     SbPList(const SbPList &pl);
00091 
00093     ~SbPList();
00094 
00096     void        append(void * ptr)
00097         { if (nPtrs + 1 > ptrsSize) expand(nPtrs + 1);
00098           ptrs[nPtrs++] = ptr; }
00099 
00101     int         find(const void *ptr) const;
00102 
00104     void        insert(void *ptr, int addBefore);
00105 
00107     void        remove(int which);
00108 
00110     int         getLength() const               { return (int) nPtrs;   }
00111 
00113     void        truncate(int start)
00114         { nPtrs = start; }
00115 
00117     void        copy(const SbPList &pl);
00118 
00120     SbPList &   operator =(const SbPList &pl)   { copy(pl); return *this; }
00121 
00123     void *&     operator [](int i) const
00124         { if (i >= nPtrs) grow(i); return ptrs[i]; }
00125 
00127     int         operator ==(const SbPList &pl) const
00128         { return pl.nPtrs == nPtrs ? compare(pl) : FALSE; }
00130     int         operator !=(const SbPList &pl) const
00131         { return pl.nPtrs == nPtrs ? ! compare(pl) : TRUE; }
00132   
00134   SoINTERNAL public:
00135     void *      get(int i) const { return ptrs[i]; }
00136     void        set(int i, void *j) { ptrs[i] = j; }
00137 
00138   private:
00139 
00142     int         compare(const SbPList &pl) const;
00143 
00144     void **     ptrs;           
00145     int         nPtrs;          
00146     int         ptrsSize;       
00147 
00151     void        grow(int max) const;
00152 
00155     void        setSize(int size)
00156         { if (size > ptrsSize) expand(size); nPtrs = size; }
00157 
00160     void        expand(int size);
00161 };
00162 
00171 
00172 
00173 SoINTERNAL class INVENTOR_API SbIntList : public SbPList {
00174 
00175   public:
00177     SbIntList()                                 {}
00178     SbIntList(int initSize) : SbPList(initSize) {}
00179 
00181     void        append(int integer)
00182         { ((SbPList *) this)->append((void *) (size_t) integer); }
00183 
00185     int         find(int integer)
00186         { return ((SbPList *) this)->find((void *) (size_t) integer); }
00187 
00189     void        insert(int integer, int addBefore)
00190         { ((SbPList *) this)->insert((void *) (size_t) integer, addBefore); }
00191 
00192     int &       operator [](int i) const
00193 #if defined(_MIPS_SZPTR) && (_MIPS_SZPTR==64) && (_MIPS_SZINT==32)
00194 
00195 
00196 
00197         { return ((int &)*(((char*)&((*(const SbPList *) this) [i]) ) + 4 ));}
00198 
00199 #elif 1 || ((_MIPS_SZPTR==32) && (_MIPS_SZINT==32))
00200         { return ( (int &) ( (*(const SbPList *) this) [i] ) ); }
00201 #else
00202 #       error "Error in SbPList:  Don't know how to cast void* to int!"
00203 #endif
00204 };
00205 
00213 
00214 SoINTERNAL class INVENTOR_API SbVec3fList : public SbPList {
00215 
00216   public:
00217      SbVec3fList() {}
00218     ~SbVec3fList();
00219 
00221     void        append(SbVec3f *vec)
00222         { ((SbPList *) this)->append((void *) new SbVec3f(vec->getValue())); }
00223 
00225     void        insert(SbVec3f *vec, int addBefore)
00226         { ((SbPList *) this)->insert((void *) new SbVec3f(vec->getValue()),
00227                 addBefore); }
00228 
00229     SbVec3f *   operator [](int i) const
00230         { return ( (SbVec3f *) ( (*(const SbPList *) this) [i] ) ); }
00231 };
00232 
00241 
00242 class SbString;
00243 
00244 SoEXTENDER class INVENTOR_API SbStringList : public SbPList {
00245   public:
00247     void        append(SbString *string)
00248         { ((SbPList *) this)->append((void *) string); }
00249 
00251     int          find(SbString *string)
00252         { return ((SbPList *) this)->find((void *) string); }
00253 
00255     void        insert(SbString *string, int addBefore)
00256         { ((SbPList *) this)->insert((void *) string, addBefore); }
00257 
00258     SbString *& operator [](int i) const
00259         { return ( (SbString *&) ( (*(const SbPList *) this) [i] ) ); }
00260 };
00261 
00262 #endif /* _SB_PLIST_ */