Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 1 | // Copyright (C) 2003, Fernando Luis Cacciola Carballal. |
| 2 | // Copyright (C) 2007, Tobias Schwinger. |
| 3 | // |
| 4 | // Use, modification, and distribution is subject to the Boost Software |
| 5 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
| 7 | // |
| 8 | // See http://www.boost.org/libs/optional for documentation. |
| 9 | // |
| 10 | // You are welcome to contact the author at: |
| 11 | // fernando_cacciola@hotmail.com |
| 12 | // |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 13 | #ifndef NDNBOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP |
| 14 | #ifndef NDNBOOST_PP_IS_ITERATING |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 15 | |
| 16 | #include <ndnboost/utility/detail/in_place_factory_prefix.hpp> |
| 17 | |
| 18 | namespace ndnboost { |
| 19 | |
| 20 | class in_place_factory_base {} ; |
| 21 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 22 | #define NDNBOOST_PP_ITERATION_LIMITS (0, NDNBOOST_MAX_INPLACE_FACTORY_ARITY) |
| 23 | #define NDNBOOST_PP_FILENAME_1 <ndnboost/utility/in_place_factory.hpp> |
| 24 | #include NDNBOOST_PP_ITERATE() |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 25 | |
| 26 | } // namespace ndnboost |
| 27 | |
| 28 | #include <ndnboost/utility/detail/in_place_factory_suffix.hpp> |
| 29 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 30 | #define NDNBOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 31 | #else |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 32 | #define N NDNBOOST_PP_ITERATION() |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 33 | |
| 34 | #if N |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 35 | template< NDNBOOST_PP_ENUM_PARAMS(N, class A) > |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 36 | #endif |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 37 | class NDNBOOST_PP_CAT(in_place_factory,N) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 38 | : |
| 39 | public in_place_factory_base |
| 40 | { |
| 41 | public: |
| 42 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 43 | explicit NDNBOOST_PP_CAT(in_place_factory,N) |
| 44 | ( NDNBOOST_PP_ENUM_BINARY_PARAMS(N,A,const& a) ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 45 | #if N > 0 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 46 | : NDNBOOST_PP_ENUM(N, NDNBOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 47 | #endif |
| 48 | {} |
| 49 | |
| 50 | template<class T> |
| 51 | void* apply(void* address |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 52 | NDNBOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 53 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 54 | return new(address) T( NDNBOOST_PP_ENUM_PARAMS(N, m_a) ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | template<class T> |
| 58 | void* apply(void* address, std::size_t n |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 59 | NDNBOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 60 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 61 | for(char* next = address = this->NDNBOOST_NESTED_TEMPLATE apply<T>(address); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 62 | !! --n;) |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 63 | this->NDNBOOST_NESTED_TEMPLATE apply<T>(next = next+sizeof(T)); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 64 | return address; |
| 65 | } |
| 66 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 67 | NDNBOOST_PP_REPEAT(N, NDNBOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | #if N > 0 |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 71 | template< NDNBOOST_PP_ENUM_PARAMS(N, class A) > |
| 72 | inline NDNBOOST_PP_CAT(in_place_factory,N)< NDNBOOST_PP_ENUM_PARAMS(N, A) > |
| 73 | in_place( NDNBOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) ) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 74 | { |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame] | 75 | return NDNBOOST_PP_CAT(in_place_factory,N)< NDNBOOST_PP_ENUM_PARAMS(N, A) > |
| 76 | ( NDNBOOST_PP_ENUM_PARAMS(N, a) ); |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 77 | } |
| 78 | #else |
| 79 | inline in_place_factory0 in_place() |
| 80 | { |
| 81 | return in_place_factory0(); |
| 82 | } |
| 83 | #endif |
| 84 | |
| 85 | #undef N |
| 86 | #endif |
| 87 | #endif |
| 88 | |