|
||||
File indexing completed on 2025-01-19 09:47:38
0001 // Copyright (c) 2001-2011 Hartmut Kaiser 0002 // 0003 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0004 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0005 0006 #if !defined(BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM) 0007 #define BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM 0008 0009 #if defined(_MSC_VER) 0010 #pragma once 0011 #endif 0012 0013 #include <boost/spirit/home/support/char_class.hpp> 0014 #include <boost/spirit/home/karma/generator.hpp> 0015 #include <boost/spirit/home/karma/char.hpp> 0016 #include <boost/spirit/home/karma/numeric/detail/numeric_utils.hpp> 0017 0018 namespace boost { namespace spirit { namespace karma 0019 { 0020 /////////////////////////////////////////////////////////////////////////// 0021 // 0022 // bool_policies, if you need special handling of your boolean output 0023 // just overload this policy class and use it as a template 0024 // parameter to the karma::bool_generator boolean generator 0025 // 0026 // struct special_bool_policy : karma::bool_policies<> 0027 // { 0028 // // we want to spell the names of false as eurt (true backwards) 0029 // template <typename CharEncoding, typename Tag 0030 // , typename OutputIterator> 0031 // static bool generate_false(OutputIterator& sink, bool) 0032 // { 0033 // return string_inserter<CharEncoding, Tag>::call(sink, "eurt"); 0034 // } 0035 // }; 0036 // 0037 // typedef karma::bool_generator<special_bool_policy> backwards_bool; 0038 // 0039 // karma::generate(sink, backwards_bool(), false); // will output: eurt 0040 // 0041 /////////////////////////////////////////////////////////////////////////// 0042 template <typename T = bool> 0043 struct bool_policies 0044 { 0045 /////////////////////////////////////////////////////////////////////// 0046 // Expose the data type the generator is targeted at 0047 /////////////////////////////////////////////////////////////////////// 0048 typedef T value_type; 0049 0050 /////////////////////////////////////////////////////////////////////// 0051 // By default the policy doesn't require any special iterator 0052 // functionality. The boolean generator exposes its properties 0053 // from here, so this needs to be updated in case other properties 0054 // need to be implemented. 0055 /////////////////////////////////////////////////////////////////////// 0056 typedef mpl::int_<generator_properties::no_properties> properties; 0057 0058 /////////////////////////////////////////////////////////////////////// 0059 // This is the main function used to generate the output for a 0060 // boolean. It is called by the boolean generator in order 0061 // to perform the conversion. In theory all of the work can be 0062 // implemented here, but it is the easiest to use existing 0063 // functionality provided by the type specified by the template 0064 // parameter `Inserter`. 0065 // 0066 // sink: the output iterator to use for generation 0067 // n: the floating point number to convert 0068 // p: the instance of the policy type used to instantiate this 0069 // floating point generator. 0070 /////////////////////////////////////////////////////////////////////// 0071 template <typename Inserter, typename OutputIterator, typename Policies> 0072 static bool 0073 call (OutputIterator& sink, T n, Policies const& p) 0074 { 0075 return Inserter::call_n(sink, n, p); 0076 } 0077 0078 /////////////////////////////////////////////////////////////////////// 0079 // Print the textual representations of a true boolean value 0080 // 0081 // sink The output iterator to use for generation 0082 // b The boolean value to convert. 0083 // 0084 // The CharEncoding and Tag template parameters are either of the type 0085 // unused_type or describes the character class and conversion to be 0086 // applied to any output possibly influenced by either the lower[...] 0087 // or upper[...] directives. 0088 // 0089 /////////////////////////////////////////////////////////////////////// 0090 template <typename CharEncoding, typename Tag, typename OutputIterator> 0091 static bool generate_true(OutputIterator& sink, T) 0092 { 0093 return string_inserter<CharEncoding, Tag>::call(sink, "true"); 0094 } 0095 0096 /////////////////////////////////////////////////////////////////////// 0097 // Print the textual representations of a false boolean value 0098 // 0099 // sink The output iterator to use for generation 0100 // b The boolean value to convert. 0101 // 0102 // The CharEncoding and Tag template parameters are either of the type 0103 // unused_type or describes the character class and conversion to be 0104 // applied to any output possibly influenced by either the lower[...] 0105 // or upper[...] directives. 0106 // 0107 /////////////////////////////////////////////////////////////////////// 0108 template <typename CharEncoding, typename Tag, typename OutputIterator> 0109 static bool generate_false(OutputIterator& sink, T) 0110 { 0111 return string_inserter<CharEncoding, Tag>::call(sink, "false"); 0112 } 0113 }; 0114 0115 }}} 0116 0117 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |