Vaucanson  1.4.1
deferrer.hh
Go to the documentation of this file.
1 // deferrer.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2004, 2005, 2006 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_MISC_DEFERRER_HH
18 # define VCSN_MISC_DEFERRER_HH
19 
31 namespace vcsn
32 {
33  namespace misc
34  {
35 
38 # ifndef VCSN_NDEBUG
39  enum { deferrer_runtime_checks_default = true };
40 # else // VCSN_NDEBUG
41  enum { deferrer_runtime_checks_default = false };
42 # endif // ! VCSN_NDEBUG
43 
45 
46  template <class T, bool B>
48  {
49  protected:
50  // Defaults to true.
51  DeferrerDebugPart (void* ptr, bool is_valid = false);
52 
53  void set_valid (bool b);
54  T& cast (void*);
55  const T& cast (const void*) const;
56 
57  bool is_valid_;
58  };
59 
60  template <class T>
61  struct DeferrerDebugPart<T, false>
62  {
63  protected:
64  // False version.
65  DeferrerDebugPart (void* ptr, bool is_valid = false);
66  void set_valid (bool b);
67  T& cast (void*);
68  const T& cast (const void*) const;
69  };
95  template <class T, bool rt_checks = deferrer_runtime_checks_default>
96  struct Deferrer : DeferrerDebugPart<T, rt_checks>
97  {
98  typedef T deferred_type;
99 
108  Deferrer ();
109 
117  Deferrer&
118  operator= (const deferred_type&);
119 
121  operator T () const;
122  protected:
123  typedef unsigned char data_t[sizeof (deferred_type)];
124 
132  data_t data;
133  };
134 
136  } // End of namespace misc.
137 } // End of namespace vcsn.
138 
139 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
140 # include <vaucanson/misc/deferrer.hxx>
141 # endif // VCSN_USE_INTERFACE_ONLY
142 
143 #endif // ! VCSN_MISC_DEFERRER_HH