annotate DEPENDENCIES/generic/include/boost/spirit/home/karma/numeric/bool_policies.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // Copyright (c) 2001-2011 Hartmut Kaiser
Chris@16 2 //
Chris@16 3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
Chris@16 4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
Chris@16 5
Chris@16 6 #if !defined(BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM)
Chris@16 7 #define BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM
Chris@16 8
Chris@16 9 #if defined(_MSC_VER)
Chris@16 10 #pragma once
Chris@16 11 #endif
Chris@16 12
Chris@16 13 #include <boost/spirit/home/support/char_class.hpp>
Chris@16 14 #include <boost/spirit/home/karma/generator.hpp>
Chris@16 15 #include <boost/spirit/home/karma/char.hpp>
Chris@16 16 #include <boost/spirit/home/karma/numeric/detail/numeric_utils.hpp>
Chris@16 17
Chris@16 18 namespace boost { namespace spirit { namespace karma
Chris@16 19 {
Chris@16 20 ///////////////////////////////////////////////////////////////////////////
Chris@16 21 //
Chris@16 22 // bool_policies, if you need special handling of your boolean output
Chris@16 23 // just overload this policy class and use it as a template
Chris@16 24 // parameter to the karma::bool_generator boolean generator
Chris@16 25 //
Chris@16 26 // struct special_bool_policy : karma::bool_policies<>
Chris@16 27 // {
Chris@16 28 // // we want to spell the names of false as eurt (true backwards)
Chris@16 29 // template <typename CharEncoding, typename Tag
Chris@16 30 // , typename OutputIterator>
Chris@16 31 // static bool generate_false(OutputIterator& sink, bool)
Chris@16 32 // {
Chris@16 33 // return string_inserter<CharEncoding, Tag>::call(sink, "eurt");
Chris@16 34 // }
Chris@16 35 // };
Chris@16 36 //
Chris@16 37 // typedef karma::bool_generator<special_bool_policy> backwards_bool;
Chris@16 38 //
Chris@16 39 // karma::generate(sink, backwards_bool(), false); // will output: eurt
Chris@16 40 //
Chris@16 41 ///////////////////////////////////////////////////////////////////////////
Chris@16 42 template <typename T = bool>
Chris@16 43 struct bool_policies
Chris@16 44 {
Chris@16 45 ///////////////////////////////////////////////////////////////////////
Chris@16 46 // Expose the data type the generator is targeted at
Chris@16 47 ///////////////////////////////////////////////////////////////////////
Chris@16 48 typedef T value_type;
Chris@16 49
Chris@16 50 ///////////////////////////////////////////////////////////////////////
Chris@16 51 // By default the policy doesn't require any special iterator
Chris@16 52 // functionality. The boolean generator exposes its properties
Chris@16 53 // from here, so this needs to be updated in case other properties
Chris@16 54 // need to be implemented.
Chris@16 55 ///////////////////////////////////////////////////////////////////////
Chris@16 56 typedef mpl::int_<generator_properties::no_properties> properties;
Chris@16 57
Chris@16 58 ///////////////////////////////////////////////////////////////////////
Chris@16 59 // This is the main function used to generate the output for a
Chris@16 60 // boolean. It is called by the boolean generator in order
Chris@16 61 // to perform the conversion. In theory all of the work can be
Chris@16 62 // implemented here, but it is the easiest to use existing
Chris@16 63 // functionality provided by the type specified by the template
Chris@16 64 // parameter `Inserter`.
Chris@16 65 //
Chris@16 66 // sink: the output iterator to use for generation
Chris@16 67 // n: the floating point number to convert
Chris@16 68 // p: the instance of the policy type used to instantiate this
Chris@16 69 // floating point generator.
Chris@16 70 ///////////////////////////////////////////////////////////////////////
Chris@16 71 template <typename Inserter, typename OutputIterator, typename Policies>
Chris@16 72 static bool
Chris@16 73 call (OutputIterator& sink, T n, Policies const& p)
Chris@16 74 {
Chris@16 75 return Inserter::call_n(sink, n, p);
Chris@16 76 }
Chris@16 77
Chris@16 78 ///////////////////////////////////////////////////////////////////////
Chris@16 79 // Print the textual representations of a true boolean value
Chris@16 80 //
Chris@16 81 // sink The output iterator to use for generation
Chris@16 82 // b The boolean value to convert.
Chris@16 83 //
Chris@16 84 // The CharEncoding and Tag template parameters are either of the type
Chris@16 85 // unused_type or describes the character class and conversion to be
Chris@16 86 // applied to any output possibly influenced by either the lower[...]
Chris@16 87 // or upper[...] directives.
Chris@16 88 //
Chris@16 89 ///////////////////////////////////////////////////////////////////////
Chris@16 90 template <typename CharEncoding, typename Tag, typename OutputIterator>
Chris@16 91 static bool generate_true(OutputIterator& sink, T)
Chris@16 92 {
Chris@16 93 return string_inserter<CharEncoding, Tag>::call(sink, "true");
Chris@16 94 }
Chris@16 95
Chris@16 96 ///////////////////////////////////////////////////////////////////////
Chris@16 97 // Print the textual representations of a false boolean value
Chris@16 98 //
Chris@16 99 // sink The output iterator to use for generation
Chris@16 100 // b The boolean value to convert.
Chris@16 101 //
Chris@16 102 // The CharEncoding and Tag template parameters are either of the type
Chris@16 103 // unused_type or describes the character class and conversion to be
Chris@16 104 // applied to any output possibly influenced by either the lower[...]
Chris@16 105 // or upper[...] directives.
Chris@16 106 //
Chris@16 107 ///////////////////////////////////////////////////////////////////////
Chris@16 108 template <typename CharEncoding, typename Tag, typename OutputIterator>
Chris@16 109 static bool generate_false(OutputIterator& sink, T)
Chris@16 110 {
Chris@16 111 return string_inserter<CharEncoding, Tag>::call(sink, "false");
Chris@16 112 }
Chris@16 113 };
Chris@16 114
Chris@16 115 }}}
Chris@16 116
Chris@16 117 #endif