~ubuntu-branches/ubuntu/saucy/deal.ii/saucy

« back to all changes in this revision

Viewing changes to contrib/boost-1.46.1/include/boost/spirit/home/karma/directive/center_alignment.hpp

  • Committer: Package Import Robot
  • Author(s): "Adam C. Powell, IV", Adam C. Powell, IV, Christophe Trophime
  • Date: 2012-02-21 06:57:30 UTC
  • mfrom: (3.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20120221065730-r2iz70lg557wcd2e
Tags: 7.1.0-1
[ Adam C. Powell, IV ]
* New upstream (closes: #652057).
* Updated to use PETSc and SLEPc 3.2, and forward-ported all patches.
* Removed NetCDF Build-Depends because it uses serial HDF5.
* Made Sacado cmath patch work with new configure.
* Moved -dev package symlink lines in rules to arch all section.

[ Christophe Trophime ]
* debian/rules:
   - add dh_strip --dbg-package to generate dbg package (closes: #652058)
   - add .install files to simplify rules
* Add support for mumps, arpack (closes: #637655)
* Add patch for slepc 3.2 (closes: #659245)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Copyright (c) 2001-2011 Hartmut Kaiser
 
2
//
 
3
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
 
4
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 
5
 
 
6
#if !defined(BOOST_SPIRIT_KARMA_CENTER_ALIGNMENT_FEB_27_2007_1216PM)
 
7
#define BOOST_SPIRIT_KARMA_CENTER_ALIGNMENT_FEB_27_2007_1216PM
 
8
 
 
9
#if defined(_MSC_VER)
 
10
#pragma once
 
11
#endif
 
12
 
 
13
#include <boost/spirit/home/karma/meta_compiler.hpp>
 
14
#include <boost/spirit/home/karma/generator.hpp>
 
15
#include <boost/spirit/home/karma/domain.hpp>
 
16
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
 
17
#include <boost/spirit/home/karma/detail/default_width.hpp>
 
18
#include <boost/spirit/home/karma/delimit_out.hpp>
 
19
#include <boost/spirit/home/karma/auxiliary/lazy.hpp>
 
20
#include <boost/spirit/home/support/unused.hpp>
 
21
#include <boost/spirit/home/support/common_terminals.hpp>
 
22
#include <boost/spirit/home/support/has_semantic_action.hpp>
 
23
#include <boost/spirit/home/support/handles_container.hpp>
 
24
#include <boost/spirit/home/karma/detail/attributes.hpp>
 
25
#include <boost/spirit/home/support/info.hpp>
 
26
#include <boost/spirit/home/support/unused.hpp>
 
27
#include <boost/fusion/include/at.hpp>
 
28
#include <boost/fusion/include/vector.hpp>
 
29
#include <boost/lexical_cast.hpp>
 
30
#include <boost/integer_traits.hpp>
 
31
#include <boost/mpl/bool.hpp>
 
32
#include <boost/utility/enable_if.hpp>
 
33
#include <boost/detail/workaround.hpp>
 
34
 
 
35
///////////////////////////////////////////////////////////////////////////////
 
36
namespace boost { namespace spirit
 
37
{
 
38
    ///////////////////////////////////////////////////////////////////////////
 
39
    // Enablers
 
40
    ///////////////////////////////////////////////////////////////////////////
 
41
 
 
42
    // enables center[]
 
43
    template <>
 
44
    struct use_directive<karma::domain, tag::center>
 
45
      : mpl::true_ {};
 
46
 
 
47
    // enables center(d)[g] and center(w)[g], where d is a generator
 
48
    // and w is a maximum width
 
49
    template <typename T>
 
50
    struct use_directive<karma::domain
 
51
          , terminal_ex<tag::center, fusion::vector1<T> > >
 
52
      : mpl::true_ {};
 
53
 
 
54
    // enables *lazy* delimit(d)[g], where d provides a generator
 
55
    template <>
 
56
    struct use_lazy_directive<karma::domain, tag::center, 1> 
 
57
      : mpl::true_ {};
 
58
 
 
59
    // enables center(w, d)[g], where d is a generator and w is a maximum 
 
60
    // width
 
61
    template <typename Width, typename Padding>
 
62
    struct use_directive<karma::domain
 
63
          , terminal_ex<tag::center, fusion::vector2<Width, Padding> > >
 
64
      : spirit::traits::matches<karma::domain, Padding> {};
 
65
 
 
66
    // enables *lazy* delimit(w, d)[g], where d provides a generator and w is 
 
67
    // a maximum width
 
68
    template <>
 
69
    struct use_lazy_directive<karma::domain, tag::center, 2> 
 
70
      : mpl::true_ {};
 
71
 
 
72
}}
 
73
 
 
74
///////////////////////////////////////////////////////////////////////////////
 
75
namespace boost { namespace spirit { namespace karma
 
76
{
 
77
    using spirit::center;
 
78
    using spirit::center_type;
 
79
 
 
80
    namespace detail
 
81
    {
 
82
        ///////////////////////////////////////////////////////////////////////
 
83
        //  The center_generate template function is used for all the 
 
84
        //  different flavors of the center[] directive. 
 
85
        ///////////////////////////////////////////////////////////////////////
 
86
        template <typename OutputIterator, typename Context, typename Delimiter, 
 
87
            typename Attribute, typename Embedded, typename Padding>
 
88
        inline static bool 
 
89
        center_generate(OutputIterator& sink, Context& ctx, 
 
90
            Delimiter const& d, Attribute const& attr, Embedded const& e, 
 
91
            unsigned int const width, Padding const& p) 
 
92
        {
 
93
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
 
94
            e; // suppresses warning: C4100: 'e' : unreferenced formal parameter
 
95
#endif
 
96
            // wrap the given output iterator to allow left padding
 
97
            detail::enable_buffering<OutputIterator> buffering(sink, width);
 
98
            bool r = false;
 
99
 
 
100
            // first generate the embedded output 
 
101
            {
 
102
                detail::disable_counting<OutputIterator> nocounting(sink);
 
103
                r = e.generate(sink, ctx, d, attr);
 
104
            }   // re-enable counting
 
105
 
 
106
            buffering.disable();    // do not perform buffering any more
 
107
 
 
108
            // generate the left padding
 
109
            detail::enable_counting<OutputIterator> counting(sink);
 
110
 
 
111
            std::size_t const pre = width - (buffering.buffer_size() + width)/2;
 
112
            while (r && counting.count() < pre) 
 
113
                r = p.generate(sink, ctx, unused, unused);
 
114
 
 
115
            if (r) {
 
116
                // copy the embedded output to the target output iterator
 
117
                buffering.buffer_copy();
 
118
 
 
119
                // generate the right padding
 
120
                while (r && counting.count() < width) 
 
121
                    r = p.generate(sink, ctx, unused, unused);
 
122
            }
 
123
            return r;
 
124
        }
 
125
    }
 
126
 
 
127
    ///////////////////////////////////////////////////////////////////////////
 
128
    //  The simple left alignment directive is used for center[...]
 
129
    //  generators. It uses default values for the generated width (defined via
 
130
    //  the BOOST_KARMA_DEFAULT_FIELD_LENGTH constant) and for the padding
 
131
    //  generator (always spaces).
 
132
    ///////////////////////////////////////////////////////////////////////////
 
133
    template <typename Subject, typename Width = detail::default_width>
 
134
    struct simple_center_alignment
 
135
      : unary_generator<simple_center_alignment<Subject, Width> >
 
136
    {
 
137
        typedef Subject subject_type;
 
138
 
 
139
        typedef mpl::int_<
 
140
            generator_properties::countingbuffer | subject_type::properties::value
 
141
        > properties;
 
142
 
 
143
        template <typename Context, typename Iterator>
 
144
        struct attribute
 
145
          : traits::attribute_of<subject_type, Context, Iterator>
 
146
        {};
 
147
 
 
148
        simple_center_alignment(Subject const& subject, Width width = Width())
 
149
          : subject(subject), width(width) {}
 
150
 
 
151
        template <typename OutputIterator, typename Context, typename Delimiter
 
152
          , typename Attribute>
 
153
        bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
 
154
          , Attribute const& attr) const
 
155
        {
 
156
            return detail::center_generate(sink, ctx, d, attr,
 
157
                subject, width, compile<karma::domain>(' '));
 
158
        }
 
159
 
 
160
        template <typename Context>
 
161
        info what(Context& context) const
 
162
        {
 
163
            return info("center", subject.what(context));
 
164
        }
 
165
 
 
166
        Subject subject;
 
167
        Width width;
 
168
    };
 
169
 
 
170
    ///////////////////////////////////////////////////////////////////////////
 
171
    //  The left alignment directive with padding, is used for generators like
 
172
    //  center(padding)[...], where padding is a arbitrary generator
 
173
    //  expression. It uses a default value for the generated width (defined
 
174
    //  via the BOOST_KARMA_DEFAULT_FIELD_LENGTH constant).
 
175
    ///////////////////////////////////////////////////////////////////////////
 
176
    template <typename Subject, typename Padding
 
177
      , typename Width = detail::default_width>
 
178
    struct padding_center_alignment
 
179
      : unary_generator<padding_center_alignment<Subject, Padding, Width> >
 
180
    {
 
181
        typedef Subject subject_type;
 
182
        typedef Padding padding_type;
 
183
 
 
184
        typedef mpl::int_<
 
185
            generator_properties::countingbuffer |
 
186
            subject_type::properties::value | padding_type::properties::value 
 
187
        > properties;
 
188
 
 
189
        template <typename Context, typename Iterator>
 
190
        struct attribute
 
191
          : traits::attribute_of<Subject, Context, Iterator>::type
 
192
        {};
 
193
 
 
194
        padding_center_alignment(Subject const& subject, Padding const& padding
 
195
              , Width width = Width())
 
196
          : subject(subject), padding(padding), width(width) {}
 
197
 
 
198
        template <typename OutputIterator, typename Context, typename Delimiter
 
199
          , typename Attribute>
 
200
        bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
 
201
          , Attribute const& attr) const
 
202
        {
 
203
            return detail::center_generate(sink, ctx, d, attr,
 
204
                subject, width, padding);
 
205
        }
 
206
 
 
207
        template <typename Context>
 
208
        info what(Context& context) const
 
209
        {
 
210
            return info("center", subject.what(context));
 
211
        }
 
212
 
 
213
        Subject subject;
 
214
        Padding padding;
 
215
        Width width;
 
216
    };
 
217
 
 
218
    ///////////////////////////////////////////////////////////////////////////
 
219
    // Generator generators: make_xxx function (objects)
 
220
    ///////////////////////////////////////////////////////////////////////////
 
221
 
 
222
    // creates center[] directive generator
 
223
    template <typename Subject, typename Modifiers>
 
224
    struct make_directive<tag::center, Subject, Modifiers>
 
225
    {
 
226
        typedef simple_center_alignment<Subject> result_type;
 
227
        result_type operator()(unused_type, Subject const& subject
 
228
          , unused_type) const
 
229
        {
 
230
            return result_type(subject);
 
231
        }
 
232
    };
 
233
 
 
234
    // creates center(width)[] directive generator
 
235
    template <typename Width, typename Subject, typename Modifiers>
 
236
    struct make_directive<
 
237
        terminal_ex<tag::center, fusion::vector1<Width> >
 
238
      , Subject, Modifiers
 
239
      , typename enable_if_c< integer_traits<Width>::is_integral >::type>
 
240
    {
 
241
        typedef simple_center_alignment<Subject, Width> result_type;
 
242
 
 
243
        template <typename Terminal>
 
244
        result_type operator()(Terminal const& term, Subject const& subject
 
245
          , unused_type) const
 
246
        {
 
247
            return result_type(subject, fusion::at_c<0>(term.args));
 
248
        }
 
249
    };
 
250
 
 
251
    // creates center(pad)[] directive generator
 
252
    template <typename Padding, typename Subject, typename Modifiers>
 
253
    struct make_directive<
 
254
        terminal_ex<tag::center, fusion::vector1<Padding> >
 
255
      , Subject, Modifiers
 
256
      , typename enable_if<
 
257
            mpl::and_<
 
258
                spirit::traits::matches<karma::domain, Padding>,
 
259
                mpl::not_<mpl::bool_<integer_traits<Padding>::is_integral> >
 
260
            >
 
261
        >::type>
 
262
    {
 
263
        typedef typename
 
264
            result_of::compile<karma::domain, Padding, Modifiers>::type
 
265
        padding_type;
 
266
 
 
267
        typedef padding_center_alignment<Subject, padding_type> result_type;
 
268
 
 
269
        template <typename Terminal>
 
270
        result_type operator()(Terminal const& term, Subject const& subject
 
271
          , Modifiers const& modifiers) const
 
272
        {
 
273
            return result_type(subject
 
274
              , compile<karma::domain>(fusion::at_c<0>(term.args), modifiers));
 
275
        }
 
276
    };
 
277
 
 
278
    // creates center(width, pad)[] directive generator
 
279
    template <typename Width, typename Padding, typename Subject
 
280
      , typename Modifiers>
 
281
    struct make_directive<
 
282
        terminal_ex<tag::center, fusion::vector2<Width, Padding> >
 
283
      , Subject, Modifiers>
 
284
    {
 
285
        typedef typename
 
286
            result_of::compile<karma::domain, Padding, Modifiers>::type
 
287
        padding_type;
 
288
 
 
289
        typedef padding_center_alignment<Subject, padding_type, Width> result_type;
 
290
 
 
291
        template <typename Terminal>
 
292
        result_type operator()(Terminal const& term, Subject const& subject
 
293
          , Modifiers const& modifiers) const
 
294
        {
 
295
            return result_type(subject
 
296
              , compile<karma::domain>(fusion::at_c<1>(term.args), modifiers)
 
297
              , fusion::at_c<0>(term.args));
 
298
        }
 
299
    };
 
300
 
 
301
}}} // namespace boost::spirit::karma
 
302
 
 
303
namespace boost { namespace spirit { namespace traits
 
304
{
 
305
    ///////////////////////////////////////////////////////////////////////////
 
306
    template <typename Subject, typename Width>
 
307
    struct has_semantic_action<karma::simple_center_alignment<Subject, Width> >
 
308
      : unary_has_semantic_action<Subject> {};
 
309
 
 
310
    template <typename Subject, typename Padding, typename Width>
 
311
    struct has_semantic_action<
 
312
            karma::padding_center_alignment<Subject, Padding, Width> >
 
313
      : unary_has_semantic_action<Subject> {};
 
314
 
 
315
    ///////////////////////////////////////////////////////////////////////////
 
316
    template <typename Subject, typename Width, typename Attribute
 
317
      , typename Context, typename Iterator>
 
318
    struct handles_container<
 
319
            karma::simple_center_alignment<Subject, Width>, Attribute
 
320
          , Context, Iterator>
 
321
      : unary_handles_container<Subject, Attribute, Context, Iterator> {};
 
322
 
 
323
    template <typename Subject, typename Padding, typename Width
 
324
      , typename Attribute, typename Context, typename Iterator>
 
325
    struct handles_container<
 
326
            karma::padding_center_alignment<Subject, Padding, Width>
 
327
          , Attribute, Context, Iterator>
 
328
      : unary_handles_container<Subject, Attribute, Context, Iterator> {};
 
329
}}}
 
330
 
 
331
#endif
 
332
 
 
333