Vaucanson  1.4.1
unique.hh
Go to the documentation of this file.
1 // unique.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_MISC_UNIQUE_HH
18 # define VCSN_MISC_UNIQUE_HH
19 
25 # include <list>
26 # include <algorithm>
27 # include <typeinfo>
28 # include <map>
29 
30 namespace vcsn
31 {
32  namespace misc
33  {
35  namespace unique
36  {
38  template <class T>
40  {
41  virtual ~UniqueListBase ();
42  };
43 
45 
53  template <typename T>
54  struct uniquelist : public std::list<T>, public uniquelist_base
55  {
56  ~uniquelist ();
57  };
58 
71  template <class T>
72  struct UniqueMap
73  {
76  template <class U>
77  struct TiSlot
78  {
79  TiSlot (const std::type_info& );
80  const std::type_info &id;
81  bool operator== (const TiSlot& other) const;
82  bool operator< (const TiSlot& other) const;
83  };
84 
85  typedef TiSlot<int> ti_slot;
86 
88  typedef std::map<ti_slot, uniquelist_base*> map_t;
89 
91  static map_t& instance ();
92  protected:
93  map_t map_;
97  UniqueMap ();
104  ~UniqueMap ();
105  };
106 
107  typedef UniqueMap<int> unique_map;
108 
109  struct unifiable
110  {
111  inline unifiable ();
112  inline unifiable (const unifiable&);
113  private:
114  template <typename T>
115  friend const T& get (const T&);
116  bool unique_;
117  };
118 
127  template <typename T>
128  const T& get (const T&);
129 
131  template <typename T>
132  const T* get (const T*);
133 
135  }
136 
137  } // misc
138 } // vcsn
139 
140 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
141 # include <vaucanson/misc/unique.hxx>
142 # endif // INTERFACE_ONLY
143 
144 #endif // ! VCSN_MISC_UNIQUE_HH