Imported existing code
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright (c) 2001-2009 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_ISTREAM_MAY_05_2007_0110PM)
|
||||
#define BOOST_SPIRIT_ITERATOR_ISTREAM_MAY_05_2007_0110PM
|
||||
|
||||
#include <boost/iostreams/stream.hpp>
|
||||
#include <boost/detail/iterator.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace qi { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Iterator>
|
||||
struct iterator_source
|
||||
{
|
||||
typedef typename
|
||||
boost::detail::iterator_traits<Iterator>::value_type
|
||||
char_type;
|
||||
typedef boost::iostreams::source_tag category;
|
||||
|
||||
iterator_source (Iterator& first_, Iterator const& last_)
|
||||
: first(first_), last(last_)
|
||||
{}
|
||||
|
||||
// Read up to n characters from the input sequence into the buffer s,
|
||||
// returning the number of characters read, or -1 to indicate
|
||||
// end-of-sequence.
|
||||
std::streamsize read (char_type* s, std::streamsize n)
|
||||
{
|
||||
if (first == last)
|
||||
return -1;
|
||||
|
||||
std::streamsize bytes_read = 0;
|
||||
while (n--) {
|
||||
*s = *first;
|
||||
++s; ++bytes_read;
|
||||
if (++first == last)
|
||||
break;
|
||||
}
|
||||
return bytes_read;
|
||||
}
|
||||
|
||||
Iterator& first;
|
||||
Iterator const& last;
|
||||
};
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,104 @@
|
||||
// Copyright (c) 2001-2009 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_FORMAT_MANIP_MAY_05_2007_1203PM)
|
||||
#define BOOST_SPIRIT_FORMAT_MANIP_MAY_05_2007_1203PM
|
||||
|
||||
#include <boost/spirit/home/qi/parse.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include <string>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace qi { namespace detail
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <
|
||||
typename Expr,
|
||||
typename Attribute = unused_type const,
|
||||
typename Skipper = unused_type
|
||||
>
|
||||
struct match_manip
|
||||
{
|
||||
match_manip(Expr const& xpr, Attribute& a, Skipper const& s)
|
||||
: expr(xpr), attr(a), skipper(s)
|
||||
{}
|
||||
|
||||
Expr const& expr;
|
||||
Attribute& attr;
|
||||
Skipper const& skipper;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename Char, typename Traits, typename Expr>
|
||||
inline std::basic_istream<Char, Traits> &
|
||||
operator>> (std::basic_istream<Char, Traits> &is,
|
||||
match_manip<Expr> const& fm)
|
||||
{
|
||||
typedef std::istream_iterator<Char, Char, Traits> input_iterator;
|
||||
input_iterator f(is);
|
||||
input_iterator l;
|
||||
if (!qi::parse (f, l, fm.expr))
|
||||
{
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename Char, typename Traits, typename Expr, typename Attribute>
|
||||
inline std::basic_istream<Char, Traits> &
|
||||
operator>> (std::basic_istream<Char, Traits> &is,
|
||||
match_manip<Expr, Attribute> const& fm)
|
||||
{
|
||||
typedef std::istream_iterator<Char, Char, Traits> input_iterator;
|
||||
input_iterator f(is);
|
||||
input_iterator l;
|
||||
if (!qi::parse(f, l, fm.expr, fm.attr))
|
||||
{
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<typename Char, typename Traits, typename Expr, typename Skipper>
|
||||
inline std::basic_istream<Char, Traits> &
|
||||
operator>> (std::basic_istream<Char, Traits> &is,
|
||||
match_manip<Expr, unused_type, Skipper> const& fm)
|
||||
{
|
||||
typedef std::istream_iterator<Char, Char, Traits> input_iterator;
|
||||
input_iterator f(is);
|
||||
input_iterator l;
|
||||
if (!qi::phrase_parse(f, l, fm.expr, fm.skipper))
|
||||
{
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<
|
||||
typename Char, typename Traits,
|
||||
typename Expr, typename Attribute, typename Skipper
|
||||
>
|
||||
inline std::basic_istream<Char, Traits> &
|
||||
operator>> (
|
||||
std::basic_istream<Char, Traits> &is,
|
||||
match_manip<Expr, Attribute, Skipper> const& fm)
|
||||
{
|
||||
typedef std::istream_iterator<Char, Char, Traits> input_iterator;
|
||||
input_iterator f(is);
|
||||
input_iterator l;
|
||||
if (!qi::phrase_parse(f, l, fm.expr, fm.attr, fm.skipper))
|
||||
{
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
}}}}
|
||||
|
||||
#endif
|
||||
112
libraries/include/boost/spirit/home/qi/stream/match_manip.hpp
Normal file
112
libraries/include/boost/spirit/home/qi/stream/match_manip.hpp
Normal file
@@ -0,0 +1,112 @@
|
||||
// Copyright (c) 2001-2009 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_FORMAT_MANIP_MAY_05_2007_1202PM)
|
||||
#define BOOST_SPIRIT_FORMAT_MANIP_MAY_05_2007_1202PM
|
||||
|
||||
#include <boost/spirit/home/qi/parse.hpp>
|
||||
#include <boost/spirit/home/support/unused.hpp>
|
||||
#include <boost/spirit/home/qi/stream/detail/match_manip.hpp>
|
||||
|
||||
#include <boost/mpl/assert.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Expr>
|
||||
inline detail::match_manip<Expr>
|
||||
match(Expr const& xpr)
|
||||
{
|
||||
typedef spirit::traits::is_component<qi::domain, Expr> is_component;
|
||||
|
||||
// report invalid expression error as early as possible
|
||||
BOOST_MPL_ASSERT_MSG(is_component::value,
|
||||
xpr_is_not_convertible_to_a_parser, (Expr));
|
||||
|
||||
return qi::detail::match_manip<Expr>(xpr, unused, unused);
|
||||
}
|
||||
|
||||
template <typename Expr, typename Attribute>
|
||||
inline detail::match_manip<Expr, Attribute>
|
||||
match(Expr const& xpr, Attribute& p)
|
||||
{
|
||||
typedef spirit::traits::is_component<qi::domain, Expr> is_component;
|
||||
|
||||
// report invalid expression error as early as possible
|
||||
BOOST_MPL_ASSERT_MSG(is_component::value,
|
||||
xpr_is_not_convertible_to_a_parser, (Expr, Attribute));
|
||||
|
||||
return qi::detail::match_manip<Expr, Attribute>(xpr, p, unused);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Expr, typename Skipper>
|
||||
inline detail::match_manip<Expr, unused_type const, Skipper>
|
||||
phrase_match(Expr const& xpr, Skipper const& s)
|
||||
{
|
||||
typedef
|
||||
spirit::traits::is_component<qi::domain, Expr>
|
||||
expr_is_component;
|
||||
typedef
|
||||
spirit::traits::is_component<qi::domain, Skipper>
|
||||
skipper_is_component;
|
||||
|
||||
// report invalid expression errors as early as possible
|
||||
BOOST_MPL_ASSERT_MSG(expr_is_component::value,
|
||||
xpr_is_not_convertible_to_a_parser, (Expr, Skipper));
|
||||
|
||||
BOOST_MPL_ASSERT_MSG(skipper_is_component::value,
|
||||
skipper_is_not_convertible_to_a_parser, (Expr, Skipper));
|
||||
|
||||
return qi::detail::match_manip<Expr, unused_type const, Skipper>(
|
||||
xpr, unused, s);
|
||||
}
|
||||
|
||||
template <typename Expr, typename Attribute, typename Skipper>
|
||||
inline detail::match_manip<Expr, Attribute, Skipper>
|
||||
phrase_match(Expr const& xpr, Attribute& p, Skipper const& s)
|
||||
{
|
||||
typedef
|
||||
spirit::traits::is_component<qi::domain, Expr>
|
||||
expr_is_component;
|
||||
typedef
|
||||
spirit::traits::is_component<qi::domain, Skipper>
|
||||
skipper_is_component;
|
||||
|
||||
// report invalid expression errors as early as possible
|
||||
BOOST_MPL_ASSERT_MSG(expr_is_component::value,
|
||||
xpr_is_not_convertible_to_a_parser, (Expr, Attribute, Skipper));
|
||||
|
||||
BOOST_MPL_ASSERT_MSG(skipper_is_component::value,
|
||||
skipper_is_not_convertible_to_a_parser, (Expr, Attribute, Skipper));
|
||||
|
||||
return qi::detail::match_manip<Expr, Attribute, Skipper>(xpr, p, s);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template<typename Char, typename Traits, typename Expr>
|
||||
inline typename
|
||||
enable_if<
|
||||
spirit::traits::is_component<qi::domain, Expr>,
|
||||
std::basic_istream<Char, Traits> &
|
||||
>::type
|
||||
operator>> (std::basic_istream<Char, Traits> &is, Expr& xpr)
|
||||
{
|
||||
typedef std::istream_iterator<Char, Char, Traits> input_iterator;
|
||||
input_iterator f(is);
|
||||
input_iterator l;
|
||||
if (!qi::parse (f, l, xpr))
|
||||
{
|
||||
is.setstate(std::ios_base::failbit);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
|
||||
134
libraries/include/boost/spirit/home/qi/stream/meta_grammar.hpp
Normal file
134
libraries/include/boost/spirit/home/qi/stream/meta_grammar.hpp
Normal file
@@ -0,0 +1,134 @@
|
||||
// Copyright (c) 2001-2009 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_META_GRAMMAR_MAY_05_2007_1230PM)
|
||||
#define BOOST_SPIRIT_META_GRAMMAR_MAY_05_2007_1230PM
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
#pragma once // MS compatible compilers support #pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/qi/domain.hpp>
|
||||
#include <boost/spirit/home/support/placeholders.hpp>
|
||||
#include <boost/spirit/home/support/meta_grammar.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
namespace qi
|
||||
{
|
||||
template <typename T, typename Char>
|
||||
struct stream_tag;
|
||||
}
|
||||
|
||||
template <typename T, typename Char>
|
||||
struct is_stream_tag<qi::stream_tag<T, Char>, qi::domain>
|
||||
: mpl::true_ {};
|
||||
}}
|
||||
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// forwards
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Char, typename T>
|
||||
struct any_stream;
|
||||
|
||||
template <typename Char>
|
||||
struct stream_director;
|
||||
|
||||
struct main_meta_grammar;
|
||||
|
||||
template <typename Expr, typename Enable>
|
||||
struct is_valid_expr;
|
||||
|
||||
template <typename Expr, typename Enable>
|
||||
struct expr_transform;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// stream tag
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename T, typename Char>
|
||||
struct stream_tag
|
||||
{
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// stream specs
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename T, typename Char = char>
|
||||
struct typed_stream
|
||||
: proto::terminal<stream_tag<T, Char> >::type
|
||||
{
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// get the director for a stream
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Tag>
|
||||
struct extract_stream_director;
|
||||
|
||||
template <>
|
||||
struct extract_stream_director<tag::stream>
|
||||
{
|
||||
typedef any_stream<char> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct extract_stream_director<tag::wstream>
|
||||
{
|
||||
typedef any_stream<wchar_t> type;
|
||||
};
|
||||
|
||||
template <typename T, typename Char>
|
||||
struct extract_stream_director<stream_tag<T, Char> >
|
||||
{
|
||||
typedef any_stream<Char, T> type;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// utility meta-grammar
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
struct utility_meta_grammar :
|
||||
// stream, wstream
|
||||
meta_grammar::compose_empty<
|
||||
proto::if_<
|
||||
is_stream_tag<proto::_child, qi::domain>()
|
||||
>,
|
||||
qi::domain,
|
||||
mpl::identity<extract_stream_director<mpl::_> >
|
||||
>
|
||||
{
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// These specializations non-intrusively hooks into the Qi meta-grammar.
|
||||
// (see qi/meta_grammar.hpp)
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
template <typename Expr>
|
||||
struct is_valid_expr<
|
||||
Expr,
|
||||
typename enable_if<
|
||||
proto::matches<Expr, utility_meta_grammar>
|
||||
>::type
|
||||
>
|
||||
: mpl::true_
|
||||
{
|
||||
};
|
||||
|
||||
template <typename Expr>
|
||||
struct expr_transform<
|
||||
Expr,
|
||||
typename enable_if<
|
||||
proto::matches<Expr, utility_meta_grammar>
|
||||
>::type
|
||||
>
|
||||
: mpl::identity<utility_meta_grammar>
|
||||
{
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
73
libraries/include/boost/spirit/home/qi/stream/stream.hpp
Normal file
73
libraries/include/boost/spirit/home/qi/stream/stream.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright (c) 2001-2009 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_STREAM_MAY_05_2007_1228PM)
|
||||
#define BOOST_SPIRIT_STREAM_MAY_05_2007_1228PM
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
|
||||
#pragma once // MS compatible compilers support #pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/spirit/home/qi/detail/string_parse.hpp>
|
||||
#include <boost/spirit/home/qi/stream/detail/match_manip.hpp>
|
||||
#include <boost/spirit/home/qi/stream/detail/iterator_istream.hpp>
|
||||
#include <boost/spirit/home/support/detail/hold_any.hpp>
|
||||
|
||||
#include <iosfwd>
|
||||
#include <sstream>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit
|
||||
{
|
||||
// overload the streaming operators for the unused_type
|
||||
template <typename Char, typename Traits>
|
||||
inline std::basic_istream<Char, Traits>&
|
||||
operator>> (std::basic_istream<Char, Traits>& is, unused_type&)
|
||||
{
|
||||
return is;
|
||||
}
|
||||
}}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
namespace boost { namespace spirit { namespace qi
|
||||
{
|
||||
template <typename Char, typename T = spirit::hold_any>
|
||||
struct any_stream
|
||||
{
|
||||
template <typename Component, typename Context, typename Iterator>
|
||||
struct attribute
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Component
|
||||
, typename Iterator, typename Context
|
||||
, typename Skipper, typename Attribute>
|
||||
static bool parse(
|
||||
Component const& /*component*/
|
||||
, Iterator& first, Iterator const& last
|
||||
, Context& /*context*/, Skipper const& skipper
|
||||
, Attribute& attr)
|
||||
{
|
||||
typedef qi::detail::iterator_source<Iterator> source_device;
|
||||
typedef boost::iostreams::stream<source_device> instream;
|
||||
|
||||
qi::skip(first, last, skipper);
|
||||
instream in (first, last);
|
||||
in >> attr; // use existing operator>>()
|
||||
return in.good() || in.eof();
|
||||
}
|
||||
|
||||
template <typename Component, typename Context>
|
||||
static std::string what(Component const& component, Context const& ctx)
|
||||
{
|
||||
return "any-stream";
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user