unique.hh

Go to the documentation of this file.
00001 // unique.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_MISC_UNIQUE_HH
00018 # define VCSN_MISC_UNIQUE_HH
00019 
00025 #include <list>
00026 #include <algorithm>
00027 #include <typeinfo>
00028 #include <map>
00029 
00030 namespace utility
00031 {
00033   namespace unique
00034   {
00036     template <class T>
00037     struct UniqueListBase
00038     {
00039       virtual ~UniqueListBase();
00040     };
00041 
00042     typedef UniqueListBase<int> uniquelist_base;
00043 
00051     template<typename T>
00052     struct uniquelist : public std::list<T>, public uniquelist_base
00053     {
00054       ~uniquelist();
00055     };
00056 
00069     template <class T>
00070     struct UniqueMap
00071     {
00074       template <class U>
00075       struct TiSlot
00076       {
00077         TiSlot(const std::type_info& );
00078         const std::type_info &id;
00079         bool operator==(const TiSlot& other) const;
00080         bool operator<(const TiSlot& other) const;
00081       };
00082 
00083       typedef TiSlot<int> ti_slot;
00084 
00086       typedef std::map<ti_slot, uniquelist_base*> map_t;
00087 
00089       static map_t& instance();
00090     protected:
00091       map_t map_;
00095       UniqueMap();
00102       ~UniqueMap();
00103     };
00104 
00105     typedef UniqueMap<int> unique_map;
00106 
00107     struct unifiable
00108     {
00109       inline unifiable();
00110       inline unifiable(const unifiable&);
00111     private:
00112       template<typename T>
00113       friend const T& get(const T&);
00114       bool unique_;
00115     };
00116 
00125     template<typename T>
00126     const T& get(const T&);
00127 
00129     template<typename T>
00130     const T* get(const T*);
00131 
00133   }
00134 
00135 }
00136 
00137 # ifndef INTERFACE_ONLY
00138 #  include <vaucanson/misc/unique.hxx>
00139 # endif // INTERFACE_ONLY
00140 
00141 #endif // ! VCSN_MISC_UNIQUE_HH

Generated on Fri Jul 28 12:18:55 2006 for Vaucanson by  doxygen 1.4.6