23 #include <boost/fusion/include/at_c.hpp> 24 #include <boost/spirit/include/qi.hpp> 25 #include <boost/filesystem/path.hpp> 26 #include <boost/filesystem/path.hpp> 27 #include <boost/lexical_cast.hpp> 28 #include <boost/thread/thread.hpp> 124 attrType->addAttribute(style, specifier,
logger, info);
134 logger->warnStream() <<
"Attribute will be ignored!";
146 for(
auto& rule : rules)
148 rule->setStyleTemplate(style);
189 case obj::Node:
return boost::make_shared<ChildNodesSelector>(rule, next);
190 case obj::Way:
return boost::make_shared<ChildWaysSelector>(rule, next);
191 case obj::Line:
return boost::make_shared<ChildWaysSelector>(rule, boost::make_shared<LineSelector>(rule, next));
192 case obj::Area:
return boost::make_shared<ChildWaysSelector>(rule, boost::make_shared<AreaSelector>(rule, next));
209 const string& tag = fsio::at_c<1>(condition);
211 switch(fsio::at_c<0>(condition))
213 case op::HasTag:
return boost::make_shared<HasTagSelector>(rule, next, tag);
214 case op::Not:
return boost::make_shared<HasNotTagSelector>(rule, next, tag);
217 assert(!
"This unary condition is not implemented!");
232 const string& tag = fsio::at_c<0>(condition);
233 const string& value = fsio::at_c<2>(condition);
236 switch(fsio::at_c<1>(condition))
238 case op::Equal:
return boost::make_shared<TagEqualsSelector>(rule, next, tag, value);
239 case op::Unequal:
return boost::make_shared<TagUnequalsSelector>(rule, next, tag, value);
240 case op::SameAs:
return boost::make_shared<TagMatchesSelector>(rule, next, tag, value);
241 case op::LessThen:
return boost::make_shared<TagSmallerSelector>(rule, next, tag, boost::lexical_cast<
int>(value));
242 case op::GreaterThen:
return boost::make_shared<TagLargerSelector>(rule, next, tag, boost::lexical_cast<
int>(value));
243 case op::LessEqual:
return boost::make_shared<TagSmallerEqualsSelector>(rule, next, tag, boost::lexical_cast<
int>(value));
244 case op::GreaterEqual:
return boost::make_shared<TagLargerEqualsSelector>(rule, next, tag, boost::lexical_cast<
int>(value));
246 assert(!
"This binary condition is not implemented!");
249 }
catch (boost::bad_lexical_cast&)
251 LOG_SEV(style_log, warning) <<
"Can not compare non numeric values";
265 switch(condition.which())
274 assert(!
"This is not a condition!");
295 for(
auto it = items.crbegin();
306 zoom.focus(item.
zoom);
308 if(it == items.crend()-1) {
317 rule->first = topmost;
318 rule->setZoomBounds(zoom.bottom, zoom.top);
319 rule->setAcceptableType(acceptableType);
330 LOG_SEV(style_log, warning) <<
"Unsupported attribute '" << attribute <<
"' was ignored!";
352 logger = boost::make_shared<ParserLogger>(path);
353 LOG_SEV(style_log, info) <<
"Load stylesheet[" << path <<
"]";
357 std::ifstream cssStream(path.c_str());
362 LOG_SEV(style_log, warning) <<
"Failed to load stylesheet '" << path <<
"'!";
365 cssStream >> std::noskipws;
368 buffer.reserve(1024 * 8);
370 std::copy(std::istream_iterator<char>(cssStream), std::istream_iterator<char>(), std::back_inserter(buffer));
381 bool r = qi::phrase_parse(position_begin, position_end, mapscc_grammar,
CommentSkipper(), stylesheet);
383 if(!r || position_begin != position_end || !stylesheet)
388 }
catch(
const qi::expectation_failure<GrammarIterator>& e)
390 const classic::file_position_base<std::string>& pos = e.first.get_position();
396 <<
excp::InfoWhat(
"Illegal syntax! Expected valid " + boost::lexical_cast<string>(e.what_) +
"!"));
418 shared_ptr<MapCssParser> parser = boost::make_shared<MapCssParser>(
geodata);
422 if(!timeoutThread.timed_join(boost::posix_time::millisec(timeout)))
428 shared_ptr<Stylesheet> stylesheet = parser->parsedStylesheet;
432 throw parser->catchedException;
435 stylesheet->path = path;
Checks if a value is recognised by a regex.
MapCssParser(const shared_ptr< Geodata > &geodata)
Initializes the parser.
Checks if two values are equal.
Thrown if no more time is left.
SelectorPtr createChildSelectorFromObjectType(const SelectorPtr &next, const shared_ptr< Rule > &rule, obj::ObjectTypeEnum objType)
Creates a selector, selecting children of the specified type.
Checks if a value is greater then another.
fsio::vector< op::UnaryTypesEnum, string > UnaryCondition
Stores informations about an unary condition.
SelectorPtr createSelectorFromBinaryCondition(const SelectorPtr &next, const shared_ptr< Rule > &rule, const BinaryCondition &condition)
Creates a selector using an binary operator.
The grammar for the mapcss format.
Checks if a value is lesser than another.
SelectorPtr createSelectorFromCondition(const SelectorPtr &next, const shared_ptr< Rule > &rule, const ConditionType &condition)
Creates a selector for a given condition.
shared_ptr< Selector > SelectorPtr
Shortcut for a shared pointer to the base of all selectors.
shared_ptr< Geodata > geodata
The geodata used to inject them in the rules.
Thrown if the parsing fails.
boost::error_info< struct TagParserLogger, shared_ptr< ParserLogger > > InfoParserLogger
Contains the logger used while parsing.
Checks if a geoobject has a certain tag.
shared_ptr< Stylesheet > parsedStylesheet
The parsed stylesheet.
Zoom zoom
The zoom which should be selected.
shared_ptr< ApplySelector > ApplySelectorPtr
Shortcut for a shared pointer to thr apply selector.
fsio::vector< string, op::BinaryTypesEnum, string > BinaryCondition
Stores informations about an binary condition.
std::vector< ConditionType > conditions
The condition of the item.
shared_ptr< Rule > RulePtr
Shortcut for a shared pointer to rule.
classic::position_iterator2< StringIterator > GrammarIterator
Iterator wrapping the file iterator and to be used in all grammars.
shared_ptr< StyleTemplate > StylePtr
Shortcut for a shared pointer to style.
#define LOG_SEV(log, lvl)
RulePtr createSelectorChain(const std::vector< SelectorItem > &items)
Creates a chain of selectors from given subselectors.
boost::error_info< struct TagWhatInfo, string > InfoWhat
Use this info to give an what msg to the exception.
const unsigned int & getLine() const
boost::error_info< struct TagFailureLine, int > InfoFailureLine
Specifies the Line in the file where the failure appeared.
SelectorPtr createSelectorFromObjectType(const SelectorPtr &next, const shared_ptr< Rule > &rule, obj::ObjectTypeEnum objType, Rule::AcceptableTypes &type)
Creates an selector used to match geoobject types.
boost::variant< UnaryCondition, BinaryCondition > ConditionType
Possible Conditions.
boost::error_info< struct TagFailureLineContent, string > InfoFailureLineContent
Contains the content of the line where a failure appeared.
void addAttributeToTemplate(StylePtr &style, const shared_ptr< AttributeCreator > &attrType, const string &specifier, const ParseInfo &info)
Converts a given string into a text position.
Thrown if a file was not found.
Checks if a geoobject does not have a certain tag.
Selects lines (unclosed ways)
ObjectTypeEnum
Enum with object selectors.
Checks if two values are not equal.
excp::ParseException catchedException
The exception that may be catched.
Checks if a value is lesser or equal to another.
SelectorPtr createSelectorFromUnaryCondition(const SelectorPtr &next, const shared_ptr< Rule > &rule, const UnaryCondition &condition)
Creates a selector using an unary operator.
string TabToSpace(const string &str)
This file is part of alaCarte.
void applyStyleToRules(std::vector< RulePtr > &rules, const StylePtr &style)
Sets a given style as the style of given rules.
obj::ObjectTypeEnum objectType
The type of the object, which should be selected.
Selects areas (closed ways)
Checks if a value is greater or equal to another.
shared_ptr< ParserLogger > logger
Output logger for errors and warnings.
const unsigned int & getColumn() const
Represents a part of the style selector.
shared_ptr< Stylesheet > StylesheetPtr
Shortcut for a shared pointer to stylesheet.
Simple structure to store a zoom range.
boost::error_info< struct TagFailureColumn, int > InfoFailureColumn
Specifies the Column in the Line in the file where the failure appeared.
static shared_ptr< Stylesheet > Load(const boost::filesystem::path &path, const shared_ptr< Geodata > &geodata, int timeout)
Parses the MapCSS Stylesheet at the given path and returns a new Stylesheet containing the defined ru...
void load(const string &path)
Loads a file from the given path and tries to parse the content into a stylesheet.
const string & getSourceFile() const
void warnUnsupportedAttribute(const string &attribute) const
Emits a warning for unknown mapcss attribute.
boost::error_info< struct TagFileName, string > InfoFileName
Use this to inform about a file name.
const string & getLineContent() const