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

« back to all changes in this revision

Viewing changes to claw/multi_type_map.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
30
30
#ifndef __CLAW_MULTI_TYPE_MAP_HPP__
31
31
#define __CLAW_MULTI_TYPE_MAP_HPP__
32
32
 
33
 
#include <claw/meta.hpp>
 
33
#include <claw/meta/no_type.hpp>
 
34
#include <claw/meta/type_list.hpp>
34
35
#include <map>
35
36
 
36
37
namespace claw
37
38
{
38
 
  template<typename ReturnType, typename Map>
 
39
  /**
 
40
   * \brief This class provides types and methods to allow the call of methods
 
41
   *        recursively along the inherintance hierarchy.
 
42
   * \remark This class is to be used internally.
 
43
   *
 
44
   * Suppose we have defined the following variable
 
45
   *
 
46
   * <tt>multi_type_map<int, type_list<std::string, type_list<int, no_type> > >
 
47
   * my_map;</tt>
 
48
   *
 
49
   * The call <tt>int i = my_map.get<int>( 24 );</tt> doesn't match the type
 
50
   * of the end class. So the call is repercuted on the parent class until the
 
51
   * types match. Then, we can get the values in m_data.
 
52
   *
 
53
   * \b Template \b parameters
 
54
   * - \a ValueType is the type of the values on which the action is done.
 
55
   * - \a Map is the type of the map in which the action is done.
 
56
   *
 
57
   * \author Julien Jorge
 
58
   */
 
59
  template<typename ValueType, typename Map>
39
60
  class multi_type_map_wrapper;
40
61
 
41
62
  /**
58
79
   * \author Julien Jorge
59
80
   */
60
81
  template<typename Key, typename TypeList>
61
 
  class multi_type_map
62
 
    : public multi_type_map<Key, typename TypeList::queue_type>
 
82
  class multi_type_map;
 
83
 
 
84
  /**
 
85
   * \brief Partial specialization, to stop the inheritance recursivity.
 
86
   */
 
87
  template<typename Key>
 
88
  class multi_type_map<Key, meta::no_type>
 
89
  {
 
90
 
 
91
  }; // class multi_type_map
 
92
 
 
93
  /*
 
94
   * Here is the interface of multi_type_map
 
95
   */
 
96
  template<typename Key, typename Head, typename Tail>
 
97
  class multi_type_map< Key, meta::type_list<Head, Tail> >:
 
98
    public multi_type_map<Key, Tail>
63
99
  {
64
100
  public:
65
101
    typedef Key key_type;
66
 
    typedef typename TypeList::head_type value_type;
67
 
    typedef multi_type_map<Key, TypeList> self_type;
68
 
    typedef multi_type_map<Key, typename TypeList::queue_type> super;
 
102
    typedef Head value_type;
 
103
    typedef meta::type_list<Head, Tail> value_type_list;
 
104
    typedef multi_type_map< Key, meta::type_list<Head, Tail> > self_type;
69
105
    typedef std::map<key_type, value_type> container_type;
70
 
 
71
 
    friend
72
 
    struct multi_type_map_wrapper< value_type,
73
 
                                   multi_type_map<key_type,
74
 
                                                  TypeList> >::last_call;
 
106
    typedef multi_type_map<Key, Tail> super;
 
107
 
 
108
    friend struct multi_type_map_wrapper<value_type, self_type>;
 
109
 
 
110
    /** \brief This structure is used to create an iterator on the values of a
 
111
        given type. */
 
112
    template<typename ValueType>
 
113
    struct iterator
 
114
    {
 
115
      /** \brief The type of the iterator. */
 
116
      typedef typename std::map<key_type, ValueType>::iterator type;
 
117
 
 
118
      /** \brief The type of the const_iterator. */
 
119
      typedef
 
120
      typename std::map<key_type, ValueType>::const_iterator const_type;
 
121
    }; // struct iterator
 
122
 
 
123
  private:
 
124
    typedef typename iterator<value_type>::type iterator_type;
 
125
    typedef typename iterator<value_type>::const_type const_iterator_type;
75
126
 
76
127
  public:
77
128
    template<typename ValueType>
83
134
    template<typename ValueType>
84
135
    bool exists( const key_type& k ) const;
85
136
 
 
137
    template<typename ValueType>
 
138
    typename iterator<ValueType>::type begin();
 
139
 
 
140
    template<typename ValueType>
 
141
    typename iterator<ValueType>::type end();
 
142
 
 
143
    template<typename ValueType>
 
144
    typename iterator<ValueType>::const_type begin() const;
 
145
 
 
146
    template<typename ValueType>
 
147
    typename iterator<ValueType>::const_type end() const;
 
148
 
86
149
  private:
87
150
    /** \brief Data stored for the first type of the list. */
88
151
    container_type m_data;
89
152
 
90
153
  }; // class multi_type_map
91
154
 
92
 
  /**
93
 
   * \brief Partial specialization, to stop the inheritance recursivity.
94
 
   */
95
 
  template<typename Key>
96
 
  class multi_type_map<Key, meta::no_type>
97
 
  {
98
 
    // empty class
99
 
  }; // class multi_type_map
100
 
 
101
155
} // namespace claw
102
156
 
103
157
#include <claw/impl/multi_type_map.tpp>