X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2Fmpl.hh;h=fb1b5664c36e900b4e817f626cd5dfec857e5b1f;hb=f2f5d59e83863f3b513950173baee1b6da2aee3c;hp=2983ffecc410d9843d85dbb341ffc5d93a9079bb;hpb=21bad90912447cd2d390112cf2d2a7d383ad8058;p=senf.git diff --git a/Utils/mpl.hh b/Utils/mpl.hh index 2983ffe..fb1b566 100644 --- a/Utils/mpl.hh +++ b/Utils/mpl.hh @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -23,10 +23,11 @@ /** \file \brief mpl public header */ -#ifndef HH_mpl_ -#define HH_mpl_ 1 +#ifndef HH_SENF_Utils_mpl_ +#define HH_SENF_Utils_mpl_ 1 // Custom includes +#include "../config.hh" //#include "mpl.mpp" #include "mpl.ih" @@ -35,12 +36,18 @@ namespace senf { namespace mpl { - /** \defgroup senfmpl Low-level template meta programming helpers + /** \defgroup senfmpl Template meta programming helpers */ -# ifndef SENF_MPL_RV_ALIGNMENT -# define SENF_MPL_RV_ALIGNMENT 16 -# endif + /** \brief Marker class for empty default values etc. + + This is like Boosts \c boost::mpl::na just an empty class used as template default argument + to mark missing arguments + + \note Don't use this as an empty base class. We may add some informative members to this. + \ingroup senfmpl + */ + struct nil {}; /** \brief Return-value type used to implement overload selection @@ -99,8 +106,8 @@ namespace mpl { never called. This number is than forwarded as template argument to \c select which is specialized for - each case. Therefore, choice has a \c frobble() member whereas - choice has a \c dazzle() member. + each case. Therefore, choice\ has a \c frobble() member whereas + choice\ has a \c dazzle() member. \see \ref SENF_MPL_RV \ingroup senfmpl @@ -149,29 +156,31 @@ namespace mpl { */ template struct take_class {}; - /** \brief Define 'previous value' slot +#ifndef SENF_MPL_SLOT_NOEXPAND + + /** \brief Define MPL slot - The 'previous value' macros \ref SENF_MPL_PREVV_DEF(), \ref SENF_MPL_PREVV_SET() and \ref - SENF_MPL_PREVV_GET() provide a facility to get the last unsigned integer value assigned to + The slot macros \ref SENF_MPL_SLOT_DEF(), \ref SENF_MPL_SLOT_SET() and \ref + SENF_MPL_SLOT_GET() provide a facility to get the last unsigned integer value assigned to the slot before the current point in the current class. \code struct Foo { - // Define PREVV slot named 'accum' initialized to 0 - SENF_MPL_PREVV_DEF(accum, 0); + // Define SLOT slot named 'accum' initialized to 0 + SENF_MPL_SLOT_DEF(accum, 0); // Add 2 to 'accum' - SENF_MPL_PREVV_SET(accum, SENF_MPL_PREVV_GET(accum) + 2); + SENF_MPL_SLOT_SET(accum, SENF_MPL_SLOT_GET(accum) + 2); // Multiply 'accum' by 3 - SENF_MPL_PREVV_SET(accum, SENF_MPL_PREVV_GET(accum) * 3); + SENF_MPL_SLOT_SET(accum, SENF_MPL_SLOT_GET(accum) * 3); // Define the result as a constant expression. result is now 6 - static unsigned result = SENF_MPL_PREVV_GET(accum); + static unsigned result = SENF_MPL_SLOT_GET(accum); }; \endcode Of course, it does not make sense to use these macros for simple arithmetic as in the - example. The SENF_MPL_PREVV macros allow to define macros which pass information from one + example. The SENF_MPL_SLOT macros allow to define macros which pass information from one macro invocation to the next. \implementation The implementation is based on __LINE__: We check backwards for a value @@ -180,26 +189,40 @@ namespace mpl { \ingroup senfmpl \hideinitializer */ -# define SENF_MPL_PREVV_DEF(name,value) \ - template \ - static senf::mpl::rv<0> _SENF_MPL_PREVV_ ## name (senf::mpl::rv<_> *); \ - SENF_MPL_PREVV_SET(name,value) +# define SENF_MPL_SLOT_DEF(name,value) \ + template \ + static senf::mpl::rv<0> _SENF_MPL_SLOT_ ## name (_); \ + SENF_MPL_SLOT_SET(name,value) - /** \brief Set 'prevision value' slot - \see \ref SENF_MPL_PREVV_DEF() + /** \brief Define MPL slot initialized to 0 + + This is like \ref SENF_MPL_SLOT_DEF() but initializes the slot to the fixed value 0. The + advantage over \ref SENF_MPL_SLOT_DEF() is, that this macro may be called from an include + file whereas all the other \\c SENF_MPL_SLOT_ macros must always be called from the relevant + file. + */ +# define SENF_MPL_SLOT_DEF_ZERO(name) \ + template \ + static senf::mpl::rv<0> _SENF_MPL_SLOT_ ## name (_); + + /** \brief Set MPL slot + \see \ref SENF_MPL_SLOT_DEF() \ingroup senfmpl \hideinitializer */ -# define SENF_MPL_PREVV_SET(name,value) \ - static senf::mpl::rv _SENF_MPL_PREVV_ ## name (senf::mpl::rv<__LINE__>*) +# define SENF_MPL_SLOT_SET(name,value) \ + static senf::mpl::rv \ + _SENF_MPL_SLOT_ ## name (senf::mpl::take_int<__LINE__>) - /** \brief Get current 'previous value' slot value - \see \ref SENF_MPL_PREVV_DEF() + /** \brief Get current MPL slot value + \see \ref SENF_MPL_SLOT_DEF() \ingroup senfmpl \hideinitializer */ -# define SENF_MPL_PREVV_GET(name) \ - SENF_MPL_PREVV_I_GET(name) +# define SENF_MPL_SLOT_GET(name) \ + SENF_MPL_SLOT_I_GET(name) + +#endif }}