array.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2004-2005 by Reality Rift Studios                       *
00003  *   http://www.realityrift.com  -  mattias@realityrift.com                *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program 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         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #ifndef neo_core_array_h
00022 #define neo_core_array_h
00023 
00027 #include "platform.h"
00028 #include "exception.h"
00029 
00030 namespace neo {
00031 namespace core {
00032 
00045 template < class T > class Array
00046 {
00047     public:
00048 
00050     typedef T*                                              iterator;
00051 
00053     typedef const T*                                        const_iterator;
00054 
00055     typedef unsigned int                                    size_type;
00056     typedef ptrdiff_t                                       difference_type;
00057     typedef T&                                              reference;
00058     typedef const T&                                        const_reference;
00059     typedef T*                                              pointer;
00060     typedef const T*                                        const_pointer;
00061     typedef T                                               value_type;
00062     
00064 
00067                                                             Array( size_type num = 0 );
00068 
00070 
00074                                                             Array( size_type num, const_reference val );
00075 
00077 
00081                                                             Array( size_type num, const_pointer p_val );
00082 
00084 
00087                                                             Array( const Array< T >& array );
00088 
00090 
00091                                                            ~Array();
00092 
00094 
00098     inline void                                             push_back( const_reference obj );
00099 
00101 
00104     inline void                                             pop_back();
00105     
00107 
00112     iterator                                                insert( const_iterator at, const_reference obj );
00113 
00115 
00122     iterator                                                insert( const_iterator at, const_iterator first, const_iterator last );
00123 
00125 
00131     void                                                    erase( const_reference obj, bool once = true );
00132 
00134 
00138     iterator                                                erase( iterator pos );
00139 
00141 
00147     iterator                                                erase( iterator first, iterator last );
00148 
00150 
00154     void                                                    resize( size_type num );
00155 
00157 
00162     void                                                    resize( size_type num, const_reference val );
00163 
00165 
00171     void                                                    reserve( size_type num );
00172 
00174 
00177     void                                                    clear( bool dealloc = false );
00178 
00180 
00182     inline size_type                                        size() const;
00183 
00185 
00187     inline size_type                                        capacity() const;
00188 
00190 
00191     inline bool                                             empty() const;
00192     
00194 
00197     iterator                                                find( const T& obj );
00198 
00200 
00203     const_iterator                                          find( const T& obj ) const;
00204 
00206 
00208     inline iterator                                         begin();
00209 
00211 
00213     inline const_iterator                                   begin() const;
00214 
00216 
00219     inline iterator                                         end();
00220 
00222 
00225     inline const_iterator                                   end() const;
00226 
00228 
00229     inline reference                                        front();
00230 
00232 
00233     inline const_reference                                  front() const;
00234 
00236 
00237     inline reference                                        back();
00238 
00240 
00241     inline const_reference                                  back() const;
00242     
00244 
00246     inline void                                             swap( Array< T >& array );
00247 
00249 
00252     inline reference                                        operator [] ( size_t index );
00253 
00255 
00258     inline const_reference                                  operator [] ( size_t index ) const;
00259 
00261 
00264     Array< T >&                                             operator = ( const Array< T >& array );
00265 
00266     private:
00267 
00268     typedef char*                                           raw_pointer;
00269     
00271     size_type                                               _num;
00272 
00274     size_type                                               _used;
00275 
00277     raw_pointer                                             _p_arr;
00278 };
00279 
00280 #include "array.inl"
00281 
00283 
00286 template < typename T > inline void swap( Array< T >& lval, Array< T >& rval ) { lval.swap( rval ); }
00287 
00288 }
00289 }
00290 
00291 #endif

Generated on Sat Feb 17 20:50:47 2007 for NeoEngine 2 - Evolution by  doxygen 1.5.1