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, 2006 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 vcsn
00031 {
00032   namespace misc
00033   {
00035     namespace unique
00036     {
00038       template <class T>
00039       struct UniqueListBase
00040       {
00041           virtual ~UniqueListBase ();
00042       };
00043 
00044       typedef UniqueListBase<int> uniquelist_base;
00045 
00053       template <typename T>
00054       struct uniquelist : public std::list<T>, public uniquelist_base
00055       {
00056           ~uniquelist ();
00057       };
00058 
00071       template <class T>
00072       struct UniqueMap
00073       {
00076           template <class U>
00077           struct TiSlot
00078           {
00079               TiSlot (const std::type_info& );
00080               const std::type_info &id;
00081               bool operator== (const TiSlot& other) const;
00082               bool operator< (const TiSlot& other) const;
00083           };
00084 
00085           typedef TiSlot<int> ti_slot;
00086 
00088           typedef std::map<ti_slot, uniquelist_base*> map_t;
00089 
00091           static map_t& instance ();
00092         protected:
00093           map_t map_;
00097           UniqueMap ();
00104           ~UniqueMap ();
00105       };
00106 
00107       typedef UniqueMap<int> unique_map;
00108 
00109       struct unifiable
00110       {
00111           inline unifiable ();
00112           inline unifiable (const unifiable&);
00113         private:
00114           template <typename T>
00115           friend const T& get (const T&);
00116           bool unique_;
00117       };
00118 
00127       template <typename T>
00128       const T& get (const T&);
00129 
00131       template <typename T>
00132       const T* get (const T*);
00133 
00135     }
00136 
00137   } // misc
00138 } // vcsn
00139 
00140 # ifndef INTERFACE_ONLY
00141 #  include <vaucanson/misc/unique.hxx>
00142 # endif // INTERFACE_ONLY
00143 
00144 #endif // ! VCSN_MISC_UNIQUE_HH

Generated on Sat Jul 29 17:13:13 2006 for Vaucanson by  doxygen 1.4.6