]> https://gitweb.dealii.org/ - dealii.git/blob
98411e676cd2a5545e9a1f3f2840c248dc6d431f
[dealii.git] /
1 // ptr_vector.hpp
2 // Copyright (c) 2007-2009 Ben Hanson (http://www.benhanson.net/)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file licence_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 #ifndef BOOST_LEXER_PTR_VECTOR_HPP
7 #define BOOST_LEXER_PTR_VECTOR_HPP
8
9 #include "../size_t.hpp"
10 #include <vector>
11
12 namespace boost
13 {
14 namespace lexer
15 {
16 namespace detail
17 {
18 template<typename Type>
19 class ptr_vector
20 {
21 public:
22     typedef std::vector<Type *> vector;
23
24     ptr_vector ()
25     {
26     }
27
28     ~ptr_vector ()
29     {
30         clear ();
31     }
32
33     vector *operator -> ()
34     {
35         return &_vector;
36     }
37
38     const vector *operator -> () const
39     {
40         return &_vector;
41     }
42
43     vector &operator * ()
44     {
45         return _vector;
46     }
47
48     const vector &operator * () const
49     {
50         return _vector;
51     }
52
53     Type * &operator [] (const std::size_t index_)
54     {
55         return _vector[index_];
56     }
57
58     Type * const &operator [] (const std::size_t index_) const
59     {
60         return _vector[index_];
61     }
62
63     bool operator == (const ptr_vector &rhs_) const
64     {
65         bool equal_ = _vector.size () == rhs_._vector.size ();
66
67         if (equal_)
68         {
69             typename vector::const_iterator lhs_iter_ = _vector.begin ();
70             typename vector::const_iterator end_ = _vector.end ();
71             typename vector::const_iterator rhs_iter_ = rhs_._vector.begin ();
72
73             for (; equal_ && lhs_iter_ != end_; ++lhs_iter_, ++rhs_iter_)
74             {
75                 equal_ = **lhs_iter_ == **rhs_iter_;
76             }
77         }
78
79         return  equal_;
80     }
81
82     void clear ()
83     {
84         if (!_vector.empty ())
85         {
86             Type **iter_ = &_vector.front ();
87             Type **end_ = iter_ + _vector.size ();
88
89             for (; iter_ != end_; ++iter_)
90             {
91                 delete *iter_;
92             }
93         }
94
95         _vector.clear ();
96     }
97
98 private:
99     vector _vector;
100
101     ptr_vector (const ptr_vector &); // No copy construction.
102     ptr_vector &operator = (const ptr_vector &); // No assignment.
103 };
104 }
105 }
106 }
107
108 #endif

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.