mirror of
https://github.com/vdemydiuk/mtapi.git
synced 2026-08-23 15:48:10 +00:00
Added thirdparty: boost library
This commit is contained in:
+209
@@ -0,0 +1,209 @@
|
||||
// Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
//
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SPIRIT_KARMA_OPERATOR_ALTERNATIVE_HPP
|
||||
#define BOOST_SPIRIT_KARMA_OPERATOR_ALTERNATIVE_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/detail/alternative_function.hpp>
|
||||
#include <boost/spirit/home/karma/detail/get_stricttag.hpp>
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/has_semantic_action.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/spirit/home/support/detail/what_function.hpp>
|
||||
#include <boost/fusion/include/any.hpp>
|
||||
#include <boost/fusion/include/mpl.hpp>
|
||||
#include <boost/fusion/include/for_each.hpp>
|
||||
#include <boost/mpl/accumulate.hpp>
|
||||
#include <boost/mpl/bitor.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::bitwise_or> // enables |
|
||||
: mpl::true_ {};
|
||||
|
||||
template <>
|
||||
struct flatten_tree<karma::domain, proto::tag::bitwise_or> // flattens |
|
||||
: mpl::true_ {};
|
||||
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
// specialization for sequences
|
||||
template <typename Elements>
|
||||
struct alternative_properties
|
||||
{
|
||||
struct element_properties
|
||||
{
|
||||
template <typename T>
|
||||
struct result;
|
||||
|
||||
template <typename F, typename Element>
|
||||
struct result<F(Element)>
|
||||
{
|
||||
typedef properties_of<Element> type;
|
||||
};
|
||||
|
||||
// never called, but needed for decltype-based result_of (C++0x)
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template <typename Element>
|
||||
typename result<element_properties(Element)>::type
|
||||
operator()(Element&&) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef typename mpl::accumulate<
|
||||
typename fusion::result_of::transform<
|
||||
Elements, element_properties>::type
|
||||
, mpl::int_<karma::generator_properties::countingbuffer>
|
||||
, mpl::bitor_<mpl::_2, mpl::_1>
|
||||
>::type type;
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Elements, typename Strict, typename Derived>
|
||||
struct base_alternative : nary_generator<Derived>
|
||||
{
|
||||
typedef typename traits::alternative_properties<Elements>::type
|
||||
properties;
|
||||
|
||||
template <typename Context, typename Iterator = unused_type>
|
||||
struct attribute
|
||||
{
|
||||
// Put all the element attributes in a tuple
|
||||
typedef typename traits::build_attribute_sequence<
|
||||
Elements, Context, traits::alternative_attribute_transform
|
||||
, Iterator, karma::domain
|
||||
>::type all_attributes;
|
||||
|
||||
// Ok, now make a variant over the attribute sequence. Note that
|
||||
// build_variant makes sure that 1) all attributes in the variant
|
||||
// are unique 2) puts the unused attribute, if there is any, to
|
||||
// the front and 3) collapses single element variants, variant<T>
|
||||
// to T.
|
||||
typedef typename traits::build_variant<all_attributes>::type type;
|
||||
};
|
||||
|
||||
base_alternative(Elements const& elements)
|
||||
: elements(elements) {}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute const& attr) const
|
||||
{
|
||||
typedef detail::alternative_generate_function<
|
||||
OutputIterator, Context, Delimiter, Attribute, Strict
|
||||
> functor;
|
||||
|
||||
// f return true if *any* of the parser succeeds
|
||||
functor f (sink, ctx, d, attr);
|
||||
return fusion::any(elements, f);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
info result("alternative");
|
||||
fusion::for_each(elements,
|
||||
spirit::detail::what_function<Context>(result, context));
|
||||
return result;
|
||||
}
|
||||
|
||||
Elements elements;
|
||||
};
|
||||
|
||||
template <typename Elements>
|
||||
struct alternative
|
||||
: base_alternative<Elements, mpl::false_, alternative<Elements> >
|
||||
{
|
||||
typedef base_alternative<Elements, mpl::false_, alternative>
|
||||
base_alternative_;
|
||||
|
||||
alternative(Elements const& elements)
|
||||
: base_alternative_(elements) {}
|
||||
};
|
||||
|
||||
template <typename Elements>
|
||||
struct strict_alternative
|
||||
: base_alternative<Elements, mpl::true_, strict_alternative<Elements> >
|
||||
{
|
||||
typedef base_alternative<Elements, mpl::true_, strict_alternative>
|
||||
base_alternative_;
|
||||
|
||||
strict_alternative(Elements const& elements)
|
||||
: base_alternative_(elements) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace detail
|
||||
{
|
||||
template <typename Elements, bool strict_mode = false>
|
||||
struct make_alternative
|
||||
: make_nary_composite<Elements, alternative>
|
||||
{};
|
||||
|
||||
template <typename Elements>
|
||||
struct make_alternative<Elements, true>
|
||||
: make_nary_composite<Elements, strict_alternative>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Elements, typename Modifiers>
|
||||
struct make_composite<proto::tag::bitwise_or, Elements, Modifiers>
|
||||
: detail::make_alternative<Elements
|
||||
, detail::get_stricttag<Modifiers>::value>
|
||||
{};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements>
|
||||
struct has_semantic_action<karma::alternative<Elements> >
|
||||
: nary_has_semantic_action<Elements> {};
|
||||
|
||||
template <typename Elements>
|
||||
struct has_semantic_action<karma::strict_alternative<Elements> >
|
||||
: nary_has_semantic_action<Elements> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::alternative<Elements>
|
||||
, Attribute, Context, Iterator>
|
||||
: nary_handles_container<Elements, Attribute, Context, Iterator> {};
|
||||
|
||||
template <typename Elements, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::strict_alternative<Elements>
|
||||
, Attribute, Context, Iterator>
|
||||
: nary_handles_container<Elements, Attribute, Context, Iterator> {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
// Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
//
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SPIRIT_KARMA_OPERATOR_AND_PREDICATE_HPP
|
||||
#define BOOST_SPIRIT_KARMA_OPERATOR_AND_PREDICATE_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/has_semantic_action.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::address_of> // enables &g
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Subject>
|
||||
struct and_predicate : unary_generator<and_predicate<Subject> >
|
||||
{
|
||||
typedef Subject subject_type;
|
||||
typedef mpl::int_<
|
||||
generator_properties::disabling | subject_type::properties::value
|
||||
> properties;
|
||||
|
||||
template <typename Context, typename Iterator>
|
||||
struct attribute
|
||||
: traits::attribute_of<subject_type, Context, Iterator>
|
||||
{};
|
||||
|
||||
and_predicate(Subject const& subject)
|
||||
: subject(subject) {}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
|
||||
, Attribute const& attr) const
|
||||
{
|
||||
// inhibits output
|
||||
detail::disable_output<OutputIterator> disable(sink);
|
||||
return subject.generate(sink, ctx, d, attr);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
return info("and-predicate", subject.what(context));
|
||||
}
|
||||
|
||||
Subject subject;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements, typename Modifiers>
|
||||
struct make_composite<proto::tag::address_of, Elements, Modifiers>
|
||||
: make_unary_composite<Elements, and_predicate> {};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::and_predicate<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::and_predicate<Subject>, Attribute
|
||||
, Context, Iterator>
|
||||
: unary_handles_container<Subject, Attribute, Context, Iterator> {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+209
@@ -0,0 +1,209 @@
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
// 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_KLEENE_MAR_03_2007_0337AM)
|
||||
#define BOOST_SPIRIT_KARMA_KLEENE_MAR_03_2007_0337AM
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/indirect_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/get_stricttag.hpp>
|
||||
#include <boost/spirit/home/karma/detail/pass_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/fail_function.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/container.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
#include <boost/type_traits/add_const.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::dereference> // enables *g
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Subject, typename Strict, typename Derived>
|
||||
struct base_kleene : unary_generator<Derived>
|
||||
{
|
||||
private:
|
||||
// Ignore return value in relaxed mode (failing subject generators
|
||||
// are just skipped). This allows to selectively generate items in
|
||||
// the provided attribute.
|
||||
template <typename F, typename Attribute>
|
||||
bool generate_subject(F f, Attribute const&, mpl::false_) const
|
||||
{
|
||||
bool r = !f(subject);
|
||||
if (!r && !f.is_at_end())
|
||||
f.next();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename F, typename Attribute>
|
||||
bool generate_subject(F f, Attribute const&, mpl::true_) const
|
||||
{
|
||||
return !f(subject);
|
||||
}
|
||||
|
||||
// There is no way to distinguish a failed generator from a
|
||||
// generator to be skipped. We assume the user takes responsibility
|
||||
// for ending the loop if no attribute is specified.
|
||||
template <typename F>
|
||||
bool generate_subject(F f, unused_type, mpl::false_) const
|
||||
{
|
||||
return !f(subject);
|
||||
}
|
||||
|
||||
// template <typename F>
|
||||
// bool generate_subject(F f, unused_type, mpl::true_) const
|
||||
// {
|
||||
// return !f(subject);
|
||||
// }
|
||||
|
||||
public:
|
||||
typedef Subject subject_type;
|
||||
typedef typename subject_type::properties properties;
|
||||
|
||||
// Build a std::vector from the subject's attribute. Note
|
||||
// that build_std_vector may return unused_type if the
|
||||
// subject's attribute is an unused_type.
|
||||
template <typename Context, typename Iterator>
|
||||
struct attribute
|
||||
: traits::build_std_vector<
|
||||
typename traits::attribute_of<Subject, Context, Iterator>::type
|
||||
>
|
||||
{};
|
||||
|
||||
base_kleene(Subject const& subject)
|
||||
: subject(subject) {}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute const& attr) const
|
||||
{
|
||||
typedef detail::fail_function<
|
||||
OutputIterator, Context, Delimiter> fail_function;
|
||||
|
||||
typedef typename traits::container_iterator<
|
||||
typename add_const<Attribute>::type
|
||||
>::type iterator_type;
|
||||
|
||||
typedef
|
||||
typename traits::make_indirect_iterator<iterator_type>::type
|
||||
indirect_iterator_type;
|
||||
typedef detail::pass_container<
|
||||
fail_function, Attribute, indirect_iterator_type, mpl::false_>
|
||||
pass_container;
|
||||
|
||||
iterator_type it = traits::begin(attr);
|
||||
iterator_type end = traits::end(attr);
|
||||
|
||||
pass_container pass(fail_function(sink, ctx, d),
|
||||
indirect_iterator_type(it), indirect_iterator_type(end));
|
||||
|
||||
// kleene fails only if the underlying output fails
|
||||
while (!pass.is_at_end())
|
||||
{
|
||||
if (!generate_subject(pass, attr, Strict()))
|
||||
break;
|
||||
}
|
||||
return detail::sink_is_good(sink);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
return info("kleene", subject.what(context));
|
||||
}
|
||||
|
||||
Subject subject;
|
||||
};
|
||||
|
||||
template <typename Subject>
|
||||
struct kleene
|
||||
: base_kleene<Subject, mpl::false_, kleene<Subject> >
|
||||
{
|
||||
typedef base_kleene<Subject, mpl::false_, kleene> base_kleene_;
|
||||
|
||||
kleene(Subject const& subject)
|
||||
: base_kleene_(subject) {}
|
||||
};
|
||||
|
||||
template <typename Subject>
|
||||
struct strict_kleene
|
||||
: base_kleene<Subject, mpl::true_, strict_kleene<Subject> >
|
||||
{
|
||||
typedef base_kleene<Subject, mpl::true_, strict_kleene> base_kleene_;
|
||||
|
||||
strict_kleene(Subject const& subject)
|
||||
: base_kleene_(subject) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace detail
|
||||
{
|
||||
template <typename Subject, bool strict_mode = false>
|
||||
struct make_kleene
|
||||
: make_unary_composite<Subject, kleene>
|
||||
{};
|
||||
|
||||
template <typename Subject>
|
||||
struct make_kleene<Subject, true>
|
||||
: make_unary_composite<Subject, strict_kleene>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Subject, typename Modifiers>
|
||||
struct make_composite<proto::tag::dereference, Subject, Modifiers>
|
||||
: detail::make_kleene<Subject, detail::get_stricttag<Modifiers>::value>
|
||||
{};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::kleene<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::strict_kleene<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::kleene<Subject>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::strict_kleene<Subject>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+231
@@ -0,0 +1,231 @@
|
||||
// Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
//
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SPIRIT_KARMA_OPERATOR_LIST_HPP
|
||||
#define BOOST_SPIRIT_KARMA_OPERATOR_LIST_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/indirect_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/get_stricttag.hpp>
|
||||
#include <boost/spirit/home/karma/detail/pass_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/fail_function.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/container.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::modulus> // enables g % d
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Left, typename Right, typename Strict, typename Derived>
|
||||
struct base_list : binary_generator<Derived>
|
||||
{
|
||||
private:
|
||||
// iterate over the given container until its exhausted or the embedded
|
||||
// (left) generator succeeds
|
||||
template <typename F, typename Attribute>
|
||||
bool generate_left(F f, Attribute const&, mpl::false_) const
|
||||
{
|
||||
// Failing subject generators are just skipped. This allows to
|
||||
// selectively generate items in the provided attribute.
|
||||
while (!f.is_at_end())
|
||||
{
|
||||
bool r = !f(left);
|
||||
if (r)
|
||||
return true;
|
||||
if (!f.is_at_end())
|
||||
f.next();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename F, typename Attribute>
|
||||
bool generate_left(F f, Attribute const&, mpl::true_) const
|
||||
{
|
||||
return !f(left);
|
||||
}
|
||||
|
||||
// There is no way to distinguish a failed generator from a
|
||||
// generator to be skipped. We assume the user takes responsibility
|
||||
// for ending the loop if no attribute is specified.
|
||||
template <typename F>
|
||||
bool generate_left(F f, unused_type, mpl::false_) const
|
||||
{
|
||||
return !f(left);
|
||||
}
|
||||
|
||||
public:
|
||||
typedef Left left_type;
|
||||
typedef Right right_type;
|
||||
|
||||
typedef mpl::int_<
|
||||
left_type::properties::value
|
||||
| right_type::properties::value
|
||||
| generator_properties::buffering
|
||||
| generator_properties::counting
|
||||
> properties;
|
||||
|
||||
// Build a std::vector from the LHS's attribute. Note
|
||||
// that build_std_vector may return unused_type if the
|
||||
// subject's attribute is an unused_type.
|
||||
template <typename Context, typename Iterator>
|
||||
struct attribute
|
||||
: traits::build_std_vector<
|
||||
typename traits::attribute_of<Left, Context, Iterator>::type>
|
||||
{};
|
||||
|
||||
base_list(Left const& left, Right const& right)
|
||||
: left(left), right(right)
|
||||
{}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute const& attr) const
|
||||
{
|
||||
typedef detail::fail_function<
|
||||
OutputIterator, Context, Delimiter
|
||||
> fail_function;
|
||||
|
||||
typedef typename traits::container_iterator<
|
||||
typename add_const<Attribute>::type
|
||||
>::type iterator_type;
|
||||
|
||||
typedef
|
||||
typename traits::make_indirect_iterator<iterator_type>::type
|
||||
indirect_iterator_type;
|
||||
typedef detail::pass_container<
|
||||
fail_function, Attribute, indirect_iterator_type, mpl::false_>
|
||||
pass_container;
|
||||
|
||||
iterator_type it = traits::begin(attr);
|
||||
iterator_type end = traits::end(attr);
|
||||
|
||||
pass_container pass(fail_function(sink, ctx, d),
|
||||
indirect_iterator_type(it), indirect_iterator_type(end));
|
||||
|
||||
if (generate_left(pass, attr, Strict()))
|
||||
{
|
||||
while (!pass.is_at_end())
|
||||
{
|
||||
// wrap the given output iterator as generate_left might fail
|
||||
detail::enable_buffering<OutputIterator> buffering(sink);
|
||||
{
|
||||
detail::disable_counting<OutputIterator> nocounting(sink);
|
||||
|
||||
if (!right.generate(sink, ctx, d, unused))
|
||||
return false; // shouldn't happen
|
||||
|
||||
if (!generate_left(pass, attr, Strict()))
|
||||
break; // return true as one item succeeded
|
||||
}
|
||||
buffering.buffer_copy();
|
||||
}
|
||||
return detail::sink_is_good(sink);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
return info("list",
|
||||
std::make_pair(left.what(context), right.what(context)));
|
||||
}
|
||||
|
||||
Left left;
|
||||
Right right;
|
||||
};
|
||||
|
||||
template <typename Left, typename Right>
|
||||
struct list
|
||||
: base_list<Left, Right, mpl::false_, list<Left, Right> >
|
||||
{
|
||||
typedef base_list<Left, Right, mpl::false_, list> base_list_;
|
||||
|
||||
list(Left const& left, Right const& right)
|
||||
: base_list_(left, right) {}
|
||||
};
|
||||
|
||||
template <typename Left, typename Right>
|
||||
struct strict_list
|
||||
: base_list<Left, Right, mpl::true_, strict_list<Left, Right> >
|
||||
{
|
||||
typedef base_list<Left, Right, mpl::true_, strict_list> base_list_;
|
||||
|
||||
strict_list (Left const& left, Right const& right)
|
||||
: base_list_(left, right) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace detail
|
||||
{
|
||||
template <typename Subject, bool strict_mode = false>
|
||||
struct make_list
|
||||
: make_binary_composite<Subject, list>
|
||||
{};
|
||||
|
||||
template <typename Subject>
|
||||
struct make_list<Subject, true>
|
||||
: make_binary_composite<Subject, strict_list>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Subject, typename Modifiers>
|
||||
struct make_composite<proto::tag::modulus, Subject, Modifiers>
|
||||
: detail::make_list<Subject, detail::get_stricttag<Modifiers>::value>
|
||||
{};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Left, typename Right>
|
||||
struct has_semantic_action<karma::list<Left, Right> >
|
||||
: binary_has_semantic_action<Left, Right> {};
|
||||
|
||||
template <typename Left, typename Right>
|
||||
struct has_semantic_action<karma::strict_list<Left, Right> >
|
||||
: binary_has_semantic_action<Left, Right> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Left, typename Right, typename Attribute
|
||||
, typename Context, typename Iterator>
|
||||
struct handles_container<karma::list<Left, Right>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
|
||||
template <typename Left, typename Right, typename Attribute
|
||||
, typename Context, typename Iterator>
|
||||
struct handles_container<karma::strict_list<Left, Right>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
// Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
//
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SPIRIT_KARMA_OPERATOR_NOT_PREDICATE_HPP
|
||||
#define BOOST_SPIRIT_KARMA_OPERATOR_NOT_PREDICATE_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/has_semantic_action.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::logical_not> // enables !g
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Subject>
|
||||
struct not_predicate : unary_generator<not_predicate<Subject> >
|
||||
{
|
||||
typedef Subject subject_type;
|
||||
|
||||
typedef mpl::int_<
|
||||
generator_properties::disabling | subject_type::properties::value
|
||||
> properties;
|
||||
|
||||
template <typename Context, typename Iterator>
|
||||
struct attribute
|
||||
: traits::attribute_of<subject_type, Context, Iterator>
|
||||
{};
|
||||
|
||||
not_predicate(Subject const& subject)
|
||||
: subject(subject) {}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
|
||||
, Attribute const& attr) const
|
||||
{
|
||||
// inhibits output
|
||||
detail::disable_output<OutputIterator> disable(sink);
|
||||
return !subject.generate(sink, ctx, d, attr);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
return info("not-predicate", subject.what(context));
|
||||
}
|
||||
|
||||
Subject subject;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements, typename Modifiers>
|
||||
struct make_composite<proto::tag::logical_not, Elements, Modifiers>
|
||||
: make_unary_composite<Elements, not_predicate> {};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::not_predicate<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::not_predicate<Subject>, Attribute
|
||||
, Context, Iterator>
|
||||
: unary_handles_container<Subject, Attribute, Context, Iterator> {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SPIRIT_KARMA_OPERATOR_OPTIONAL_HPP
|
||||
#define BOOST_SPIRIT_KARMA_OPERATOR_OPTIONAL_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/spirit/home/support/container.hpp>
|
||||
#include <boost/spirit/home/support/has_semantic_action.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::negate> // enables -g
|
||||
: mpl::true_ {};
|
||||
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject>
|
||||
struct optional : unary_generator<optional<Subject> >
|
||||
{
|
||||
typedef Subject subject_type;
|
||||
typedef typename subject_type::properties properties;
|
||||
|
||||
// Build a boost::optional from the subject's attribute. Note
|
||||
// that boost::optional may return unused_type if the
|
||||
// subject's attribute is an unused_type.
|
||||
template <typename Context, typename Iterator = unused_type>
|
||||
struct attribute
|
||||
: traits::build_optional<
|
||||
typename traits::attribute_of<Subject, Context, Iterator>::type
|
||||
>
|
||||
{};
|
||||
|
||||
optional(Subject const& subject)
|
||||
: subject(subject) {}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute const& attr) const
|
||||
{
|
||||
if (traits::has_optional_value(attr))
|
||||
subject.generate(sink, ctx, d, traits::optional_value(attr));
|
||||
return sink_is_good(sink);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
return info("optional", subject.what(context));
|
||||
}
|
||||
|
||||
Subject subject;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements, typename Modifiers>
|
||||
struct make_composite<proto::tag::negate, Elements, Modifiers>
|
||||
: make_unary_composite<Elements, optional> {};
|
||||
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::optional<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::optional<Subject>, Attribute, Context
|
||||
, Iterator>
|
||||
: mpl::true_ {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+227
@@ -0,0 +1,227 @@
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
// 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_POSITIVE_MAR_03_2007_0945PM)
|
||||
#define BOOST_SPIRIT_KARMA_POSITIVE_MAR_03_2007_0945PM
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/karma/detail/indirect_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/output_iterator.hpp>
|
||||
#include <boost/spirit/home/karma/detail/get_stricttag.hpp>
|
||||
#include <boost/spirit/home/karma/detail/pass_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/fail_function.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/container.hpp>
|
||||
#include <boost/spirit/home/support/has_semantic_action.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
#include <boost/type_traits/add_const.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::unary_plus> // enables +g
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Subject, typename Strict, typename Derived>
|
||||
struct base_plus : unary_generator<Derived>
|
||||
{
|
||||
private:
|
||||
// Ignore return value in relaxed mode (failing subject generators
|
||||
// are just skipped). This allows to selectively generate items in
|
||||
// the provided attribute.
|
||||
template <typename F, typename Attribute>
|
||||
bool generate_subject(F f, Attribute const&, bool& result, mpl::false_) const
|
||||
{
|
||||
bool r = !f(subject);
|
||||
if (r)
|
||||
result = true;
|
||||
else if (!f.is_at_end())
|
||||
f.next();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename F, typename Attribute>
|
||||
bool generate_subject(F f, Attribute const&, bool& result, mpl::true_) const
|
||||
{
|
||||
bool r = !f(subject);
|
||||
if (r)
|
||||
result = true;
|
||||
return r;
|
||||
}
|
||||
|
||||
// There is no way to distinguish a failed generator from a
|
||||
// generator to be skipped. We assume the user takes responsibility
|
||||
// for ending the loop if no attribute is specified.
|
||||
template <typename F>
|
||||
bool generate_subject(F f, unused_type, bool& result, mpl::false_) const
|
||||
{
|
||||
bool r = f(subject);
|
||||
if (!r)
|
||||
result = true;
|
||||
return !r;
|
||||
}
|
||||
|
||||
// template <typename F>
|
||||
// bool generate_subject(F f, unused_type, bool& result, mpl::true_) const
|
||||
// {
|
||||
// bool r = f(subject);
|
||||
// if (!r)
|
||||
// result = true;
|
||||
// return !r;
|
||||
// }
|
||||
|
||||
public:
|
||||
typedef Subject subject_type;
|
||||
typedef typename subject_type::properties properties;
|
||||
|
||||
// Build a std::vector from the subjects attribute. Note
|
||||
// that build_std_vector may return unused_type if the
|
||||
// subject's attribute is an unused_type.
|
||||
template <typename Context, typename Iterator>
|
||||
struct attribute
|
||||
: traits::build_std_vector<
|
||||
typename traits::attribute_of<subject_type, Context, Iterator>::type
|
||||
>
|
||||
{};
|
||||
|
||||
base_plus(Subject const& subject)
|
||||
: subject(subject) {}
|
||||
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute const& attr) const
|
||||
{
|
||||
typedef detail::fail_function<
|
||||
OutputIterator, Context, Delimiter> fail_function;
|
||||
|
||||
typedef typename traits::container_iterator<
|
||||
typename add_const<Attribute>::type
|
||||
>::type iterator_type;
|
||||
|
||||
typedef
|
||||
typename traits::make_indirect_iterator<iterator_type>::type
|
||||
indirect_iterator_type;
|
||||
typedef detail::pass_container<
|
||||
fail_function, Attribute, indirect_iterator_type, mpl::false_>
|
||||
pass_container;
|
||||
|
||||
iterator_type it = traits::begin(attr);
|
||||
iterator_type end = traits::end(attr);
|
||||
|
||||
// plus fails if the parameter is empty
|
||||
if (traits::compare(it, end))
|
||||
return false;
|
||||
|
||||
pass_container pass(fail_function(sink, ctx, d),
|
||||
indirect_iterator_type(it), indirect_iterator_type(end));
|
||||
|
||||
// from now on plus fails if the underlying output fails or overall
|
||||
// no subject generators succeeded
|
||||
bool result = false;
|
||||
while (!pass.is_at_end())
|
||||
{
|
||||
if (!generate_subject(pass, attr, result, Strict()))
|
||||
break;
|
||||
}
|
||||
return result && detail::sink_is_good(sink);
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
return info("plus", subject.what(context));
|
||||
}
|
||||
|
||||
Subject subject;
|
||||
};
|
||||
|
||||
template <typename Subject>
|
||||
struct plus
|
||||
: base_plus<Subject, mpl::false_, plus<Subject> >
|
||||
{
|
||||
typedef base_plus<Subject, mpl::false_, plus> base_plus_;
|
||||
|
||||
plus(Subject const& subject)
|
||||
: base_plus_(subject) {}
|
||||
};
|
||||
|
||||
template <typename Subject>
|
||||
struct strict_plus
|
||||
: base_plus<Subject, mpl::true_, strict_plus<Subject> >
|
||||
{
|
||||
typedef base_plus<Subject, mpl::true_, strict_plus> base_plus_;
|
||||
|
||||
strict_plus(Subject const& subject)
|
||||
: base_plus_(subject) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace detail
|
||||
{
|
||||
template <typename Elements, bool strict_mode = false>
|
||||
struct make_plus
|
||||
: make_unary_composite<Elements, plus>
|
||||
{};
|
||||
|
||||
template <typename Elements>
|
||||
struct make_plus<Elements, true>
|
||||
: make_unary_composite<Elements, strict_plus>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Elements, typename Modifiers>
|
||||
struct make_composite<proto::tag::unary_plus, Elements, Modifiers>
|
||||
: detail::make_plus<Elements, detail::get_stricttag<Modifiers>::value>
|
||||
{};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::plus<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
template <typename Subject>
|
||||
struct has_semantic_action<karma::strict_plus<Subject> >
|
||||
: unary_has_semantic_action<Subject> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::plus<Subject>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
|
||||
template <typename Subject, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::strict_plus<Subject>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
// Copyright (c) 2001-2011 Hartmut Kaiser
|
||||
// Copyright (c) 2001-2011 Joel de Guzman
|
||||
//
|
||||
// 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)
|
||||
|
||||
#ifndef BOOST_SPIRIT_KARMA_OPERATOR_SEQUENCE_HPP
|
||||
#define BOOST_SPIRIT_KARMA_OPERATOR_SEQUENCE_HPP
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/karma/domain.hpp>
|
||||
#include <boost/spirit/home/karma/generator.hpp>
|
||||
#include <boost/spirit/home/karma/meta_compiler.hpp>
|
||||
#include <boost/spirit/home/karma/detail/fail_function.hpp>
|
||||
#include <boost/spirit/home/karma/detail/pass_container.hpp>
|
||||
#include <boost/spirit/home/karma/detail/get_stricttag.hpp>
|
||||
#include <boost/spirit/home/support/info.hpp>
|
||||
#include <boost/spirit/home/support/detail/what_function.hpp>
|
||||
#include <boost/spirit/home/karma/detail/attributes.hpp>
|
||||
#include <boost/spirit/home/karma/detail/indirect_iterator.hpp>
|
||||
#include <boost/spirit/home/support/algorithm/any_if.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/support/sequence_base_id.hpp>
|
||||
#include <boost/spirit/home/support/has_semantic_action.hpp>
|
||||
#include <boost/spirit/home/support/handles_container.hpp>
|
||||
#include <boost/spirit/home/support/attributes.hpp>
|
||||
#include <boost/fusion/include/vector.hpp>
|
||||
#include <boost/fusion/include/as_vector.hpp>
|
||||
#include <boost/fusion/include/for_each.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/mpl/bitor.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/mpl/and.hpp>
|
||||
#include <boost/mpl/not.hpp>
|
||||
#include <boost/fusion/include/transform.hpp>
|
||||
#include <boost/mpl/accumulate.hpp>
|
||||
#include <boost/proto/operators.hpp>
|
||||
#include <boost/proto/tags.hpp>
|
||||
#include <boost/config.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Enablers
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <>
|
||||
struct use_operator<karma::domain, proto::tag::shift_left> // enables <<
|
||||
: mpl::true_ {};
|
||||
|
||||
template <>
|
||||
struct flatten_tree<karma::domain, proto::tag::shift_left> // flattens <<
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
// specialization for sequences
|
||||
template <typename Elements>
|
||||
struct sequence_properties
|
||||
{
|
||||
struct element_properties
|
||||
{
|
||||
template <typename T>
|
||||
struct result;
|
||||
|
||||
template <typename F, typename Element>
|
||||
struct result<F(Element)>
|
||||
{
|
||||
typedef properties_of<Element> type;
|
||||
};
|
||||
|
||||
// never called, but needed for decltype-based result_of (C++0x)
|
||||
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
|
||||
template <typename Element>
|
||||
typename result<element_properties(Element)>::type
|
||||
operator()(Element&&) const;
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef typename mpl::accumulate<
|
||||
typename fusion::result_of::transform<
|
||||
Elements, element_properties>::type
|
||||
, mpl::int_<karma::generator_properties::no_properties>
|
||||
, mpl::bitor_<mpl::_2, mpl::_1>
|
||||
>::type type;
|
||||
};
|
||||
}}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace karma
|
||||
{
|
||||
template <typename Elements, typename Strict, typename Derived>
|
||||
struct base_sequence : nary_generator<Derived>
|
||||
{
|
||||
typedef typename traits::sequence_properties<Elements>::type properties;
|
||||
|
||||
base_sequence(Elements const& elements)
|
||||
: elements(elements) {}
|
||||
|
||||
typedef Elements elements_type;
|
||||
struct sequence_base_id;
|
||||
|
||||
template <typename Context, typename Iterator = unused_type>
|
||||
struct attribute
|
||||
{
|
||||
// Put all the element attributes in a tuple
|
||||
typedef typename traits::build_attribute_sequence<
|
||||
Elements, Context, traits::sequence_attribute_transform
|
||||
, Iterator, karma::domain
|
||||
>::type all_attributes;
|
||||
|
||||
// Now, build a fusion vector over the attributes. Note
|
||||
// that build_fusion_vector 1) removes all unused attributes
|
||||
// and 2) may return unused_type if all elements have
|
||||
// unused_type(s).
|
||||
typedef typename
|
||||
traits::build_fusion_vector<all_attributes>::type
|
||||
type_;
|
||||
|
||||
// Finally, strip single element vectors into its
|
||||
// naked form: vector1<T> --> T
|
||||
typedef typename
|
||||
traits::strip_single_element_vector<type_>::type
|
||||
type;
|
||||
};
|
||||
|
||||
// standard case. Attribute is a fusion tuple
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute, typename Pred1, typename Pred2>
|
||||
bool generate_impl(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute& attr_, Pred1, Pred2) const
|
||||
{
|
||||
typedef detail::fail_function<
|
||||
OutputIterator, Context, Delimiter> fail_function;
|
||||
typedef traits::attribute_not_unused<Context> predicate;
|
||||
|
||||
// wrap the attribute in a tuple if it is not a tuple or if the
|
||||
// attribute of this sequence is a single element tuple
|
||||
typedef typename attribute<Context>::type_ attr_type_;
|
||||
typename traits::wrap_if_not_tuple<Attribute
|
||||
, typename mpl::and_<
|
||||
traits::one_element_sequence<attr_type_>
|
||||
, mpl::not_<traits::one_element_sequence<Attribute> >
|
||||
>::type
|
||||
>::type attr(attr_);
|
||||
|
||||
// return false if *any* of the generators fail
|
||||
bool r = spirit::any_if(elements, attr
|
||||
, fail_function(sink, ctx, d), predicate());
|
||||
|
||||
typedef typename traits::attribute_size<Attribute>::type size_type;
|
||||
|
||||
// fail generating if sequences have not the same (logical) length
|
||||
return !r && (!Strict::value ||
|
||||
// This ignores container element count (which is not good),
|
||||
// but allows valid attributes to succeed. This will lead to
|
||||
// false positives (failing generators, even if they shouldn't)
|
||||
// if the embedded component is restricting the number of
|
||||
// container elements it consumes (i.e. repeat). This solution
|
||||
// is not optimal but much better than letting _all_ repetitive
|
||||
// components fail.
|
||||
Pred1::value ||
|
||||
size_type(traits::sequence_size<attr_type_>::value) == traits::size(attr_));
|
||||
}
|
||||
|
||||
// Special case when Attribute is an stl container and the sequence's
|
||||
// attribute is not a one element sequence
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate_impl(OutputIterator& sink, Context& ctx
|
||||
, Delimiter const& d, Attribute const& attr_
|
||||
, mpl::true_, mpl::false_) const
|
||||
{
|
||||
// return false if *any* of the generators fail
|
||||
typedef detail::fail_function<
|
||||
OutputIterator, Context, Delimiter> fail_function;
|
||||
|
||||
typedef typename traits::container_iterator<
|
||||
typename add_const<Attribute>::type
|
||||
>::type iterator_type;
|
||||
|
||||
typedef
|
||||
typename traits::make_indirect_iterator<iterator_type>::type
|
||||
indirect_iterator_type;
|
||||
typedef detail::pass_container<
|
||||
fail_function, Attribute, indirect_iterator_type, mpl::true_>
|
||||
pass_container;
|
||||
|
||||
iterator_type begin = traits::begin(attr_);
|
||||
iterator_type end = traits::end(attr_);
|
||||
|
||||
pass_container pass(fail_function(sink, ctx, d),
|
||||
indirect_iterator_type(begin), indirect_iterator_type(end));
|
||||
bool r = fusion::any(elements, pass);
|
||||
|
||||
// fail generating if sequences have not the same (logical) length
|
||||
return !r && (!Strict::value || begin == end);
|
||||
}
|
||||
|
||||
// main generate function. Dispatches to generate_impl depending
|
||||
// on the Attribute type.
|
||||
template <
|
||||
typename OutputIterator, typename Context, typename Delimiter
|
||||
, typename Attribute>
|
||||
bool generate(OutputIterator& sink, Context& ctx, Delimiter const& d
|
||||
, Attribute const& attr) const
|
||||
{
|
||||
typedef typename traits::is_container<Attribute>::type
|
||||
is_container;
|
||||
|
||||
typedef typename attribute<Context>::type_ attr_type_;
|
||||
typedef typename traits::one_element_sequence<attr_type_>::type
|
||||
is_one_element_sequence;
|
||||
|
||||
return generate_impl(sink, ctx, d, attr, is_container()
|
||||
, is_one_element_sequence());
|
||||
}
|
||||
|
||||
template <typename Context>
|
||||
info what(Context& context) const
|
||||
{
|
||||
info result("sequence");
|
||||
fusion::for_each(elements,
|
||||
spirit::detail::what_function<Context>(result, context));
|
||||
return result;
|
||||
}
|
||||
|
||||
Elements elements;
|
||||
};
|
||||
|
||||
template <typename Elements>
|
||||
struct sequence
|
||||
: base_sequence<Elements, mpl::false_, sequence<Elements> >
|
||||
{
|
||||
typedef base_sequence<Elements, mpl::false_, sequence> base_sequence_;
|
||||
|
||||
sequence(Elements const& subject)
|
||||
: base_sequence_(subject) {}
|
||||
};
|
||||
|
||||
template <typename Elements>
|
||||
struct strict_sequence
|
||||
: base_sequence<Elements, mpl::true_, strict_sequence<Elements> >
|
||||
{
|
||||
typedef base_sequence<Elements, mpl::true_, strict_sequence>
|
||||
base_sequence_;
|
||||
|
||||
strict_sequence(Elements const& subject)
|
||||
: base_sequence_(subject) {}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Generator generators: make_xxx function (objects)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
namespace detail
|
||||
{
|
||||
template <typename Elements, bool strict_mode = false>
|
||||
struct make_sequence
|
||||
: make_nary_composite<Elements, sequence>
|
||||
{};
|
||||
|
||||
template <typename Elements>
|
||||
struct make_sequence<Elements, true>
|
||||
: make_nary_composite<Elements, strict_sequence>
|
||||
{};
|
||||
}
|
||||
|
||||
template <typename Elements, typename Modifiers>
|
||||
struct make_composite<proto::tag::shift_left, Elements, Modifiers>
|
||||
: detail::make_sequence<Elements, detail::get_stricttag<Modifiers>::value>
|
||||
{};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Helper template allowing to get the required container type for a rule
|
||||
// attribute, which is part of a sequence.
|
||||
template <typename Iterator>
|
||||
struct make_sequence_iterator_range
|
||||
{
|
||||
typedef iterator_range<detail::indirect_iterator<Iterator> > type;
|
||||
};
|
||||
}}}
|
||||
|
||||
namespace boost { namespace spirit { namespace traits
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements>
|
||||
struct has_semantic_action<karma::sequence<Elements> >
|
||||
: nary_has_semantic_action<Elements> {};
|
||||
|
||||
template <typename Elements>
|
||||
struct has_semantic_action<karma::strict_sequence<Elements> >
|
||||
: nary_has_semantic_action<Elements> {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Elements, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::sequence<Elements>, Attribute, Context
|
||||
, Iterator>
|
||||
: mpl::true_ {};
|
||||
|
||||
template <typename Elements, typename Attribute, typename Context
|
||||
, typename Iterator>
|
||||
struct handles_container<karma::strict_sequence<Elements>, Attribute
|
||||
, Context, Iterator>
|
||||
: mpl::true_ {};
|
||||
}}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user