Vaucanson 1.4
constraints.hh
00001 // constraints.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_CONSTRAINTS_HH
00018 # define VCSN_MISC_CONSTRAINTS_HH
00019 
00020 
00021 namespace vcsn
00022 {
00023   namespace misc
00024   {
00025 
00026   /*---------------------------.
00027   | Static constraint checking |
00028   `---------------------------*/
00029 
00030     // this stuff is heavily inspired from the C++ Boost Library.
00031     // Use it sparingly, it can cause HUGE amounts of template instanciations.
00032 
00033 # if defined(__GNUC__)
00034 #  define UnusedConceptVar __attribute__ ((__unused__))
00035 # else
00036 #  define UnusedConceptVar /* unused */
00037 # endif
00038 
00039     namespace concepts
00040     {
00041       template <typename Concept_>
00042       static void function_requires()
00043       {
00044         void (Concept_::*ptr)() UnusedConceptVar = &Concept_::constraints;
00045       }
00046 
00047       // deep wizardry at work here...
00048 
00049 # define MISC_CLASS_CHECKING_IDX(Lineno, Concept, T) \
00050       ConceptChecking ## Lineno ## _ ## Concept ## T
00051 # define MISC_CLASS_CHECKING_ID(Lineno, Concept, T)     \
00052       MISC_CLASS_CHECKING_IDX(Lineno, Concept, T)
00053 # define MISC_CLASS_FPTR_IDX(Lineno, Concept, T)        \
00054       Concept ## Lineno ## _fptr_ ## T
00055 # define MISC_CLASS_FPTR_ID(Lineno, Concept, T) \
00056       MISC_CLASS_FPTR_IDX(Lineno, Concept, T)
00057 
00058 # ifdef VCSN_NDEBUG
00059 
00060 #  define MISC_CLASS_REQUIRE_CONCEPT(Var, Namespace, Concept)   \
00061       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00062 #  define MISC_CLASS_REQUIRE_CONCEPT2(Var1, Var2, Namespace, Concept) \
00063       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00064 #  define MISC_CLASS_REQUIRE_CONCEPT3(Var1, Var2, Var3, Namespace, Concept) \
00065       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00066 #  define MISC_CLASS_REQUIRE_CONCEPT4(Var1, Var2, Var3, Var4, Namespace, Concept) \
00067       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00068 #  define MISC_REQUIRE_CONCEPT(Var, Namespace, Concept)         \
00069       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00070 #  define MISC_REQUIRE_CONCEPT2(Var1, Var2, Namespace, Concept) \
00071       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00072 #  define MISC_REQUIRE_CONCEPT3(Var1, Var2, Var3, Namespace, Concept) \
00073       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00074 #  define MISC_REQUIRE_CONCEPT4(Var1, Var2, Var3, Var4, Namespace, Concept) \
00075       typedef void MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00076 
00077 # else // VCSN_NDEBUG
00078 
00079       // these should be left 120 columns wide for better readability
00080 
00081 #  define MISC_CLASS_REQUIRE_CONCEPT(Var, Namespace, Concept)   \
00082       typedef void (Namespace::Concept <Var>::* MISC_CLASS_FPTR_ID(__LINE__, Concept, t))();    \
00083       template <MISC_CLASS_FPTR_ID(__LINE__, Concept, t) MISC_CLASS_FPTR_ID(__LINE__, Concept, arg)> \
00084       struct MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s) {};  \
00085       typedef MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s)<& Namespace::Concept<Var>::constraints> \
00086               MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00087 
00088 #  define MISC_CLASS_REQUIRE_CONCEPT2(Var1, Var2, Namespace, Concept) \
00089       typedef void (Namespace::Concept <Var1,Var2>::* MISC_CLASS_FPTR_ID(__LINE__, Concept, t))(); \
00090       template <MISC_CLASS_FPTR_ID(__LINE__, Concept, t) MISC_CLASS_FPTR_ID(__LINE__, Concept, arg)> \
00091       struct MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s) {};  \
00092       typedef MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s)<& Namespace::Concept<Var1,Var2>::constraints> \
00093               MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00094 
00095 #  define MISC_CLASS_REQUIRE_CONCEPT3(Var1, Var2, Var3, Namespace, Concept) \
00096       typedef void (Namespace::Concept <Var1,Var2,Var3>::* MISC_CLASS_FPTR_ID(__LINE__, Concept, t))(); \
00097       template <MISC_CLASS_FPTR_ID(__LINE__, Concept, t) MISC_CLASS_FPTR_ID(__LINE__, Concept, arg)> \
00098       struct MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s) {};  \
00099       typedef MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s)<& Namespace::Concept<Var1,Var2,Var3>::constraints> \
00100               MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00101 
00102 #  define MISC_CLASS_REQUIRE_CONCEPT4(Var1, Var2, Var3, Var4, Namespace, Concept) \
00103       typedef void (Namespace::Concept <Var1,Var2,Var3,Var4>::* MISC_CLASS_FPTR_ID(__LINE__, Concept, t))();    \
00104       template <MISC_CLASS_FPTR_ID(__LINE__, Concept, t) MISC_CLASS_FPTR_ID(__LINE__, Concept, arg)> \
00105       struct MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s) {};  \
00106       typedef MISC_CLASS_CHECKING_ID(__LINE__, Concept, _s)<& Namespace::Concept<Var1,Var2,Var3,Var4>::constraints> \
00107               MISC_CLASS_CHECKING_ID(__LINE__, Concept, _t)
00108 
00109 #  define MISC_REQUIRE_CONCEPT(Var, Namespace, Concept)         \
00110       vcsn::misc::concepts::function_requires<Namespace::Concept <Var> >()
00111 #  define MISC_REQUIRE_CONCEPT2(Var1, Var2, Namespace, Concept) \
00112       vcsn::misc::concepts::function_requires<Namespace::Concept <Var1, Var2> >()
00113 #  define MISC_REQUIRE_CONCEPT3(Var1, Var2, Var3, Namespace, Concept) \
00114       vcsn::misc::concepts::function_requires<Namespace::Concept <Var1, Var2, Var3> >()
00115 #  define MISC_REQUIRE_CONCEPT4(Var1, Var2, Var3, Var4, Namespace, Concept) \
00116       vcsn::misc::concepts::function_requires<Namespace::Concept <Var1, Var2, Var3, Var4> >()
00117 
00118 # endif // ! VCSN_NDEBUG
00119 
00120     } // concepts
00121   } // misc
00122 } // vcsn
00123 
00124 #endif // ! VCSN_MISC_CONSTRAINTS_HH