stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,207 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_03_2007_1424PM)
#define BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_03_2007_1424PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <iterator>
#include <string>
#include <boost/spirit/home/karma/generate.hpp>
#include <boost/spirit/home/support/iterators/ostream_iterator.hpp>
#include <boost/mpl/bool.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma { namespace detail
{
///////////////////////////////////////////////////////////////////////////
template <typename Expr
, typename CopyExpr = mpl::false_, typename CopyAttr = mpl::false_
, typename Delimiter = unused_type, typename Attribute = unused_type>
struct format_manip
{
// This assertion makes sure we don't hit the only code path which is
// not implemented (because it isn't needed), where both, the
// expression and the attribute need to be held as a copy.
BOOST_SPIRIT_ASSERT_MSG(!CopyExpr::value || !CopyAttr::value
, error_invalid_should_not_happen, ());
format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a)
: expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {}
format_manip(Expr const& xpr, Delimiter const& d
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a)
: expr(xpr), delim(d), pre(pre_delimit), attr(a) {}
Expr const& expr;
Delimiter const& delim;
BOOST_SCOPED_ENUM(delimit_flag) const pre;
Attribute const& attr;
private:
// silence MSVC warning C4512: assignment operator could not be generated
format_manip& operator= (format_manip const&);
};
template <typename Expr, typename Delimiter, typename Attribute>
struct format_manip<Expr, mpl::false_, mpl::true_, Delimiter, Attribute>
{
format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a)
: expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {}
format_manip(Expr const& xpr, Delimiter const& d
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a)
: expr(xpr), delim(d), pre(pre_delimit), attr(a) {}
Expr const& expr;
Delimiter const& delim;
BOOST_SCOPED_ENUM(delimit_flag) const pre;
Attribute attr;
private:
// silence MSVC warning C4512: assignment operator could not be generated
format_manip& operator= (format_manip const&);
};
template <typename Expr, typename Delimiter, typename Attribute>
struct format_manip<Expr, mpl::true_, mpl::false_, Delimiter, Attribute>
{
format_manip(Expr const& xpr, Delimiter const& d, Attribute const& a)
: expr(xpr), delim(d), pre(delimit_flag::dont_predelimit), attr(a) {}
format_manip(Expr const& xpr, Delimiter const& d
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit, Attribute const& a)
: expr(xpr), delim(d), pre(pre_delimit), attr(a) {}
Expr expr;
Delimiter const& delim;
BOOST_SCOPED_ENUM(delimit_flag) const pre;
Attribute const& attr;
private:
// silence MSVC warning C4512: assignment operator could not be generated
format_manip& operator= (format_manip const&);
};
///////////////////////////////////////////////////////////////////////////
template <typename Expr, typename Enable = void>
struct format
{
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (Expr) is not a valid spirit karma expression.
// Did you intend to use the auto_ facilities while forgetting to
// #include <boost/spirit/include/karma_format_auto.hpp>?
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
};
template <typename Expr>
struct format<Expr
, typename enable_if<traits::matches<karma::domain, Expr> >::type>
{
typedef format_manip<Expr> type;
static type call(Expr const& expr)
{
return type(expr, unused, unused);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename Expr, typename Delimiter, typename Enable = void>
struct format_delimited
{
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (Expr) is not a valid spirit karma expression.
// Did you intend to use the auto_ facilities while forgetting to
// #include <boost/spirit/include/karma_format_auto.hpp>?
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
};
template <typename Expr, typename Delimiter>
struct format_delimited<Expr, Delimiter
, typename enable_if<traits::matches<karma::domain, Expr> >::type>
{
typedef format_manip<Expr, mpl::false_, mpl::false_, Delimiter> type;
static type call(
Expr const& expr
, Delimiter const& delimiter
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
{
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the delimiter is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
return type(expr, delimiter, pre_delimit, unused);
}
};
///////////////////////////////////////////////////////////////////////////
template<typename Char, typename Traits, typename Expr
, typename CopyExpr, typename CopyAttr>
inline std::basic_ostream<Char, Traits> &
operator<< (std::basic_ostream<Char, Traits> &os
, format_manip<Expr, CopyExpr, CopyAttr> const& fm)
{
karma::ostream_iterator<Char, Char, Traits> sink(os);
if (!karma::generate (sink, fm.expr))
{
os.setstate(std::ios_base::failbit);
}
return os;
}
///////////////////////////////////////////////////////////////////////////
template<typename Char, typename Traits, typename Expr
, typename CopyExpr, typename CopyAttr, typename Attribute>
inline std::basic_ostream<Char, Traits> &
operator<< (std::basic_ostream<Char, Traits> &os
, format_manip<Expr, CopyExpr, CopyAttr, unused_type, Attribute> const& fm)
{
karma::ostream_iterator<Char, Char, Traits> sink(os);
if (!karma::generate(sink, fm.expr, fm.attr))
{
os.setstate(std::ios_base::failbit);
}
return os;
}
template<typename Char, typename Traits, typename Expr
, typename CopyExpr, typename CopyAttr, typename Delimiter>
inline std::basic_ostream<Char, Traits> &
operator<< (std::basic_ostream<Char, Traits> &os
, format_manip<Expr, CopyExpr, CopyAttr, Delimiter> const& fm)
{
karma::ostream_iterator<Char, Char, Traits> sink(os);
if (!karma::generate_delimited(sink, fm.expr, fm.delim, fm.pre))
{
os.setstate(std::ios_base::failbit);
}
return os;
}
///////////////////////////////////////////////////////////////////////////
template<typename Char, typename Traits, typename Expr
, typename CopyExpr, typename CopyAttr, typename Delimiter
, typename Attribute>
inline std::basic_ostream<Char, Traits> &
operator<< (std::basic_ostream<Char, Traits> &os
, format_manip<Expr, CopyExpr, CopyAttr, Delimiter, Attribute> const& fm)
{
karma::ostream_iterator<Char, Char, Traits> sink(os);
if (!karma::generate_delimited(sink, fm.expr, fm.delim, fm.pre, fm.attr))
{
os.setstate(std::ios_base::failbit);
}
return os;
}
}}}}
#endif
@@ -0,0 +1,56 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_KARMA_FORMAT_MANIP_AUTO_DEC_02_2009_1246PM)
#define BOOST_SPIRIT_KARMA_FORMAT_MANIP_AUTO_DEC_02_2009_1246PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/karma/stream/detail/format_manip.hpp>
#include <boost/spirit/home/karma/auto/create_generator.hpp>
#include <boost/utility/enable_if.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma { namespace detail
{
///////////////////////////////////////////////////////////////////////////
template <typename Expr>
struct format<Expr
, typename enable_if<traits::meta_create_exists<karma::domain, Expr> >::type>
{
typedef typename result_of::create_generator<Expr>::type expr_type;
typedef format_manip<
expr_type, mpl::true_, mpl::false_, unused_type, Expr
> type;
static type call(Expr const& expr)
{
return type(create_generator<Expr>(), unused, expr);
}
};
///////////////////////////////////////////////////////////////////////////
template <typename Expr, typename Delimiter>
struct format_delimited<Expr, Delimiter
, typename enable_if<traits::meta_create_exists<karma::domain, Expr> >::type>
{
typedef typename result_of::create_generator<Expr>::type expr_type;
typedef format_manip<
expr_type, mpl::true_, mpl::false_, Delimiter, Expr
> type;
static type call(Expr const& expr
, Delimiter const& delimiter
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit)
{
return type(create_generator<Expr>(), delimiter, pre_delimit, expr);
}
};
}}}}
#endif
@@ -0,0 +1,55 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boist.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_ITERATOR_SINK_MAY_27_2007_0133PM)
#define BOOST_SPIRIT_ITERATOR_SINK_MAY_27_2007_0133PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/iostreams/stream.hpp>
#include <boost/spirit/home/karma/detail/generate_to.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma { namespace detail
{
///////////////////////////////////////////////////////////////////////////
template <
typename OutputIterator, typename Char, typename CharEncoding
, typename Tag
>
struct iterator_sink
{
typedef boost::iostreams::sink_tag category;
typedef Char char_type;
iterator_sink (OutputIterator& sink_)
: sink(sink_)
{}
// Write up to n characters from the buffer s to the output sequence,
// returning the number of characters written
std::streamsize write (Char const* s, std::streamsize n)
{
std::streamsize bytes_written = 0;
while (n--) {
if (!generate_to(sink, *s, CharEncoding(), Tag()))
break;
++s; ++bytes_written;
}
return bytes_written;
}
OutputIterator& sink;
private:
// silence MSVC warning C4512: assignment operator could not be generated
iterator_sink& operator= (iterator_sink const&);
};
}}}}
#endif
@@ -0,0 +1,117 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_01_2007_1211PM)
#define BOOST_SPIRIT_KARMA_FORMAT_MANIP_MAY_01_2007_1211PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/karma/generate.hpp>
#include <boost/spirit/home/karma/generator.hpp>
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
#include <boost/spirit/home/karma/stream/detail/format_manip.hpp>
#include <boost/spirit/home/support/unused.hpp>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma
{
///////////////////////////////////////////////////////////////////////////
template <typename Expr>
inline typename detail::format<Expr>::type
format(Expr const& expr)
{
return detail::format<Expr>::call(expr);
}
template <typename Expr, typename Attribute>
inline detail::format_manip<Expr, mpl::false_, mpl::false_, unused_type, Attribute>
format(
Expr const& expr
, Attribute const& attr)
{
using karma::detail::format_manip;
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (expr) is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
return format_manip<Expr, mpl::false_, mpl::false_, unused_type, Attribute>(
expr, unused, attr);
}
///////////////////////////////////////////////////////////////////////////
template <typename Expr, typename Delimiter>
inline typename detail::format_delimited<Expr, Delimiter>::type
format_delimited(
Expr const& expr
, Delimiter const& d
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit =
delimit_flag::dont_predelimit)
{
return detail::format_delimited<Expr, Delimiter>::call(expr, d, pre_delimit);
}
template <typename Expr, typename Delimiter, typename Attribute>
inline detail::format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>
format_delimited(
Expr const& xpr
, Delimiter const& d
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
, Attribute const& attr)
{
using karma::detail::format_manip;
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (expr) is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
return format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>(
xpr, d, pre_delimit, attr);
}
template <typename Expr, typename Delimiter, typename Attribute>
inline detail::format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>
format_delimited(
Expr const& xpr
, Delimiter const& d
, Attribute const& attr)
{
using karma::detail::format_manip;
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (expr) is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
return format_manip<Expr, mpl::false_, mpl::false_, Delimiter, Attribute>(
xpr, d, delimit_flag::dont_predelimit, attr);
}
///////////////////////////////////////////////////////////////////////////
template<typename Char, typename Traits, typename Derived>
inline std::basic_ostream<Char, Traits> &
operator<< (std::basic_ostream<Char, Traits> &os, generator<Derived> const& g)
{
typedef traits::properties_of<
typename result_of::compile<karma::domain, Derived>::type
> properties;
typedef karma::ostream_iterator<Char, Char, Traits> outiter_type;
outiter_type target_sink(os);
karma::detail::output_iterator<outiter_type, properties> sink(target_sink);
if (!g.derived().generate(sink, unused, unused, unused))
{
os.setstate(std::ios_base::failbit);
}
return os;
}
}}}
#endif
@@ -0,0 +1,123 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_PP_IS_ITERATING)
#if !defined(BOOST_SPIRIT_KARMA_FORMAT_MANIP_ATTR_APR_24_2009_0734AM)
#define BOOST_SPIRIT_KARMA_FORMAT_MANIP_ATTR_APR_24_2009_0734AM
#include <boost/spirit/home/karma/stream/format_manip.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/preprocessor/iterate.hpp>
#include <boost/preprocessor/repetition/enum.hpp>
#include <boost/preprocessor/repetition/enum_params.hpp>
#include <boost/preprocessor/repetition/enum_binary_params.hpp>
#define BOOST_PP_FILENAME_1 \
<boost/spirit/home/karma/stream/format_manip_attr.hpp>
#define BOOST_PP_ITERATION_LIMITS (2, SPIRIT_ARGUMENTS_LIMIT)
#include BOOST_PP_ITERATE()
#endif
///////////////////////////////////////////////////////////////////////////////
//
// Preprocessor vertical repetition code
//
///////////////////////////////////////////////////////////////////////////////
#else // defined(BOOST_PP_IS_ITERATING)
#define N BOOST_PP_ITERATION()
#define BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE(z, n, A) \
BOOST_PP_CAT(A, n) const&
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma
{
///////////////////////////////////////////////////////////////////////////
template <typename Expr, BOOST_PP_ENUM_PARAMS(N, typename A)>
inline detail::format_manip<Expr, mpl::false_, mpl::true_, unused_type
, fusion::vector<
BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
> >
format(Expr const& xpr, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
{
using karma::detail::format_manip;
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (expr) is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
typedef fusion::vector<
BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
> vector_type;
vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
return format_manip<Expr, mpl::false_, mpl::true_, unused_type, vector_type>(
xpr, unused, attr);
}
///////////////////////////////////////////////////////////////////////////
template <typename Expr, typename Delimiter
, BOOST_PP_ENUM_PARAMS(N, typename A)>
inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter
, fusion::vector<
BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
> >
format_delimited(Expr const& xpr, Delimiter const& d
, BOOST_SCOPED_ENUM(delimit_flag) pre_delimit
, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
{
using karma::detail::format_manip;
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (expr) is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
typedef fusion::vector<
BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
> vector_type;
vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>(
xpr, d, pre_delimit, attr);
}
template <typename Expr, typename Delimiter
, BOOST_PP_ENUM_PARAMS(N, typename A)>
inline detail::format_manip<Expr, mpl::false_, mpl::true_, Delimiter
, fusion::vector<
BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
> >
format_delimited(Expr const& xpr, Delimiter const& d
, BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& attr))
{
using karma::detail::format_manip;
// Report invalid expression error as early as possible.
// If you got an error_invalid_expression error message here,
// then the expression (expr) is not a valid spirit karma expression.
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Expr);
BOOST_SPIRIT_ASSERT_MATCH(karma::domain, Delimiter);
typedef fusion::vector<
BOOST_PP_ENUM(N, BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE, A)
> vector_type;
vector_type attr (BOOST_PP_ENUM_PARAMS(N, attr));
return format_manip<Expr, mpl::false_, mpl::true_, Delimiter, vector_type>(
xpr, d, delimit_flag::dont_predelimit, attr);
}
}}}
#undef BOOST_SPIRIT_KARMA_ATTRIBUTE_REFERENCE
#undef N
#endif
@@ -0,0 +1,65 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_KARMA_OSTREAM_ITERATOR_MAY_26_2007_1016PM)
#define BOOST_SPIRIT_KARMA_OSTREAM_ITERATOR_MAY_26_2007_1016PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <iterator>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma
{
///////////////////////////////////////////////////////////////////////////
// We need our own implementation of an ostream_iterator just to be able
// to access the wrapped ostream, which is necessary for the
// stream_generator, where we must generate the output using the original
// ostream to retain possibly registered facets.
///////////////////////////////////////////////////////////////////////////
template <
typename T, typename Elem = char
, typename Traits = std::char_traits<Elem> >
class ostream_iterator
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
public:
typedef Elem char_type;
typedef Traits traits_type;
typedef std::basic_ostream<Elem, Traits> ostream_type;
typedef ostream_iterator<T, Elem, Traits> self_type;
ostream_iterator(ostream_type& os_, Elem const* delim_ = 0)
: os(&os_), delim(delim_) {}
self_type& operator= (T const& val)
{
*os << val;
if (0 != delim)
*os << delim;
return *this;
}
self_type& operator*() { return *this; }
self_type& operator++() { return *this; }
self_type operator++(int) { return *this; }
// expose underlying stream
ostream_type& get_ostream() { return *os; }
ostream_type const& get_ostream() const { return *os; }
// expose good bit of underlying stream object
bool good() const { return get_ostream().good(); }
protected:
ostream_type *os;
Elem const* delim;
};
}}}
#endif
@@ -0,0 +1,379 @@
// Copyright (c) 2001-2011 Hartmut Kaiser
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(BOOST_SPIRIT_KARMA_STREAM_MAY_01_2007_0310PM)
#define BOOST_SPIRIT_KARMA_STREAM_MAY_01_2007_0310PM
#if defined(_MSC_VER)
#pragma once
#endif
#include <boost/spirit/home/support/common_terminals.hpp>
#include <boost/spirit/home/support/info.hpp>
#include <boost/spirit/home/support/container.hpp>
#include <boost/spirit/home/support/detail/hold_any.hpp>
#include <boost/spirit/home/support/detail/get_encoding.hpp>
#include <boost/spirit/home/support/detail/is_spirit_tag.hpp>
#include <boost/spirit/home/karma/domain.hpp>
#include <boost/spirit/home/karma/meta_compiler.hpp>
#include <boost/spirit/home/karma/delimit_out.hpp>
#include <boost/spirit/home/karma/auxiliary/lazy.hpp>
#include <boost/spirit/home/karma/stream/detail/format_manip.hpp>
#include <boost/spirit/home/karma/stream/detail/iterator_sink.hpp>
#include <boost/spirit/home/karma/detail/get_casetag.hpp>
#include <boost/spirit/home/karma/detail/extract_from.hpp>
#include <boost/fusion/include/at.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/cons.hpp>
#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <iosfwd>
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit
{
namespace tag
{
template <typename Char = char>
struct stream_tag
{
BOOST_SPIRIT_IS_TAG()
};
}
namespace karma
{
///////////////////////////////////////////////////////////////////////
// This one is the class that the user can instantiate directly in
// order to create a customized int generator
template <typename Char = char>
struct stream_generator
: spirit::terminal<tag::stream_tag<Char> >
{};
}
///////////////////////////////////////////////////////////////////////////
// Enablers
///////////////////////////////////////////////////////////////////////////
template <>
struct use_terminal<karma::domain, tag::stream> // enables stream
: mpl::true_ {};
template <>
struct use_terminal<karma::domain, tag::wstream> // enables wstream
: mpl::true_ {};
template <typename A0>
struct use_terminal<karma::domain // enables stream(...)
, terminal_ex<tag::stream, fusion::vector1<A0> >
> : mpl::true_ {};
template <typename A0>
struct use_terminal<karma::domain // enables wstream(...)
, terminal_ex<tag::wstream, fusion::vector1<A0> >
> : mpl::true_ {};
template <> // enables stream(f)
struct use_lazy_terminal<
karma::domain, tag::stream, 1 /*arity*/
> : mpl::true_ {};
template <> // enables wstream(f)
struct use_lazy_terminal<
karma::domain, tag::wstream, 1 /*arity*/
> : mpl::true_ {};
// enables stream_generator<char_type>
template <typename Char>
struct use_terminal<karma::domain, tag::stream_tag<Char> >
: mpl::true_ {};
template <typename Char, typename A0>
struct use_terminal<karma::domain
, terminal_ex<tag::stream_tag<Char>, fusion::vector1<A0> >
> : mpl::true_ {};
template <typename Char>
struct use_lazy_terminal<
karma::domain, tag::stream_tag<Char>, 1 /*arity*/
> : mpl::true_ {};
}}
///////////////////////////////////////////////////////////////////////////////
namespace boost { namespace spirit { namespace karma
{
#ifndef BOOST_SPIRIT_NO_PREDEFINED_TERMINALS
using spirit::stream;
using spirit::wstream;
#endif
using spirit::stream_type;
using spirit::wstream_type;
///////////////////////////////////////////////////////////////////////////
template <typename Char, typename CharEncoding, typename Tag>
struct any_stream_generator
: primitive_generator<any_stream_generator<Char, CharEncoding, Tag> >
{
template <typename Context, typename Unused = unused_type>
struct attribute
{
typedef spirit::basic_hold_any<Char> type;
};
// any_stream_generator has an attached attribute
template <
typename OutputIterator, typename Context, typename Delimiter
, typename Attribute
>
static bool generate(OutputIterator& sink, Context& context
, Delimiter const& d, Attribute const& attr)
{
typedef karma::detail::iterator_sink<
OutputIterator, Char, CharEncoding, Tag
> sink_device;
if (!traits::has_optional_value(attr))
return false;
// use existing operator<<()
typedef typename attribute<Context>::type attribute_type;
{
boost::iostreams::stream<sink_device> ostr(sink);
ostr << traits::extract_from<attribute_type>(attr, context) << std::flush;
if (!ostr.good())
return false;
}
return karma::delimit_out(sink, d); // always do post-delimiting
}
// this is a special overload to detect if the output iterator has been
// generated by a format_manip object.
template <
typename T, typename Traits, typename Properties, typename Context
, typename Delimiter, typename Attribute
>
static bool generate(
karma::detail::output_iterator<
karma::ostream_iterator<T, Char, Traits>, Properties
>& sink, Context& context, Delimiter const& d
, Attribute const& attr)
{
typedef karma::detail::output_iterator<
karma::ostream_iterator<T, Char, Traits>, Properties
> output_iterator;
typedef karma::detail::iterator_sink<
output_iterator, Char, CharEncoding, Tag
> sink_device;
if (!traits::has_optional_value(attr))
return false;
// use existing operator<<()
typedef typename attribute<Context>::type attribute_type;
{
boost::iostreams::stream<sink_device> ostr(sink);
ostr.imbue(sink.get_ostream().getloc());
ostr << traits::extract_from<attribute_type>(attr, context)
<< std::flush;
if (!ostr.good())
return false;
}
return karma::delimit_out(sink, d); // always do post-delimiting
}
// this any_stream has no parameter attached, it needs to have been
// initialized from a value/variable
template <typename OutputIterator, typename Context
, typename Delimiter>
static bool
generate(OutputIterator&, Context&, Delimiter const&, unused_type)
{
// It is not possible (doesn't make sense) to use stream generators
// without providing any attribute, as the generator doesn't 'know'
// what to output. The following assertion fires if this situation
// is detected in your code.
BOOST_SPIRIT_ASSERT_FAIL(OutputIterator, stream_not_usable_without_attribute, ());
return false;
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("stream");
}
};
template <typename T, typename Char, typename CharEncoding, typename Tag>
struct lit_stream_generator
: primitive_generator<lit_stream_generator<T, Char, CharEncoding, Tag> >
{
template <typename Context, typename Unused>
struct attribute
{
typedef unused_type type;
};
lit_stream_generator(typename add_reference<T>::type t)
: t_(t)
{}
// lit_stream_generator has an attached parameter
// this overload will be used in the normal case (not called from
// format_manip).
template <
typename OutputIterator, typename Context, typename Delimiter
, typename Attribute>
bool generate(OutputIterator& sink, Context&, Delimiter const& d
, Attribute const&) const
{
typedef karma::detail::iterator_sink<
OutputIterator, Char, CharEncoding, Tag
> sink_device;
boost::iostreams::stream<sink_device> ostr(sink);
ostr << t_ << std::flush; // use existing operator<<()
if (ostr.good())
return karma::delimit_out(sink, d); // always do post-delimiting
return false;
}
// this is a special overload to detect if the output iterator has been
// generated by a format_manip object.
template <
typename T1, typename Traits, typename Properties
, typename Context, typename Delimiter, typename Attribute>
bool generate(
karma::detail::output_iterator<
karma::ostream_iterator<T1, Char, Traits>, Properties
>& sink, Context&, Delimiter const& d, Attribute const&) const
{
typedef karma::detail::output_iterator<
karma::ostream_iterator<T1, Char, Traits>, Properties
> output_iterator;
typedef karma::detail::iterator_sink<
output_iterator, Char, CharEncoding, Tag
> sink_device;
{
boost::iostreams::stream<sink_device> ostr(sink);
ostr.imbue(sink.get_ostream().getloc());
ostr << t_ << std::flush; // use existing operator<<()
if (!ostr.good())
return false;
}
return karma::delimit_out(sink, d); // always do post-delimiting
}
template <typename Context>
info what(Context& /*context*/) const
{
return info("any-stream");
}
T t_;
private:
// silence MSVC warning C4512: assignment operator could not be generated
lit_stream_generator& operator= (lit_stream_generator const&);
};
///////////////////////////////////////////////////////////////////////////
// Generator generators: make_xxx function (objects)
///////////////////////////////////////////////////////////////////////////
template <typename Char, typename Modifiers>
struct make_stream
{
static bool const lower =
has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
static bool const upper =
has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
typedef any_stream_generator<
Char
, typename spirit::detail::get_encoding_with_case<
Modifiers, unused_type, lower || upper>::type
, typename detail::get_casetag<Modifiers, lower || upper>::type
> result_type;
result_type operator()(unused_type, unused_type) const
{
return result_type();
}
};
// stream
template <typename Modifiers>
struct make_primitive<tag::stream, Modifiers>
: make_stream<char, Modifiers> {};
// wstream
template <typename Modifiers>
struct make_primitive<tag::wstream, Modifiers>
: make_stream<wchar_t, Modifiers> {};
// any_stream_generator<char_type>
template <typename Char, typename Modifiers>
struct make_primitive<tag::stream_tag<Char>, Modifiers>
: make_stream<Char, Modifiers> {};
///////////////////////////////////////////////////////////////////////////
template <typename Char, typename A0, typename Modifiers>
struct make_any_stream
{
static bool const lower =
has_modifier<Modifiers, tag::char_code_base<tag::lower> >::value;
static bool const upper =
has_modifier<Modifiers, tag::char_code_base<tag::upper> >::value;
typedef typename add_const<A0>::type const_attribute;
typedef lit_stream_generator<
const_attribute, Char
, typename spirit::detail::get_encoding_with_case<
Modifiers, unused_type, lower || upper>::type
, typename detail::get_casetag<Modifiers, lower || upper>::type
> result_type;
template <typename Terminal>
result_type operator()(Terminal const& term, unused_type) const
{
return result_type(fusion::at_c<0>(term.args));
}
};
// stream(...)
template <typename Modifiers, typename A0>
struct make_primitive<
terminal_ex<tag::stream, fusion::vector1<A0> >, Modifiers>
: make_any_stream<char, A0, Modifiers> {};
// wstream(...)
template <typename Modifiers, typename A0>
struct make_primitive<
terminal_ex<tag::wstream, fusion::vector1<A0> >, Modifiers>
: make_any_stream<wchar_t, A0, Modifiers> {};
// any_stream_generator<char_type>(...)
template <typename Char, typename Modifiers, typename A0>
struct make_primitive<
terminal_ex<tag::stream_tag<Char>, fusion::vector1<A0> >
, Modifiers>
: make_any_stream<Char, A0, Modifiers> {};
}}}
#endif