Statistics
| Revision:

root / tmp / org.txm.statsengine.r.core.win32 / res / win32 / library / BH / include / boost / accumulators / framework / extractor.hpp @ 2486

History | View | Annotate | Download (10.4 kB)

1
///////////////////////////////////////////////////////////////////////////////
2
// extractor.hpp
3
//
4
//  Copyright 2005 Eric Niebler. Distributed under the Boost
5
//  Software License, Version 1.0. (See accompanying file
6
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

    
8
#ifndef BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005
9
#define BOOST_ACCUMULATORS_FRAMEWORK_EXTRACTOR_HPP_EAN_28_10_2005
10

    
11
#include <boost/preprocessor/tuple/rem.hpp>
12
#include <boost/preprocessor/array/size.hpp>
13
#include <boost/preprocessor/array/data.hpp>
14
#include <boost/preprocessor/array/elem.hpp>
15
#include <boost/preprocessor/seq/to_array.hpp>
16
#include <boost/preprocessor/seq/transform.hpp>
17
#include <boost/preprocessor/repetition/enum_params.hpp>
18
#include <boost/preprocessor/repetition/enum_trailing_params.hpp>
19
#include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
20
#include <boost/parameter/binding.hpp>
21
#include <boost/mpl/apply.hpp>
22
#include <boost/mpl/eval_if.hpp>
23
#include <boost/type_traits/remove_reference.hpp>
24
#include <boost/accumulators/accumulators_fwd.hpp>
25
#include <boost/accumulators/framework/parameters/accumulator.hpp>
26

    
27
namespace boost { namespace accumulators
28
{
29

    
30
namespace detail
31
{
32
    template<typename AccumulatorSet, typename Feature>
33
    struct accumulator_set_result
34
    {
35
        typedef typename as_feature<Feature>::type feature_type;
36
        typedef typename mpl::apply<AccumulatorSet, feature_type>::type::result_type type;
37
    };
38

    
39
    template<typename Args, typename Feature>
40
    struct argument_pack_result
41
      : accumulator_set_result<
42
            typename remove_reference<
43
                typename parameter::binding<Args, tag::accumulator>::type
44
            >::type
45
          , Feature
46
        >
47
    {
48
    };
49

    
50
    template<typename A, typename Feature>
51
    struct extractor_result
52
      : mpl::eval_if<
53
            detail::is_accumulator_set<A>
54
          , accumulator_set_result<A, Feature>
55
          , argument_pack_result<A, Feature>
56
        >
57
    {
58
    };
59

    
60
    template<typename Feature, typename AccumulatorSet>
61
    typename extractor_result<AccumulatorSet, Feature>::type
62
    do_extract(AccumulatorSet const &acc, mpl::true_)
63
    {
64
        typedef typename as_feature<Feature>::type feature_type;
65
        return extract_result<feature_type>(acc);
66
    }
67

    
68
    template<typename Feature, typename Args>
69
    typename extractor_result<Args, Feature>::type
70
    do_extract(Args const &args, mpl::false_)
71
    {
72
        typedef typename as_feature<Feature>::type feature_type;
73
        return find_accumulator<feature_type>(args[accumulator]).result(args);
74
    }
75

    
76
} // namespace detail
77

    
78

    
79
///////////////////////////////////////////////////////////////////////////////
80
/// Extracts the result associated with Feature from the specified accumulator_set.
81
template<typename Feature>
82
struct extractor
83
{
84
    typedef extractor<Feature> this_type;
85

    
86
    /// The result meta-function for determining the return type of the extractor
87
    template<typename F>
88
    struct result;
89

    
90
    template<typename A1>
91
    struct result<this_type(A1)>
92
      : detail::extractor_result<A1, Feature>
93
    {
94
    };
95

    
96
    /// Extract the result associated with Feature from the accumulator set
97
    /// \param acc The accumulator set object from which to extract the result
98
    template<typename Arg1>
99
    typename detail::extractor_result<Arg1, Feature>::type
100
    operator ()(Arg1 const &arg1) const
101
    {
102
        // Arg1 could be an accumulator_set or an argument pack containing
103
        // an accumulator_set. Dispatch accordingly.
104
        return detail::do_extract<Feature>(arg1, detail::is_accumulator_set<Arg1>());
105
    }
106

    
107
    /// \overload
108
    ///
109
    /// \param a1 Optional named parameter to be passed to the accumulator's result() function.
110
    template<typename AccumulatorSet, typename A1>
111
    typename detail::extractor_result<AccumulatorSet, Feature>::type
112
    operator ()(AccumulatorSet const &acc, A1 const &a1) const
113
    {
114
        BOOST_MPL_ASSERT((detail::is_accumulator_set<AccumulatorSet>));
115
        typedef typename as_feature<Feature>::type feature_type;
116
        return extract_result<feature_type>(acc, a1);
117
    }
118

    
119
    // ... other overloads generated by Boost.Preprocessor:
120

    
121
    /// INTERNAL ONLY
122
    ///
123
#define BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP(z, n, _)                                    \
124
    template<BOOST_PP_ENUM_PARAMS_Z(z, n, typename A)>                                  \
125
    struct result<this_type(BOOST_PP_ENUM_PARAMS_Z(z, n, A))>                           \
126
      : detail::extractor_result<A1, Feature>                                           \
127
    {};                                                                                 \
128
    template<                                                                           \
129
        typename AccumulatorSet                                                         \
130
        BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A)                               \
131
    >                                                                                   \
132
    typename detail::extractor_result<AccumulatorSet, Feature>::type                    \
133
    operator ()(                                                                        \
134
        AccumulatorSet const &acc                                                       \
135
        BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a)                       \
136
    ) const                                                                             \
137
    {                                                                                   \
138
        BOOST_MPL_ASSERT((detail::is_accumulator_set<AccumulatorSet>));                 \
139
        typedef typename as_feature<Feature>::type feature_type;                        \
140
        return extract_result<feature_type>(acc BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a));\
141
    }
142

    
143
    BOOST_PP_REPEAT_FROM_TO(
144
        2
145
      , BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)
146
      , BOOST_ACCUMULATORS_EXTRACTOR_FUN_OP
147
      , _
148
    )
149

    
150
    #ifdef BOOST_ACCUMULATORS_DOXYGEN_INVOKED
151
    /// \overload
152
    ///
153
    template<typename AccumulatorSet, typename A1, typename A2, ...>
154
    typename detail::extractor_result<AccumulatorSet, Feature>::type
155
    operator ()(AccumulatorSet const &acc, A1 const &a1, A2 const &a2, ...);
156
    #endif
157
};
158

    
159
/// INTERNAL ONLY
160
///
161
#define BOOST_ACCUMULATORS_ARRAY_REM(Array)                                                         \
162
    BOOST_PP_TUPLE_REM_CTOR(BOOST_PP_ARRAY_SIZE(Array), BOOST_PP_ARRAY_DATA(Array))
163

    
164
/// INTERNAL ONLY
165
///
166
#define BOOST_ACCUMULATORS_SEQ_REM(Seq)                                                             \
167
    BOOST_ACCUMULATORS_ARRAY_REM(BOOST_PP_SEQ_TO_ARRAY(Seq))
168

    
169
/// INTERNAL ONLY
170
///
171
#define BOOST_ACCUMULATORS_ARGS_OP(s, data, elem)                                                   \
172
    T ## s
173

    
174
/// INTERNAL ONLY
175
///
176
#define BOOST_ACCUMULATORS_PARAMS_OP(s, data, elem)                                                 \
177
    elem T ## s
178

    
179
/// INTERNAL ONLY
180
///
181
#define BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq)                                    \
182
    Tag::Feature<                                                                                   \
183
        BOOST_ACCUMULATORS_SEQ_REM(                                                                 \
184
            BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_ARGS_OP, ~, ParamsSeq)                        \
185
        )                                                                                           \
186
    >
187

    
188
/// INTERNAL ONLY
189
///
190
#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL(z, n, Tag, Feature, ParamsSeq)                 \
191
    template<                                                                                       \
192
        BOOST_ACCUMULATORS_SEQ_REM(                                                                 \
193
            BOOST_PP_SEQ_TRANSFORM(BOOST_ACCUMULATORS_PARAMS_OP, ~, ParamsSeq)                      \
194
        )                                                                                           \
195
      , typename Arg1                                                                               \
196
        BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, typename A)                                           \
197
    >                                                                                               \
198
    typename boost::accumulators::detail::extractor_result<                                         \
199
        Arg1                                                                                        \
200
      , BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq)                                    \
201
    >::type                                                                                         \
202
    Feature(Arg1 const &arg1 BOOST_PP_ENUM_TRAILING_BINARY_PARAMS_Z(z, n, A, const &a) )            \
203
    {                                                                                               \
204
        typedef BOOST_ACCUMULATORS_MAKE_FEATURE(Tag, Feature, ParamsSeq) feature_type;              \
205
        return boost::accumulators::extractor<feature_type>()(                                      \
206
            arg1 BOOST_PP_ENUM_TRAILING_PARAMS_Z(z, n, a));                                         \
207
    }
208

    
209
/// INTERNAL ONLY
210
///
211
#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN(z, n, _)                                            \
212
    BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN_IMPL(                                                   \
213
        z                                                                                           \
214
      , n                                                                                           \
215
      , BOOST_PP_ARRAY_ELEM(0, _)                                                                   \
216
      , BOOST_PP_ARRAY_ELEM(1, _)                                                                   \
217
      , BOOST_PP_ARRAY_ELEM(2, _)                                                                   \
218
    )
219

    
220
#define BOOST_ACCUMULATORS_DEFINE_EXTRACTOR(Tag, Feature, ParamSeq)                                 \
221
    BOOST_PP_REPEAT(                                                                                \
222
        BOOST_PP_INC(BOOST_ACCUMULATORS_MAX_ARGS)                                                   \
223
      , BOOST_ACCUMULATORS_DEFINE_EXTRACTOR_FUN                                                     \
224
      , (3, (Tag, Feature, ParamSeq))                                                               \
225
    )
226

    
227
}} // namespace boost::accumulators
228

    
229
#endif