Stellarium 0.14.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 
37 namespace br_stl
38 {
39 
40 template<class T>
41 class gVectorTempl : public std::vector<T>
42 {
43 
44 public:
45 
46  #ifndef _MSC_BUILD
47  //inherited types
48  typedef typename gVectorTempl::size_type size_type;
49  typedef typename gVectorTempl::iterator iterator;
50  typedef typename gVectorTempl::difference_type difference_type;
51  typedef typename gVectorTempl::reference reference;
52  typedef typename gVectorTempl::const_reference const_reference;
53  #endif
54 
55 
56  gVectorTempl()
57  {
58  }
59 
60  gVectorTempl(const gVectorTempl &right)
61  :std::vector<T>((std::vector<T>) right)
62  {
63 
64  }
65  gVectorTempl(size_type n, const T& value=T())
66  :std::vector<T>(n, value)
67  {
68  }
69 
70  gVectorTempl(iterator i, iterator j)
71  :std::vector<T>(i, j)
72  {
73  }
74 
75  reference operator [](difference_type index)
76  {
77  assert(index >=0 && index < static_cast<difference_type>(gVectorTempl::size()));
78 
79 
80  return std::vector<T>::operator[](index);
81  }
82 
83  const_reference operator [](difference_type index) const
84  {
85  assert(index >=0 && index < static_cast<difference_type>(gVectorTempl::size()));
86 
87  return std::vector<T>::operator[](index);
88  }
89 
90 
91 };
92 
93 
94 template<class T>
95 inline std::ostream& operator<<(std::ostream& s, const gVectorTempl<T>& m)
96 {
97  typedef typename gVectorTempl<T>::size_type size_type;
98 
99  for(size_type i = 0; i < m.size(); ++i)
100  {
101  s << std::endl << i <<" : ";
102  s << m[i] <<" ";
103  }
104  s << std::endl;
105  return s;
106 }
107 
108 }
109 #endif // _GVECTORTEMPL_H_
110