Version: 9.16.0
MED_Vector.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 CEA, EDF, OPEN CASCADE
2//
3// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5//
6// This library is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 2.1 of the License, or (at your option) any later version.
10//
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public
17// License along with this library; if not, write to the Free Software
18// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19//
20// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21//
22
23#ifndef MED_Vector_HeaderFile
24#define MED_Vector_HeaderFile
25
26#include <vector>
27#include <stdexcept>
28
29# define MED_TVECTOR_CHECK_RANGE
30
31namespace MED
32{
34 template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
35 class TVector : public std::vector<_Tp, _Alloc>
36 {
37 public:
38 typedef size_t size_type;
39
40 typedef std::vector<_Tp, _Alloc> superclass;
41 typedef typename superclass::allocator_type allocator_type;
42
43 typedef _Tp value_type;
46
47 protected:
48 void
50 {
51 if (__n >= this->size())
52 throw std::out_of_range("TVector [] access out of range");
53 }
54
57 {
58 return superclass::operator[](__n);
59 }
60
63 {
64 return superclass::operator[](__n);
65 }
66
67 public:
68 explicit
70 superclass(__a)
71 {}
72
73 TVector(size_type __n, const value_type& __val,
74 const allocator_type& __a = allocator_type()):
75 superclass(__n, __val, __a)
76 {}
77
78 explicit
80 superclass(__n)
81 {}
82
83 TVector(const TVector& __x):
84 superclass(__x)
85 {}
86
87 template<typename _InputIterator>
88 TVector(_InputIterator __first, _InputIterator __last,
89 const allocator_type& __a = allocator_type()):
90 superclass(__first, __last, __a)
91 {}
92
93 template<typename _Yp, typename _Al>
95 superclass(__y.begin(), __y.end())
96 {}
97
98 TVector&
99 operator=(const TVector& __x)
100 {
101 superclass::operator=(__x);
102 return *this;
103 }
104
105 template<typename _Yp, typename _Al>
106 TVector&
108 {
109 this->assign(__y.begin(), __y.end());
110 return *this;
111 }
112
115 {
116#if defined(MED_TVECTOR_CHECK_RANGE)
117 check_range(__n);
118#endif
119 return get_value(__n);
120 }
121
124 {
125#if defined(MED_TVECTOR_CHECK_RANGE)
126 check_range(__n);
127#endif
128 return get_value(__n);
129 }
130
133 {
134 check_range(__n);
135 return get_value(__n);
136 }
137
139 at(size_type __n) const
140 {
141 check_range(__n);
142 return get_value(__n);
143 }
144 };
145}
146
147#undef MED_TVECTOR_CHECK_RANGE
148
149#endif // MED_Vector_HeaderFile
IMAP::const_iterator begin(const IMAP &m)
Definition: StdMeshers_Projection_2D.cxx:104
IMAP::const_iterator end(const IMAP &m)
Definition: StdMeshers_Projection_2D.cxx:106
Main purpose to introduce the class was to customize operator [].
Definition: MED_Vector.hxx:36
_Tp value_type
Definition: MED_Vector.hxx:43
void check_range(size_type __n) const
Definition: MED_Vector.hxx:49
const_reference operator[](size_type __n) const
Definition: MED_Vector.hxx:123
const value_type & const_reference
Definition: MED_Vector.hxx:45
TVector(size_type __n)
Definition: MED_Vector.hxx:79
const_reference at(size_type __n) const
Definition: MED_Vector.hxx:139
superclass::allocator_type allocator_type
Definition: MED_Vector.hxx:41
TVector(size_type __n, const value_type &__val, const allocator_type &__a=allocator_type())
Definition: MED_Vector.hxx:73
std::vector< _Tp, _Alloc > superclass
Definition: MED_Vector.hxx:40
const_reference get_value(size_type __n) const
Definition: MED_Vector.hxx:56
TVector(_InputIterator __first, _InputIterator __last, const allocator_type &__a=allocator_type())
Definition: MED_Vector.hxx:88
value_type & reference
Definition: MED_Vector.hxx:44
TVector(const TVector &__x)
Definition: MED_Vector.hxx:83
TVector & operator=(const TVector &__x)
Definition: MED_Vector.hxx:99
TVector(TVector< _Yp, _Al > __y)
Definition: MED_Vector.hxx:94
TVector & operator=(TVector< _Yp, _Al > __y)
Definition: MED_Vector.hxx:107
reference operator[](size_type __n)
Definition: MED_Vector.hxx:114
TVector(const allocator_type &__a=allocator_type())
Definition: MED_Vector.hxx:69
reference get_value(size_type __n)
Definition: MED_Vector.hxx:62
size_t size_type
Definition: MED_Vector.hxx:38
reference at(size_type __n)
Definition: MED_Vector.hxx:132
Definition: MED_Algorithm.cxx:28