- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# deferrer.hxx

Go to the documentation of this file.

    00001 // deferrer.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 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_DEFERRER_HXX
    00018 # define VCSN_MISC_DEFERRER_HXX
    00019
    00031 # include <vaucanson/misc/deferrer.hh>
    00032 # include <vaucanson/misc/contract.hh>
    00033
    00034 # include <new>
    00035 # include <cstdlib>
    00036
    00037 namespace vcsn
    00038 {
    00039   namespace misc
    00040   {
    00041
    00044   /*-----------------------------------------------.
    00045   | DeferrerDebugPart, with runtime tests enabled  |
    00046   `-----------------------------------------------*/
    00047
    00048     template <class T, bool B>
    00049     DeferrerDebugPart<T, B>::DeferrerDebugPart (void* ptr, bool is_valid) :
    00050       is_valid_ (is_valid)
    00051     {
    00052       memset (ptr, 0, sizeof (T));
    00053     }
    00054
    00055     template <class T, bool B>
    00056     void
    00057     DeferrerDebugPart<T, B>::set_valid (bool b)
    00058     {
    00059       if (is_valid_)
    00060         WARNING ("Modifying a valid Deferrer<T, true>.");
    00061       is_valid_ = b;
    00062     }
    00063
    00064     template <class T, bool B>
    00065     T&
    00066     DeferrerDebugPart<T, B>::cast (void *ptr)
    00067     {
    00068       precondition (is_valid_);
    00069       return *reinterpret_cast<T*> (ptr);
    00070     }
    00071
    00072     template <class T, bool B>
    00073     const T&
    00074     DeferrerDebugPart<T, B>::cast (const void *ptr) const
    00075     {
    00076       precondition (is_valid_);
    00077       return *reinterpret_cast<const T*> (ptr);
    00078     }
    00079
    00080   /*-------------------------------------------------.
    00081   | DeferrerDebugPart, with runtime tests *disabled* |
    00082   `-------------------------------------------------*/
    00083
    00084     template <class T>
    00085     DeferrerDebugPart<T, false>::DeferrerDebugPart (void*, bool)
    00086     {
    00087     }
    00088
    00089     template <class T>
    00090     void
    00091     DeferrerDebugPart<T, false>::set_valid (bool)
    00092     {
    00093     }
    00094
    00095     template <class T>
    00096     T&
    00097     DeferrerDebugPart<T, false>::cast (void *ptr)
    00098     {
    00099       return *reinterpret_cast<T*> (ptr);
    00100     }
    00101
    00102     template <class T>
    00103     const T&
    00104     DeferrerDebugPart<T, false>::cast (const void *ptr) const
    00105     {
    00106       return *reinterpret_cast<const T*> (ptr);
    00107     }
    00108
    00109   /*---------.
    00110   | Deferrer |
    00111   `---------*/
    00112
    00113     template <class T, bool rt_checks>
    00114     Deferrer<T, rt_checks>::Deferrer () : DeferrerDebugPart<T, rt_checks> (data)
    00115     {
    00116     }
    00117
    00118     template <class T, bool rt_checks>
    00119     Deferrer<T, rt_checks>&
    00120     Deferrer<T, rt_checks>::operator= (const deferred_type& rhs)
    00121     {
    00122       new (data) deferred_type (rhs);
    00123       this->set_valid (true);
    00124       return *this;
    00125     }
    00126
    00127     template <class T, bool rt_checks>
    00128     Deferrer<T, rt_checks>::operator T () const
    00129     {
    00130       return cast (data);
    00131     }
    00132
    00134   } // End of namespace misc.
    00135 } // End of namespace vcsn.
    00136
    00137 #endif // ! VCSN_MISC_DEFERRER_HXX