Main Page   Class Hierarchy   Compound List   File List   Compound Members  

barray.h

00001 /*=============================================================================
00002         File: barray.h
00003      Purpose:      
00004     Revision: $Id: barray.h,v 1.4 2003/01/27 11:37:35 philosophil Exp $
00005   Created by: Philippe Lavoie          (3 Oct, 1996)
00006  Modified by: 
00007 
00008  Copyright notice:
00009           Copyright (C) 1996-1998 Philippe Lavoie
00010  
00011           This library is free software; you can redistribute it and/or
00012           modify it under the terms of the GNU Library General Public
00013           License as published by the Free Software Foundation; either
00014           version 2 of the License, or (at your option) any later version.
00015  
00016           This library is distributed in the hope that it will be useful,
00017           but WITHOUT ANY WARRANTY; without even the implied warranty of
00018           MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019           Library General Public License for more details.
00020  
00021           You should have received a copy of the GNU Library General Public
00022           License along with this library; if not, write to the Free
00023           Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00024 =============================================================================*/
00025 
00026 #ifndef _MATRIX_barray_h_
00027 #define _MATRIX_barray_h_
00028 
00029 #include "matrix_global.h"
00030 #include "specialType.h"
00031 #include "list.h"
00032 
00033 // Predefining every friend functions
00034 // This is required by the latest ISO C++ draft
00035 
00038 namespace PLib {
00039   template <class T> class BasicArray ;
00040 
00041   template <class T> int operator!=(const BasicArray<T>&,const BasicArray<T>&);
00042   template <class T> int operator==(const BasicArray<T>&,const BasicArray<T>&);
00043   template <class T> istream& operator>>(istream& is, BasicArray<T>& arry);
00044   template <class T> ostream& operator<<(ostream& os, const BasicArray<T>& arry);
00045 
00046 #include "galloc.h"
00047 
00048 
00058 template<class T> class BasicArray
00059 {
00060 public:
00061   int n() const 
00062     { return sze; } 
00063   BasicArray();
00064   BasicArray(const int ni);
00065   BasicArray(const BasicArray<T>& f2);
00066   BasicArray(T* ap, const int size) ;  
00067   BasicArray(BasicList<T>& list) ;
00068   virtual ~BasicArray();
00069   
00070   BasicArray<T>& operator=(const BasicArray<T>& f2);
00071   
00072   int size() const 
00073     { return sze; } 
00074   void resize(const int nsize) 
00075     { resizeBasicArray(*this,nsize) ; }
00076   void resize(const BasicArray<T>& A) 
00077     { resize(A.n()); } 
00078   
00079   void trim(const int nsize);    
00080   void clear();
00081   void untrim() 
00082     { sze = rsize; } 
00083   
00084   T& push_back(const T i, int end_buffer=10, double end_mult=-1);
00085 
00086   
00087   virtual void reset(const T val = 0.0);
00088   T operator=(const T val) 
00089     { reset(val); return val; } 
00090   
00091 
00092   T& operator[](const int i) 
00093     { return elem(i); } 
00094   T  operator[](const int i) const  
00095     { return elem(i); } 
00096 
00097 #ifdef DEBUG_PLIB
00098   T& elem(const int i) ; 
00099   T  elem(const int i) const ; 
00100 #else
00101   T& elem(const int i) 
00102     { return x[i]; } 
00103   T  elem(const int i) const  
00104     { return x[i]; } 
00105 #endif
00106   T* memory() const 
00107     { return x ; }
00108 
00109   void width(const int w) 
00110     { wdth = w; }   
00111 
00112 #ifdef HAVE_ISO_FRIEND_DECL
00113   friend int operator!= <>(const BasicArray<T>&,const BasicArray<T>&);    
00114   friend int operator== <>(const BasicArray<T>&,const BasicArray<T>&);      
00115   friend istream& operator>> <>(istream& is, BasicArray<T>& arry);
00116   friend ostream& operator<< <>(ostream& os, const BasicArray<T>& arry);
00117 #else
00118   friend int operator!= (const BasicArray<T>&,const BasicArray<T>&);    
00119   friend int operator== (const BasicArray<T>&,const BasicArray<T>&);      
00120   friend istream& operator>> (istream& is, BasicArray<T>& arry);
00121   friend ostream& operator<< (ostream& os, const BasicArray<T>& arry);
00122 #endif
00123 
00124   ostream& print(ostream& os) const ; 
00125 
00126   FRIEND_ARRAY_ALLOCATOR 
00127 
00128   // compatibility for std:vector
00129   typedef T* iterator ;
00130   typedef const T* const_iterator ;
00131 
00132   iterator begin() { return (0<sze) ? x : 0 ; }
00133   const_iterator begin() const { return (0<sze) ? x : 0 ; }
00134 
00135   iterator end() { return (0<sze) ? x+sze : 0; }
00136   const_iterator end() const { return (0<sze) ? x+sze : 0; }
00137 
00138 protected:
00139   int rsize; 
00140   int wdth;  
00141   int destruct ; 
00142   int sze; 
00143   T *x;   
00144 };
00145 
00146 } // end namespace 
00147 
00148 typedef PLib::BasicArray<int> BasicArray_INT ;            
00149 typedef PLib::BasicArray<char> BasicArray_BYTE ;          
00150 typedef PLib::BasicArray<double> BasicArray_DOUBLE ;      
00151 typedef PLib::BasicArray<float> BasicArray_FLOAT ;      
00152 typedef PLib::BasicArray<Complex> BasicArray_COMPLEX ;    
00153 typedef PLib::BasicArray<unsigned char> BasicArray_UBYTE ;
00154 typedef PLib::BasicArray<PLib::HPoint3Df> BasicArray_HPoint3D ;
00155 typedef PLib::BasicArray<PLib::Point3Df> BasicArray_Point3D ;
00156 typedef PLib::BasicArray<PLib::HPoint3Dd> BasicArray_HPoint3Dd ;
00157 typedef PLib::BasicArray<PLib::Point3Dd> BasicArray_Point3Dd ;
00158 typedef PLib::BasicArray<PLib::HPoint2Df> BasicArray_HPoint2D ;
00159 typedef PLib::BasicArray<PLib::Point2Df> BasicArray_Point2D ;
00160 typedef PLib::BasicArray<PLib::HPoint2Dd> BasicArray_HPoint2Dd ;
00161 typedef PLib::BasicArray<PLib::Point2Dd> BasicArray_Point2Dd ;
00162 typedef PLib::BasicArray<void*> BasicArray_VoidPtr ;
00163 typedef PLib::BasicArray<PLib::Coordinate> BasicArray_Coordinate ;
00164 
00165 #ifdef INCLUDE_TEMPLATE_SOURCE
00166 #include "barray.cpp"
00167 #include "barray_hpoint.cpp"
00168 #endif
00169 
00170 
00171 
00172 #endif 

Generated on Tue Jun 24 13:26:54 2003 for NURBS++ by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002