Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // boost utility/base_from_member.hpp header file --------------------------// |
| 2 | |
| 3 | // Copyright 2001, 2003, 2004 Daryle Walker. Use, modification, and |
| 4 | // distribution are subject to the Boost Software License, Version 1.0. (See |
| 5 | // accompanying file LICENSE_1_0.txt or a copy at |
| 6 | // <http://www.boost.org/LICENSE_1_0.txt>.) |
| 7 | |
| 8 | // See <http://www.boost.org/libs/utility/> for the library's home page. |
| 9 | |
| 10 | #ifndef BOOST_UTILITY_BASE_FROM_MEMBER_HPP |
| 11 | #define BOOST_UTILITY_BASE_FROM_MEMBER_HPP |
| 12 | |
| 13 | #include <ndnboost/preprocessor/arithmetic/inc.hpp> |
| 14 | #include <ndnboost/preprocessor/repetition/enum_binary_params.hpp> |
| 15 | #include <ndnboost/preprocessor/repetition/enum_params.hpp> |
| 16 | #include <ndnboost/preprocessor/repetition/repeat_from_to.hpp> |
| 17 | |
| 18 | |
| 19 | // Base-from-member arity configuration macro ------------------------------// |
| 20 | |
| 21 | // The following macro determines how many arguments will be in the largest |
| 22 | // constructor template of base_from_member. Constructor templates will be |
| 23 | // generated from one argument to this maximum. Code from other files can read |
| 24 | // this number if they need to always match the exact maximum base_from_member |
| 25 | // uses. The maximum constructor length can be changed by overriding the |
| 26 | // #defined constant. Make sure to apply the override, if any, for all source |
| 27 | // files during project compiling for consistency. |
| 28 | |
| 29 | // Contributed by Jonathan Turkanis |
| 30 | |
| 31 | #ifndef BOOST_BASE_FROM_MEMBER_MAX_ARITY |
| 32 | #define BOOST_BASE_FROM_MEMBER_MAX_ARITY 10 |
| 33 | #endif |
| 34 | |
| 35 | |
| 36 | // An iteration of a constructor template for base_from_member -------------// |
| 37 | |
| 38 | // A macro that should expand to: |
| 39 | // template < typename T1, ..., typename Tn > |
| 40 | // base_from_member( T1 x1, ..., Tn xn ) |
| 41 | // : member( x1, ..., xn ) |
| 42 | // {} |
| 43 | // This macro should only persist within this file. |
| 44 | |
| 45 | #define BOOST_PRIVATE_CTR_DEF( z, n, data ) \ |
| 46 | template < BOOST_PP_ENUM_PARAMS(n, typename T) > \ |
| 47 | explicit base_from_member( BOOST_PP_ENUM_BINARY_PARAMS(n, T, x) ) \ |
| 48 | : member( BOOST_PP_ENUM_PARAMS(n, x) ) \ |
| 49 | {} \ |
| 50 | /**/ |
| 51 | |
| 52 | |
| 53 | namespace ndnboost |
| 54 | { |
| 55 | |
| 56 | // Base-from-member class template -----------------------------------------// |
| 57 | |
| 58 | // Helper to initialize a base object so a derived class can use this |
| 59 | // object in the initialization of another base class. Used by |
| 60 | // Dietmar Kuehl from ideas by Ron Klatcho to solve the problem of a |
| 61 | // base class needing to be initialized by a member. |
| 62 | |
| 63 | // Contributed by Daryle Walker |
| 64 | |
| 65 | template < typename MemberType, int UniqueID = 0 > |
| 66 | class base_from_member |
| 67 | { |
| 68 | protected: |
| 69 | MemberType member; |
| 70 | |
| 71 | base_from_member() |
| 72 | : member() |
| 73 | {} |
| 74 | |
| 75 | BOOST_PP_REPEAT_FROM_TO( 1, BOOST_PP_INC(BOOST_BASE_FROM_MEMBER_MAX_ARITY), |
| 76 | BOOST_PRIVATE_CTR_DEF, _ ) |
| 77 | |
| 78 | }; // ndnboost::base_from_member |
| 79 | |
| 80 | } // namespace ndnboost |
| 81 | |
| 82 | |
| 83 | // Undo any private macros |
| 84 | #undef BOOST_PRIVATE_CTR_DEF |
| 85 | |
| 86 | |
| 87 | #endif // BOOST_UTILITY_BASE_FROM_MEMBER_HPP |