Stellarium 0.12.3
gVectorTempl.hpp
1 /***************************************************************************
2  * Name: GVector.h
3  *
4  * Description: GVector class envelop the STL vertor class to add
5  * some error control.
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * Copyright (C) 2006 by J.L. Canales *
10  * jlcanales@users.sourceforge.net *
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  * This program is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU General Public License *
23  * along with this program; if not, write to the *
24  * Free Software Foundation, Inc., *
25  * 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA. *
26  ***************************************************************************/
27 
28 #ifndef _GVECTORTEMPL_H_
29 #define _GVECTORTEMPL_H_ 1
30 
31 
32 #include <cassert>
33 #include <vector> //libreria stl de vectores
34 #include <iostream> // for operator<<(), see below
35 
36 namespace br_stl
37 {
38 
39 template<class T>
40 class gVectorTempl : public std::vector<T>
41 {
42 
43 public:
44 
45  //inherited types
46  typedef typename gVectorTempl::size_type size_type;
47  typedef typename gVectorTempl::iterator iterator;
48  typedef typename gVectorTempl::difference_type difference_type;
49  typedef typename gVectorTempl::reference reference;
50  typedef typename gVectorTempl::const_reference const_reference;
51 
52 
53  gVectorTempl()
54  {
55  }
56 
57  gVectorTempl(const gVectorTempl &right)
58  :std::vector<T>((std::vector<T>) right)
59  {
60 
61  }
62  gVectorTempl(size_type n, const T& value=T())
63  :std::vector<T>(n, value)
64  {
65  }
66 
67  gVectorTempl(iterator i, iterator j)
68  :std::vector<T>(i, j)
69  {
70  }
71 
72  reference operator [](difference_type index)
73  {
74  assert(index >=0 && index < static_cast<difference_type>(gVectorTempl::size()));
75 
76 
77  return std::vector<T>::operator[](index);
78  }
79 
80  const_reference operator [](difference_type index) const
81  {
82  assert(index >=0 && index < static_cast<difference_type>(gVectorTempl::size()));
83 
84  return std::vector<T>::operator[](index);
85  }
86 
87 
88 };
89 
90 
91 template<class T>
92 inline std::ostream& operator<<(std::ostream& s, const gVectorTempl<T>& m)
93 {
94  typedef typename gVectorTempl<T>::size_type size_type;
95 
96  for(size_type i = 0; i < m.size(); ++i)
97  {
98  s << std::endl << i <<" : ";
99  s << m[i] <<" ";
100  }
101  s << std::endl;
102  return s;
103 }
104 
105 }
106 #endif // _GVECTORTEMPL_H_
107