-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_path_grammar.hpp
104 lines (90 loc) · 2.88 KB
/
tile_path_grammar.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*------------------------------------------------------------------------------
*
* This file is part of rendermq
*
* Author: [email protected]
*
* Copyright 2010-1 Mapquest, Inc. All Rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*-----------------------------------------------------------------------------*/
#ifndef TILE_PATH_GRAMMAR_HPP
#define TILE_PATH_GRAMMAR_HPP
#include <boost/spirit/include/qi.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/qi_omit.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include "tile_protocol.hpp"
BOOST_FUSION_ADAPT_STRUCT(
rendermq::tile_protocol,
(std::string, style)
(int, z)
(int, x)
(int, y)
(rendermq::protoFmt, format)
(rendermq::protoCmd, status)
)
namespace rendermq {
namespace qi = boost::spirit::qi;
namespace phoenix = boost::phoenix;
struct formats_ : qi::symbols<char, protoFmt> {
formats_() {
add
("png", fmtPNG)
("jpg", fmtJPEG)
("jpeg", fmtJPEG) // why not, let's have both spellings...
("gif", fmtGIF)
("json", fmtJSON)
;
}
};
template <typename Iterator>
struct commands_ : qi::grammar<Iterator, protoCmd()> {
commands_() : commands_::base_type(cmd) {
using qi::_val;
using qi::lit;
using qi::eoi;
cmd =
eoi [ _val = rendermq::cmdRender ] |
lit("/dirty") [ _val = rendermq::cmdDirty ] |
lit("/status") [ _val = rendermq::cmdStatus ]
;
}
qi::rule<Iterator, protoCmd()> cmd;
};
template <typename Iterator>
struct tile_path_grammar : qi::grammar<Iterator, tile_protocol()> {
tile_path_grammar()
: tile_path_grammar::base_type(path) {
using qi::lit;
using qi::int_;
using qi::alpha;
using qi::alnum;
using boost::spirit::raw;
path %= lit("/") >> raw[ (alpha >> *alnum) % lit("/") ]
>> lit("/") >> int_
>> lit("/") >> int_
>> lit("/") >> int_
>> lit(".") >> formats
>> commands;
}
qi::rule<Iterator, tile_protocol()> path;
commands_<Iterator> commands;
formats_ formats;
};
}
#endif // TILE_PATH_GRAMMAR_HPP