~ubuntu-branches/ubuntu/oneiric/libclaw/oneiric

« back to all changes in this revision

Viewing changes to claw/max_vector.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge
  • Date: 2010-12-23 20:55:14 UTC
  • mfrom: (4.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101223205514-s10m6ywla7s4ttqf
Tags: 1.6.1-3
Upload in sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
  CLAW is a free library without any particular aim but being useful to 
5
5
  anyone.
6
6
 
7
 
  Copyright (C) 2005-2008 Julien Jorge
 
7
  Copyright (C) 2005-2010 Julien Jorge
8
8
 
9
9
  This library is free software; you can redistribute it and/or
10
10
  modify it under the terms of the GNU Lesser General Public
24
24
*/
25
25
/**
26
26
 * \file max_vector.hpp
27
 
 * \brief Stockage d'une liste d'�l�ments ayant la m�me valeur avec majoration.
 
27
 * \brief Fill a container with some values, keeping only all the "maximum"
 
28
 *        inserted values.
28
29
 * \author Julien Jorge
29
30
 */
30
31
#ifndef __CLAW_MAX_VECTOR_HPP__
31
32
#define __CLAW_MAX_VECTOR_HPP__
32
33
 
33
34
#include <vector>
 
35
#include <functional>
34
36
 
35
37
namespace claw
36
38
{
37
39
  /**
38
 
   * \brief Stockage d'une liste d'�l�ments ayant la m�me valeur avec
39
 
   *        majoration.
40
 
   * L'ajout d'un �l�ment de valeur sup�rieur � la valeur max actuelle supprime
41
 
   * tous les �l�ments pr�sents de la liste.
42
 
   * \param E : type des �l�ments � stocker.
 
40
   * \brief Fill a container with some values, keeping only all the "maximum"
 
41
   *        inserted values.
 
42
   *
 
43
   * Adding a value greater than the previous ones remove all the old values.
 
44
   *
 
45
   * \b Template \b parameters:
 
46
   * - \param E: the type of the stored values.
 
47
   * - \param Comp: how to compare the old values with the new ones.
 
48
   * - \param Container: the type of the container in which the values are
 
49
   *   stored.
 
50
   *
43
51
   * \author Julien Jorge
44
52
   */
45
 
  template < class E > class max_vector
 
53
  template< typename E, typename Comp = std::less<E>,
 
54
            typename Container = std::vector<E> >
 
55
  class max_vector
46
56
  {
47
57
  public:
48
 
   
49
 
    explicit max_vector(const E& e);
50
 
    void add(const E& e);
51
 
    const std::vector<E>& get_v() const;
 
58
    /** \brief The type of the values stored in the container. */
 
59
    typedef E value_type;
 
60
 
 
61
    /** \brief The comparator used to compare the values inserted. */
 
62
    typedef Comp comparator_type;
 
63
 
 
64
    /** \brief The type of the container in which the values are stored. */
 
65
    typedef Container container_type;
 
66
 
 
67
  public:
 
68
    max_vector();
 
69
    explicit max_vector(const value_type& e);
 
70
 
 
71
    void add(const value_type& e);
 
72
    const container_type& get_v() const;
52
73
 
53
74
  private:
54
 
    /** \brief Maximum des �l�ment du vecteur. */
55
 
    E m_max;
 
75
    /** \brief The maximum values. */
 
76
    container_type m_values;
56
77
 
57
 
    /** \brief Les maximums rencontr�s. */
58
 
    std::vector<E> m_vector;
59
78
  }; // max_vector
60
79
 
61
80
} // namespace claw