alaCarte Maps
Renderer for OpenStreetMap tiles
eval_helpers.cpp
Go to the documentation of this file.
1 
24 #include <boost/spirit/include/qi.hpp>
25 #include <boost/algorithm/string.hpp>
26 
29 
30 namespace eval {
31 
32 
33 
34 
35 
36 template<>
37 bool Conv(const string& str, bool* out, bool tryToCache )
38 {
39  assert(out);
40  *out = true;
41 
42  if(str == "")
43  *out = false;
44  if(str == "false")
45  *out = false;
46  if(str == "no")
47  *out = false;
48 
49  int i;
50  if(Conv(str, &i) && i == 0)
51  {
52  *out = false;
53  }
54 
55  return true;
56 }
57 
58 
60 
61 template<>
62 bool Conv(const string& str, Color* out, bool tryToCache )
63 {
64  assert(out);
65  StringIterator begin = str.cbegin();
66  StringIterator end = str.cend();
67 
68  bool result = qi::phrase_parse(begin, end, color_, chs::space, *out);
69 
70  return begin == end && result;
71 }
72 
73 
74 template<>
75 bool Conv(const string& str, string* out, bool tryToCache )
76 {
77  assert(out);
78  out->clear();
79 
80  bool quote = false;
81  for(char c : str)
82  {
83  if(c == '\"')
84  {
85  quote = !quote;
86  }else{
87  out->push_back(c);
88  }
89  }
90  boost::algorithm::trim(*out);
91  return !quote;
92 }
93 
94 
95 template<>
96 bool Conv(const string& str, MaybeCachedString* out, bool tryToCache )
97 {
98  string extr;
99 
100  bool result = Conv<string>(str, &extr);
101 
102  if(result)
103  {
104  if(tryToCache)
105  {
106  *out = CachedString(extr);
107  }else{
108  *out = extr;
109  }
110  }
111 
112  return result;
113 }
114 
115 
116 template<>
117 string ToString(const bool& v)
118 {
119  return v ? "true" : "false";
120 }
121 
122 
123 
124 }
A grammar to parse a mapcss color.
Definition: color.hpp:40
bool Conv(const string &str, bool *out, bool tryToCache)
Use some extra function for bool conversion.
Represents a string which could be cached into an internal cache.
This file is part of alaCarte.
std::string::const_iterator StringIterator
Iterator to iterate over a file.
Definition: mapcss_def.hpp:146
string ToString(const bool &v)
Represents a string which is cached into an internal cache.
ColorGrammar color_