deferrer.hh

Go to the documentation of this file.
00001 // deferrer.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 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_DEFERRER_HH
00018 # define VCSN_MISC_DEFERRER_HH
00019  
00031 namespace utility
00032 {
00033 
00036 # ifndef VCSN_NDEBUG
00037   enum { deferrer_runtime_checks_default = true };
00038 #  else // VCSN_NDEBUG
00039   enum { deferrer_runtime_checks_default = false };
00040 # endif // ! VCSN_NDEBUG
00041 
00043 
00044   template <class T, bool B>
00045   struct DeferrerDebugPart
00046   {
00047   protected:
00048     // Defaults to true.
00049     DeferrerDebugPart(void* ptr, bool is_valid = false);
00050 
00051     void        set_valid(bool b);
00052     T&          cast(void*);
00053     const T&    cast(const void*) const;
00054 
00055     bool is_valid_;
00056   };
00057 
00058   template <class T>
00059   struct DeferrerDebugPart<T, false>
00060   {
00061   protected:
00062     // False version.
00063     DeferrerDebugPart(void* ptr, bool is_valid = false);
00064     void        set_valid(bool b);
00065      T&         cast(void*);
00066      const T&   cast(const void*) const;
00067   };
00093   template <class T, bool rt_checks = deferrer_runtime_checks_default>
00094   struct Deferrer : DeferrerDebugPart<T, rt_checks>
00095   {
00096     typedef T deferred_type;
00097 
00106     Deferrer();
00107 
00115     Deferrer&
00116     operator = (const deferred_type&);
00117 
00119     operator T () const;
00120   protected:
00121     typedef unsigned char data_t[sizeof (deferred_type)];
00122 
00130     data_t data;
00131   };
00132 
00134 } // End of namespace utility.
00135 
00136 # ifndef VCSN_USE_INTERFACE_ONLY
00137 #  include <vaucanson/misc/deferrer.hxx>
00138 # endif // VCSN_USE_INTERFACE_ONLY
00139 
00140 #endif // ! VCSN_MISC_DEFERRER_HH

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