Claw  1.7.3
max_vector.tpp
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
25 /**
26  * \file max_vector.tpp
27  * \brief Implementation of the claw::max_vector class.
28  * \author Julien Jorge
29  */
30 
31 /*---------------------------------------------------------------------------*/
32 /**
33  * \brief Constructor.
34  */
35 template<typename E, typename Comp, typename Container>
36 claw::max_vector<E, Comp, Container>::max_vector()
37 {
38 
39 } // max_vector::max_vector()
40 
41 /*---------------------------------------------------------------------------*/
42 /**
43  * \brief Constructor with an initial value.
44  * \param e élément ajouté.
45  */
46 template <typename E, typename Comp, typename Container>
47 claw::max_vector<E, Comp, Container>::max_vector(const value_type& e)
48 {
49  add(e);
50 } // max_vector::max_vector()
51 
52 /*---------------------------------------------------------------------------*/
53 /**
54  * \brief Insert a value in the vector.
55  * \param e The value to insert.
56  */
57 template <typename E, typename Comp, typename Container>
58 void claw::max_vector<E, Comp, Container>::add(const value_type& e)
59 {
60  if (m_values.empty())
61  *std::inserter(m_values, m_values.end()) = e;
62  else
63  {
64  comparator_type comp;
65  if ( comp(m_values.front(), e) )
66  {
67  m_values.clear();
68  *std::inserter(m_values, m_values.end()) = e;
69  }
70  else if ( !comp(e, m_values.front()) )
71  *std::inserter(m_values, m_values.end()) = e;
72  }
73 } // max_vector::add()
74 
75 /*---------------------------------------------------------------------------*/
76 /**
77  * \brief Get the stored values.
78  */
79 template <typename E, typename Comp, typename Container>
80 const typename claw::max_vector<E, Comp, Container>::container_type&
81 claw::max_vector<E, Comp, Container>::get_v() const
82 {
83  return m_values;
84 } // max_vector::get_v()