00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 utility
00038 {
00039
00042
00043
00044
00045
00046 template <class T, bool B>
00047 DeferrerDebugPart<T, B>::DeferrerDebugPart(void* ptr, bool is_valid) :
00048 is_valid_ (is_valid)
00049 {
00050 memset(ptr, 0, sizeof(T));
00051 }
00052
00053 template <class T, bool B>
00054 void
00055 DeferrerDebugPart<T, B>::set_valid(bool b)
00056 {
00057 if (is_valid_)
00058 warning("Modifying a valid Deferrer<T, true>.");
00059 is_valid_ = b;
00060 }
00061
00062 template <class T, bool B>
00063 T&
00064 DeferrerDebugPart<T, B>::cast(void *ptr)
00065 {
00066 precondition(is_valid_);
00067 return *reinterpret_cast<T*> (ptr);
00068 }
00069
00070 template <class T, bool B>
00071 const T&
00072 DeferrerDebugPart<T, B>::cast(const void *ptr) const
00073 {
00074 precondition(is_valid_);
00075 return *reinterpret_cast<const T*> (ptr);
00076 }
00077
00078
00079
00080
00081
00082 template <class T>
00083 DeferrerDebugPart<T, false>::DeferrerDebugPart(void*, bool)
00084 {
00085 }
00086
00087 template <class T>
00088 void
00089 DeferrerDebugPart<T, false>::set_valid(bool)
00090 {
00091 }
00092
00093 template <class T>
00094 T&
00095 DeferrerDebugPart<T, false>::cast(void *ptr)
00096 {
00097 return *reinterpret_cast<T*> (ptr);
00098 }
00099
00100 template <class T>
00101 const T&
00102 DeferrerDebugPart<T, false>::cast(const void *ptr) const
00103 {
00104 return *reinterpret_cast<const T*> (ptr);
00105 }
00106
00107
00108
00109
00110
00111 template <class T, bool rt_checks>
00112 Deferrer<T, rt_checks>::Deferrer() : DeferrerDebugPart<T, rt_checks> (data)
00113 {
00114 }
00115
00116 template <class T, bool rt_checks>
00117 Deferrer<T, rt_checks>&
00118 Deferrer<T, rt_checks>::operator = (const deferred_type& rhs)
00119 {
00120 new (data) deferred_type (rhs);
00121 this->set_valid(true);
00122 return *this;
00123 }
00124
00125 template <class T, bool rt_checks>
00126 Deferrer<T, rt_checks>::operator T () const
00127 {
00128 return cast(data);
00129 }
00130
00132 }
00133
00134 #endif // ! VCSN_MISC_DEFERRER_HXX