alaCarte Maps
Renderer for OpenStreetMap tiles
color_grammar.cpp
Go to the documentation of this file.
1 
23 
24 #include "utils/colorTable.hpp"
25 
26 #include <boost/spirit/include/qi.hpp>
27 #include <boost/spirit/include/phoenix_core.hpp>
28 #include <boost/spirit/include/phoenix_operator.hpp>
29 #include <boost/spirit/include/phoenix_fusion.hpp>
30 #include <boost/spirit/include/phoenix_object.hpp>
31 #include <boost/spirit/include/phoenix_stl.hpp>
32 #include <boost/spirit/include/phoenix_bind.hpp>
33 #include <boost/spirit/include/phoenix.hpp>
34 #include <boost/spirit/include/qi_symbols.hpp>
35 
36 
38 {
39  auto& table = ColorTable::Inst().getTable();
40 
41  for(auto& entry : table)
42  {
43  this->add(entry.first, entry.second);
44  }
45 }
46 
47 
52  : ColorGrammar::base_type(rule_color, "color-grammar")
53 {
54  //using namespace boost::phoenix::local_names;
55  using namespace qi::labels;
56  using boost::phoenix::construct;
57  auto& _1 = qi::_1;
58 
59  rule_hexvalue = (hexdigit[_a = _1] >> hexdigit[_val = _a * 16 + _1]);
60  rule_hexcolor = qi::eps[_d = 255] >> (( rule_hexvalue[_a = _1] >> rule_hexvalue[_b = _1] >> rule_hexvalue[_c = _1] >> -(rule_hexvalue[_d = _1]))[_val = phx::construct<Color>(_a, _b, _c, _d)]
61  | (hexdigit[_a = _1] >> hexdigit[_b = _1] >> hexdigit[_val = phx::construct<Color>(_a, _b, _1)]));
62 
63  rule_rgb = '(' >> qi::float_[_a = _1] >> ',' >> qi::float_[_b = _1] >> ',' >> qi::float_[_val = phx::construct<Color>(_a, _b, _1)] >> ')';
64  rule_rgba = '(' >> qi::float_[_a = _1] >> ',' >> qi::float_[_b = _1] >> ',' >> qi::float_[_c = _1] >> ',' >> qi::float_[_val = phx::construct<Color>(_a, _b, _c, _1)] >> ')';
65  rule_color = ('#' >> rule_hexcolor)
66  | (qi::lit("rgb") >> rule_rgb)
67  | (qi::lit("rgba") >> rule_rgba)
68  | colorSymbol_;
69 
70  //qi::debug(rule_color);
71  //qi::debug(rule_rgba);
72  //qi::debug(rule_rgb);
73  // qi::debug(rule_hexcolor);
74  // qi::debug(rule_hexvalue);
75 }
A grammar to parse a mapcss color.
qi::rule< ItType, uint8(), qi::locals< uint8, uint8 > > rule_hexvalue
Rule to parse the hex color code.
ColorSymbols()
This file is part of alaCarte.
const boost::unordered_map< string, Color > & getTable() const
Returns the hole table.
Definition: colorTable.cpp:237
qi::uint_parser< uint8, 16, 1, 1 > hexdigit
Rule to parse a hex digit.
qi::rule< ItType, Color(), qi::locals< float, float >, Skipper > rule_rgb
Rule for rgb(...)
qi::rule< ItType, Color(), qi::locals< float, float, float >, Skipper > rule_rgba
Rule for rgba(...)
ColorGrammar()
Creates all rules for the color grammar.
ColorSymbols colorSymbol_
Symbol parser for colors.
qi::rule< ItType, Color(), Skipper > rule_color
Mainrule.
qi::rule< ItType, Color(), qi::locals< uint8, uint8, uint8, uint8 > > rule_hexcolor
Rule for #COLORCODE.
static const ColorTable & Inst()
Returns a instance of a color table.
Definition: colorTable.cpp:209