blob: 899bd37a04f52111e86ffb84c29eedff38a65915 [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001// 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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070010#ifndef NDNBOOST_UTILITY_BASE_FROM_MEMBER_HPP
11#define NDNBOOST_UTILITY_BASE_FROM_MEMBER_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070012
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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070031#ifndef NDNBOOST_BASE_FROM_MEMBER_MAX_ARITY
32#define NDNBOOST_BASE_FROM_MEMBER_MAX_ARITY 10
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070033#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
Jeff Thompson3d613fd2013-10-15 15:39:04 -070045#define NDNBOOST_PRIVATE_CTR_DEF( z, n, data ) \
46 template < NDNBOOST_PP_ENUM_PARAMS(n, typename T) > \
47 explicit base_from_member( NDNBOOST_PP_ENUM_BINARY_PARAMS(n, T, x) ) \
48 : member( NDNBOOST_PP_ENUM_PARAMS(n, x) ) \
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070049 {} \
50 /**/
51
52
53namespace 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
65template < typename MemberType, int UniqueID = 0 >
66class base_from_member
67{
68protected:
69 MemberType member;
70
71 base_from_member()
72 : member()
73 {}
74
Jeff Thompson3d613fd2013-10-15 15:39:04 -070075 NDNBOOST_PP_REPEAT_FROM_TO( 1, NDNBOOST_PP_INC(NDNBOOST_BASE_FROM_MEMBER_MAX_ARITY),
76 NDNBOOST_PRIVATE_CTR_DEF, _ )
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070077
78}; // ndnboost::base_from_member
79
80} // namespace ndnboost
81
82
83// Undo any private macros
Jeff Thompson3d613fd2013-10-15 15:39:04 -070084#undef NDNBOOST_PRIVATE_CTR_DEF
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070085
86
Jeff Thompson3d613fd2013-10-15 15:39:04 -070087#endif // NDNBOOST_UTILITY_BASE_FROM_MEMBER_HPP