Chris@16: // Copyright (c) 2001-2011 Hartmut Kaiser Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. (See accompanying Chris@16: // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #if !defined(BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM) Chris@16: #define BOOST_SPIRIT_KARMA_BOOL_POLICIES_SEP_28_2009_1203PM Chris@16: Chris@16: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { namespace spirit { namespace karma Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: // Chris@16: // bool_policies, if you need special handling of your boolean output Chris@16: // just overload this policy class and use it as a template Chris@16: // parameter to the karma::bool_generator boolean generator Chris@16: // Chris@16: // struct special_bool_policy : karma::bool_policies<> Chris@16: // { Chris@16: // // we want to spell the names of false as eurt (true backwards) Chris@16: // template Chris@16: // static bool generate_false(OutputIterator& sink, bool) Chris@16: // { Chris@16: // return string_inserter::call(sink, "eurt"); Chris@16: // } Chris@16: // }; Chris@16: // Chris@16: // typedef karma::bool_generator backwards_bool; Chris@16: // Chris@16: // karma::generate(sink, backwards_bool(), false); // will output: eurt Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: struct bool_policies Chris@16: { Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Expose the data type the generator is targeted at Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: typedef T value_type; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // By default the policy doesn't require any special iterator Chris@16: // functionality. The boolean generator exposes its properties Chris@16: // from here, so this needs to be updated in case other properties Chris@16: // need to be implemented. Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: typedef mpl::int_ properties; Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // This is the main function used to generate the output for a Chris@16: // boolean. It is called by the boolean generator in order Chris@16: // to perform the conversion. In theory all of the work can be Chris@16: // implemented here, but it is the easiest to use existing Chris@16: // functionality provided by the type specified by the template Chris@16: // parameter `Inserter`. Chris@16: // Chris@16: // sink: the output iterator to use for generation Chris@16: // n: the floating point number to convert Chris@16: // p: the instance of the policy type used to instantiate this Chris@16: // floating point generator. Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: static bool Chris@16: call (OutputIterator& sink, T n, Policies const& p) Chris@16: { Chris@16: return Inserter::call_n(sink, n, p); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Print the textual representations of a true boolean value Chris@16: // Chris@16: // sink The output iterator to use for generation Chris@16: // b The boolean value to convert. Chris@16: // Chris@16: // The CharEncoding and Tag template parameters are either of the type Chris@16: // unused_type or describes the character class and conversion to be Chris@16: // applied to any output possibly influenced by either the lower[...] Chris@16: // or upper[...] directives. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: static bool generate_true(OutputIterator& sink, T) Chris@16: { Chris@16: return string_inserter::call(sink, "true"); Chris@16: } Chris@16: Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: // Print the textual representations of a false boolean value Chris@16: // Chris@16: // sink The output iterator to use for generation Chris@16: // b The boolean value to convert. Chris@16: // Chris@16: // The CharEncoding and Tag template parameters are either of the type Chris@16: // unused_type or describes the character class and conversion to be Chris@16: // applied to any output possibly influenced by either the lower[...] Chris@16: // or upper[...] directives. Chris@16: // Chris@16: /////////////////////////////////////////////////////////////////////// Chris@16: template Chris@16: static bool generate_false(OutputIterator& sink, T) Chris@16: { Chris@16: return string_inserter::call(sink, "false"); Chris@16: } Chris@16: }; Chris@16: Chris@16: }}} Chris@16: Chris@16: #endif