00001 /* 00002 fix size vector class similar to STL 00003 Copyright (C) 1999-2002 Frediano Ziglio 00004 ----- 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 ----- 00020 00021 INFORMATION 00022 www: https://freddy77.tripod.com/perdr/ 00023 e-mail: freddy77@angelfire.com 00024 */ 00025 #ifndef FILE_FIXVECT_HPP 00026 #define FILE_FIXVECT_HPP 00027 00028 template <class T,unsigned _size> 00029 class fix_vector 00030 { 00031 public: 00032 typedef T value_type; 00033 typedef T& reference; 00034 typedef const T& const_reference; 00035 typedef T* iterator; 00036 typedef const T* const_iterator; 00037 typedef size_t size_type; 00038 typedef ptrdiff_t difference_type; 00039 #ifndef __GNUC__ 00040 typedef std::reverse_iterator<const_iterator, value_type, 00041 const_reference, difference_type> 00042 const_reverse_iterator; 00043 typedef std::reverse_iterator<iterator, value_type, 00044 reference, difference_type> 00045 reverse_iterator; 00046 #else 00047 typedef std::reverse_iterator<const_iterator> const_reverse_iterator; 00048 typedef std::reverse_iterator<iterator> reverse_iterator; 00049 #endif 00050 00051 // iterator access 00052 iterator begin() { return info; } 00053 const_iterator begin() const { return info; } 00054 iterator end () { return info+_size; } 00055 const_iterator end () const { return info+_size; } 00056 00057 // reverse iterator access 00058 reverse_iterator rbegin () 00059 { 00060 return reverse_iterator(end()); 00061 } 00062 const_reverse_iterator rbegin () const 00063 { 00064 return const_reverse_iterator(end()); 00065 } 00066 reverse_iterator rend () 00067 { 00068 return reverse_iterator(begin()); 00069 } 00070 const_reverse_iterator rend () const 00071 { 00072 return const_reverse_iterator(begin()); 00073 } 00074 00075 // capacity 00076 size_type size() const { return _size; } 00077 size_type capacity () const { return _size; } 00078 bool empty () const { return false; } 00079 00080 // element access 00081 reference operator[] (size_type n) { return info[n]; } 00082 const_reference operator[] (size_type n) const { return info[n]; } 00083 reference front () { return info[0]; } 00084 const_reference front () const { return info[0]; } 00085 reference back () { return *(end() - 1); } 00086 const_reference back () const { return *(end() - 1); } 00087 private: 00088 T info[_size]; 00089 }; 00090 00091 #endif //FILE_FIXVECT_HPP 00092