1 /* Swapping_Vector class declaration.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Swapping_Vector_defs_hh
25 #define PPL_Swapping_Vector_defs_hh 1
26 
27 #include "Swapping_Vector_types.hh"
28 #include "globals_defs.hh"
29 #include <vector>
30 
31 namespace Parma_Polyhedra_Library {
32 
33 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
34 //! A wrapper for std::vector that calls a swap() method instead of copying
35 //! elements, when possible.
36 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
37 template <typename T>
38 class Swapping_Vector {
39 
40 public:
41   typedef typename std::vector<T>::const_iterator const_iterator;
42   typedef typename std::vector<T>::iterator iterator;
43   typedef typename std::vector<T>::size_type size_type;
44 
45   Swapping_Vector();
46   explicit Swapping_Vector(dimension_type new_size);
47   Swapping_Vector(dimension_type new_size, const T& x);
48 
49   void clear();
50   void reserve(dimension_type new_capacity);
51   void resize(dimension_type new_size);
52   void resize(dimension_type new_size, const T& x);
53 
54   dimension_type size() const;
55   dimension_type capacity() const;
56   bool empty() const;
57 
58   void m_swap(Swapping_Vector& v);
59 
60   T& operator[](dimension_type i);
61   const T& operator[](dimension_type i) const;
62 
63   T& back();
64   const T& back() const;
65 
66   void push_back(const T& x);
67   void pop_back();
68 
69   iterator begin();
70   iterator end();
71   const_iterator begin() const;
72   const_iterator end() const;
73 
74   iterator erase(iterator itr);
75   iterator erase(iterator first, iterator last);
76 
77   // This is defined only if T has an external_memory_in_bytes() method.
78   memory_size_type external_memory_in_bytes() const;
79 
80   dimension_type max_num_rows();
81 
82 private:
83   std::vector<T> impl;
84 };
85 
86 #ifdef PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS
87 /*! \relates Swapping_Vector */
88 #endif // defined(PPL_DOXYGEN_INCLUDE_IMPLEMENTATION_DETAILS)
89 template <typename T>
90 void swap(Swapping_Vector<T>& x, Swapping_Vector<T>& y);
91 
92 } // namespace Parma_Polyhedra_Library
93 
94 #include "Swapping_Vector_inlines.hh"
95 
96 #endif // !defined(PPL_Swapping_Vector_defs_hh)
97