alaCarte Maps
Renderer for OpenStreetMap tiles
mapcss_grammar.hpp
Go to the documentation of this file.
1 
21 #pragma once
22 #ifndef MAPCSS_GRAMMAR_HPP
23 #define MAPCSS_GRAMMAR_HPP
24 
25 
26 
27 
28 #include "mapcss_def.hpp"
29 #include "comment_skipper.hpp"
30 #include "server/eval/eval.hpp"
31 #include "eval_grammar.hpp"
32 
34 #include "config.hpp"
35 
36 
37 namespace phx = boost::phoenix;
38 
39 
41 struct Zoom
42 {
44  Zoom()
46  {
47  }
48 
50  Zoom(int bottom, int top)
51  : top(top), bottom(bottom)
52  {
53 
54  }
55 
56  void expand(const Zoom& other)
57  {
58  top = std::max(top, other.top);
59  bottom = std::min(bottom, other.bottom);
60  }
61 
62  void focus(const Zoom& other)
63  {
64  top = std::min(top, other.top);
65  bottom = std::max(bottom, other.bottom);
66  }
67 
68 
70  bool operator == (const Zoom& z) const
71  {
72  return top == z.top && bottom == z.bottom;
73  }
74 
76  int top;
77 
79  int bottom;
80 };
81 
82 
84 typedef fsio::vector< op::UnaryTypesEnum, /* operator */
85  string /* tag */
87 
89 typedef fsio::vector< string, /* tag */
90  op::BinaryTypesEnum, /* operator */
91  string /* tag */
93 
95 typedef boost::variant<UnaryCondition, BinaryCondition> ConditionType;
96 
99 {
102  : objectType(obj::Any)
103  {}
104 
106  SelectorItem(obj::ObjectTypeEnum o, const Zoom& zoom, const std::vector<ConditionType>& conds)
107  : objectType(o)
108  , zoom(zoom)
109  , conditions(conds)
110  {}
111 
113  bool operator == (const SelectorItem& i) const
114  {
115  return objectType == i.objectType && zoom == i.zoom && conditions == i.conditions;
116  }
117 
123  std::vector<ConditionType> conditions;
124 };
125 
126 
127 
129  (obj::ObjectTypeEnum, objectType)
130  (Zoom, zoom)
131  (std::vector<ConditionType>, conditions)
132  )
133 
134 
135 struct UnitTypes : qi::symbols<char, unit::UnitTypesEnum>
137 {
138 
139  UnitTypes()
140  {
141  this->add
142  ("px", unit::Pixel)
143  ("pt", unit::Points)
144  ("%", unit::Percent)
145  ;
146  }
147 
148 };
149 
151 struct ObjectTypes : qi::symbols<char, obj::ObjectTypeEnum>
152 {
153 
155  {
156  this->add
157  ("node", obj::Node)
158  ("way", obj::Way)
159  ("relation", obj::Relation)
160  ("area", obj::Area)
161  ("line", obj::Line)
162  ("*", obj::Any)
163  ;
164  }
165 
166 };
167 
169 struct BinaryTypes : qi::symbols<char, op::BinaryTypesEnum>
170 {
171 
173  {
174  this->add
175  ("=", op::Equal)
176  ("!=", op::Unequal)
177  ("=~", op::SameAs)
178  ("<", op::LessThen)
179  (">", op::GreaterThen)
180  ("<=", op::LessEqual)
181  (">=", op::GreaterEqual)
182  ;
183  }
184 
185 };
186 
188 struct UnaryTypes : qi::symbols<char, op::UnaryTypesEnum>
189 {
190 
192  {
193  this->add
194  ("!", op::Not)
195  ("-", op::Minus)
196  ;
197  }
198 
199 };
200 
202 {
203  virtual void addAttribute(const shared_ptr<StyleTemplate>& styleTemplate, const string& specifier, const shared_ptr<ParserLogger>& logger, const ParseInfo& info) = 0;
204 };
205 
207 struct AttributeTypes : qi::symbols<char, shared_ptr<AttributeCreator> >
208 {
209  AttributeTypes();
210 };
211 
212 
213 
214 struct MapCssParser;
215 
220 struct MapCSSGrammar : public qi::grammar<GrammarIterator, StylesheetPtr(), qi::locals<std::vector<RulePtr>, StylePtr>, CommentSkipper>
221 {
226 
235 
236  MapCSSGrammar(MapCssParser& parser);
237 
239  qi::rule<ItType, StylePtr(), qi::locals<shared_ptr<AttributeCreator>, ParseInfo>, Skipper> rule_styleset;
241  qi::rule<ItType, string(), Skipper> attribute_name;
243  qi::rule<ItType, string(), Skipper> rule_specifier;
245  qi::rule<ItType, string()> rule_value;
247  qi::rule<ItType, string()> rule_tag;
249  qi::rule<ItType, Zoom(), qi::locals<int, int>, Skipper> rule_zoom;
251  qi::rule<ItType, BinaryCondition()> rule_binary_condition;
253  qi::rule<ItType, UnaryCondition()> rule_unary_condition;
255  qi::rule<ItType> rule_class;
257  qi::rule<ItType, SelectorItem(), Skipper> rule_subselector;
259  qi::rule<ItType, RulePtr(), qi::locals<std::vector<SelectorItem> >, Skipper> rule_selector;
260 
262  qi::rule<ItType, std::vector<RulePtr>(), Skipper> rule_cssrule;
264  qi::rule<ItType, StylesheetPtr(), qi::locals<std::vector<RulePtr>, StylePtr>, Skipper> rule_stylesheet;
265 };
266 
267 
268 
269 #endif
Checks if a value is recognised by a regex.
Definition: mapcss_def.hpp:68
Checks if two values are equal.
Definition: mapcss_def.hpp:66
Zoom(int bottom, int top)
Creates a zoom from given values.
SelectorItem()
Creates an empty selector item.
qi::rule< ItType, StylePtr(), qi::locals< shared_ptr< AttributeCreator >, ParseInfo >, Skipper > rule_styleset
Rule to parse a styleset of a rule.
symbols for the binary operators
qi::rule< ItType, Zoom(), qi::locals< int, int >, Skipper > rule_zoom
Rule to parse a zoom range.
Checks if a value is greater then another.
Definition: mapcss_def.hpp:70
BOOST_FUSION_ADAPT_STRUCT(SelectorItem,(obj::ObjectTypeEnum, objectType)(Zoom, zoom)(std::vector< ConditionType >, conditions)) struct UnitTypes
symbols for the unit types
fsio::vector< op::UnaryTypesEnum, string > UnaryCondition
Stores informations about an unary condition.
The grammar for the mapcss format.
Checks if a value is lesser than another.
Definition: mapcss_def.hpp:69
Grammar to skipp c/c++ style comments.
AttributeTypes attributeType_
The symbol parser for style attributes.
int bottom
The bottom of the zoom range.
Selects nodes.
Definition: mapcss_def.hpp:51
void expand(const Zoom &other)
qi::rule< ItType, string(), Skipper > rule_specifier
Rule to parse the specifier.
Zoom zoom
The zoom which should be selected.
qi::rule< ItType, string()> rule_tag
Rule to parse a tag.
Selects relations.
Definition: mapcss_def.hpp:53
fsio::vector< string, op::BinaryTypesEnum, string > BinaryCondition
Stores informations about an binary condition.
std::vector< ConditionType > conditions
The condition of the item.
Selects ways.
Definition: mapcss_def.hpp:52
BinaryTypesEnum
Enum with binary operators used in selectors.
Definition: mapcss_def.hpp:64
classic::position_iterator2< StringIterator > GrammarIterator
Iterator wrapping the file iterator and to be used in all grammars.
Definition: mapcss_def.hpp:148
Zoom()
Creates the standard zoom.
symbols for the attributes
shared_ptr< StyleTemplate > StylePtr
Shortcut for a shared pointer to style.
Definition: mapcss_def.hpp:141
std::string string
Definition: settings.hpp:110
qi::rule< ItType > rule_class
Rule to parse mapcss classes.
ObjectTypes selectorObject_
The symbol parser for objects.
qi::rule< ItType, RulePtr(), qi::locals< std::vector< SelectorItem > >, Skipper > rule_selector
Rule to parse a selector.
qi::rule< ItType, string()> rule_value
Rule to parse a value.
GrammarIterator ItType
The Iterator used in this grammar.
boost::variant< UnaryCondition, BinaryCondition > ConditionType
Possible Conditions.
qi::rule< ItType, SelectorItem(), Skipper > rule_subselector
Rule to parse one part of the selector.
UnitTypesEnum
Contains all the units available for numeric values.
Definition: mapcss_def.hpp:89
Checks if a geoobject does not have a certain tag.
Definition: mapcss_def.hpp:79
Selects lines (unclosed ways)
Definition: mapcss_def.hpp:55
ObjectTypeEnum
Enum with object selectors.
Definition: mapcss_def.hpp:49
CommentSkipper Skipper
The skipper used in this grammar.
#define ALAC_ZOOM_BOTTOM
Definition: settings.hpp:132
Checks if two values are not equal.
Definition: mapcss_def.hpp:67
Checks if a value is lesser or equal to another.
Definition: mapcss_def.hpp:71
UnaryTypes unaryOperator_
The symbol parser for unary operators.
bool operator==(const Zoom &z) const
Compares to zoom&#39;s.
obj::ObjectTypeEnum objectType
The type of the object, which should be selected.
BinaryTypes binaryOperator_
The symbol parser for binary operators.
Selects areas (closed ways)
Definition: mapcss_def.hpp:54
Checks if a value is greater or equal to another.
Definition: mapcss_def.hpp:72
Represents a part of the style selector.
#define ALAC_ZOOM_TOP
Definition: settings.hpp:133
Simple structure to store a zoom range.
qi::rule< ItType, string(), Skipper > attribute_name
Rule to parse generic (unknown) attribute name.
int top
The top of the zoom range.
qi::rule< ItType, BinaryCondition()> rule_binary_condition
Rule to parse a binary condition.
void focus(const Zoom &other)
SelectorItem(obj::ObjectTypeEnum o, const Zoom &zoom, const std::vector< ConditionType > &conds)
Creates an selector item from given values.
symbols for the objects
UnaryTypesEnum
Enum with unary operators used in selectors.
Definition: mapcss_def.hpp:76
symbols for the unary operators
qi::rule< ItType, StylesheetPtr(), qi::locals< std::vector< RulePtr >, StylePtr >, Skipper > rule_stylesheet
Main rule returning a stylesheet.
Selects everything.
Definition: mapcss_def.hpp:56
qi::rule< ItType, UnaryCondition()> rule_unary_condition
Rule to parse a unary condition.