DoorKeeper/src/asciimap_parser.hpp

74 lines
2.4 KiB
C++

/* Copyright 2015, Michele Santullo
* This file is part of DoorKeeper.
*
* DoorKeeper is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DoorKeeper is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DoorKeeper. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idB6D0694FDF6B4902A244C7A51C9727FE
#define idB6D0694FDF6B4902A244C7A51C9727FE
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
#include <boost/spirit/include/support_line_pos_iterator.hpp>
#include <boost/spirit/repository/include/qi_iter_pos.hpp>
#include <boost/spirit/include/support_multi_pass.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
namespace dkh { namespace implem {
struct get_line_f {
template <typename> struct result { typedef size_t type; };
template <typename I> size_t operator()(const I& parStart, const I& parPosIter) const {
return boost::spirit::get_column(parStart, parPosIter) - 1;
}
};
template <typename I, typename T>
struct AsciiMapGrammar : boost::spirit::qi::grammar<I, std::vector<T>()> {
explicit AsciiMapGrammar ( const I& parItStart );
boost::spirit::qi::rule<I, std::vector<T>()> start;
std::vector<int> lengths;
boost::phoenix::function<get_line_f> getline;
boost::spirit::qi::int_parser<T, 16, 1, 1> digit_int;
};
template <typename I, typename T>
AsciiMapGrammar<I, T>::AsciiMapGrammar (const I& parItStart) :
AsciiMapGrammar::base_type(start)
{
using boost::phoenix::push_back;
using boost::spirit::qi::_1;
using boost::spirit::qi::eol;
using boost::spirit::qi::eoi;
using boost::spirit::qi::raw;
using boost::phoenix::begin;
using boost::spirit::qi::int_parser;
start %= *digit_int %
raw[
eol
][push_back(boost::phoenix::ref(lengths), getline(boost::phoenix::val(parItStart), begin(_1)))]
;
}
}} //namespace dkh::implem
#undef BOOST_SPIRIT_USE_PHOENIX_V3
#endif