#ifndef __vtkBaseArray_h #define __vtkBaseArray_h #include #include #ifdef _WIN32 #endif #include "Macros.h" #include "vtkObject.h" //! vtkBaseArray template class vtkBaseArray : public vtkObject { //***** c o n s t r u c t o r s / d e s t r u c t o r public: const char *GetClassName() {return "vtkBaseArray";}; //! Constructors allowing the specification of array sizes, additional memory reservation, and initialization with other arrays vtkBaseArray() {m_pData = NULL; m_uSize = 0;}; //! Fake copy constructor vtkBaseArray( const vtkBaseArray& ) { assert( false ); } //***** p u b l i c m e t h o d s //! Inquire whether array contains at least one element const bool Defined() const { return m_uSize > 0; } //! Return pointer to array data type*& GetData() { return m_pData; } //! Initialize array void Initialize( const type Value = 0 ) { for( UINT uEl = 0; uEl < m_uSize; uEl++ ) m_pData[uEl] = Value; } //! Inquire whether array has size zero const bool IsEmpty() const { return !m_uSize; } //! Sum of two arrays void IsSumOf( const vtkBaseArray&, const vtkBaseArray& ); //! Allow direct access to last array element type& Last() {assert( m_uSize ); return m_pData[m_uSize - 1];}; //! Access of array elements type& operator[]( const UINT u ) { assert( u < m_uSize ); return m_pData[u]; } type operator[]( const UINT u ) const { assert( u < m_uSize ); return m_pData[u]; } //! Inquire array size const UINT Size() const { return m_uSize; } //***** v i r t u a l m e t h o d s //! Assure a certain array size, i.e. for vtkBESSArray, set array size, and for vtkSubArray, assert the correct array size virtual void AssureSize( const UINT uSize ) = 0; //***** p r o t e c t e d m e t h o d s protected: ~vtkBaseArray() {}; //! Assignment of other arrays void BaseCopyOf( const vtkBaseArray& a ) { AssureSize( a.m_uSize ); for( UINT uEl = 0; uEl < m_uSize; uEl++ ) m_pData[uEl] = a[uEl]; }; //! Array size UINT m_uSize; //! Data pointer type *m_pData; private: }; // template class CBaseArray template //! Is Sum Of void vtkBaseArray::IsSumOf( const vtkBaseArray& c_aA, const vtkBaseArray& c_aB ) { //! Assert coinciding size of input arrays assert( c_aA.Size() == c_aB.Size() ); //! Assure corresponding size of resulting array AssureSize( c_aA.Size() ); //! Compute sum of arrays for( unsigned int uEl = 0; uEl < m_uSize; uEl++ ) m_pData[uEl] = c_aA[uEl] + c_aB[uEl]; } #endif