Back to index

salome-med  6.5.0
MED_Vector.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library 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 GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : 
00024 //  Author : 
00025 //  Module : 
00026 //  $Header: /home/server/cvs/MED/MED_SRC/src/MEDWrapper/Base/MED_Vector.hxx,v 1.6.2.1.6.2.10.1 2012-04-13 08:48:43 vsr Exp $
00027 //
00028 #ifndef MED_Vector_HeaderFile
00029 #define MED_Vector_HeaderFile
00030 
00031 #include <vector>
00032 #include <stdexcept>
00033 
00034 //#if defined(_DEBUG_)
00035 #  define MED_TVECTOR_CHECK_RANGE
00036 //#endif
00037 
00038 namespace MED
00039 {
00040 
00042   template<typename _Tp, typename _Alloc = std::allocator<_Tp> >
00043   class TVector : public std::vector<_Tp, _Alloc>
00044   {
00045   public:
00046     typedef size_t size_type;
00047 
00048     typedef std::vector<_Tp, _Alloc> superclass;
00049     typedef typename superclass::allocator_type allocator_type;
00050 
00051     typedef _Tp value_type;
00052     typedef value_type& reference;
00053     typedef const value_type& const_reference;
00054 
00055   protected:
00056     void
00057     check_range(size_type __n) const
00058     {
00059       if (__n >= this->size())
00060         throw std::out_of_range("TVector [] access out of range");
00061     }
00062 
00063     const_reference
00064     get_value(size_type __n) const
00065     {
00066       return superclass::operator[](__n);
00067     }
00068 
00069     reference
00070     get_value(size_type __n)
00071     {
00072       return superclass::operator[](__n);
00073     }
00074 
00075   public:
00076     explicit
00077     TVector(const allocator_type& __a = allocator_type()): 
00078       superclass(__a) 
00079     {}
00080     
00081     TVector(size_type __n, const value_type& __val,
00082             const allocator_type& __a = allocator_type()):
00083       superclass(__n, __val, __a)
00084     {}
00085     
00086     explicit
00087     TVector(size_type __n):
00088       superclass(__n)
00089     {}
00090 
00091     TVector(const TVector& __x):
00092       superclass(__x)
00093     {}
00094 
00095     template<typename _InputIterator>
00096     TVector(_InputIterator __first, _InputIterator __last,
00097             const allocator_type& __a = allocator_type()):
00098       superclass(__first, __last, __a)
00099     {}
00100 
00101     template<typename _Yp, typename _Al>
00102     TVector(TVector<_Yp, _Al> __y):
00103       superclass(__y.begin(), __y.end())
00104     {}
00105 
00106     TVector&
00107     operator=(const TVector& __x)
00108     {
00109       superclass::operator=(__x);
00110       return *this;
00111     }
00112 
00113     template<typename _Yp, typename _Al>
00114     TVector&
00115     operator=(TVector<_Yp, _Al> __y)
00116     {
00117       this->assign(__y.begin(), __y.end());
00118       return *this;
00119     }
00120 
00121     reference
00122     operator[](size_type __n)
00123     {
00124 #if defined(MED_TVECTOR_CHECK_RANGE)
00125       check_range(__n);
00126 #endif
00127       return get_value(__n);
00128     }
00129 
00130     const_reference
00131     operator[](size_type __n) const
00132     {
00133 #if defined(MED_TVECTOR_CHECK_RANGE)
00134       check_range(__n);
00135 #endif
00136       return get_value(__n);
00137     }
00138 
00139     reference
00140     at(size_type __n)
00141     {
00142       check_range(__n);
00143       return get_value(__n);
00144     }
00145 
00146     const_reference
00147     at(size_type __n) const
00148     {
00149       check_range(__n);
00150       return get_value(__n);
00151     }
00152   };
00153 
00154 }
00155 
00156 #undef MED_TVECTOR_CHECK_RANGE
00157 
00158 #endif