Exemplo n.º 1
0
    // Gets double value or zero.
    inline double getValue(key_type keyId,
                           double size = 1,
                           const utymap::GeoCoordinate& coordinate = GeoCoordinate()) const
    {
        if (!has(keyId))
            return 0;

        auto declaration = get(keyId);
        auto rawValue = declaration->value();
        char dimen = (*rawValue)[rawValue->size() - 1];

        // in meters
        if (dimen == 'm' && coordinate.isValid()) {
            double value = std::stod(rawValue->substr(0, rawValue->size() - 1));
            return utymap::utils::GeoUtils::getOffset(coordinate, value);
        }

        // relative to size
        if (dimen == '%') {
            double value = std::stod(rawValue->substr(0, rawValue->size() - 1));
            return size * value * 0.01;
        }

        return  declaration->isEval()
                ? declaration->evaluate<double>(tags_, stringTable_)
                : std::stod(*rawValue);
    }
Exemplo n.º 2
0
  T evaluate(const std::vector<utymap::entities::Tag> &tags,
             const utymap::index::StringTable &stringTable) const {
    if (!isEval())
      throw utymap::MapCssException("Cannot evaluate raw value.");

    return StyleEvaluator::evaluate<T>(*tree_, tags, stringTable);
  }
Exemplo n.º 3
0
    // Gets string by given key. Empty string by default
    inline std::shared_ptr<std::string> getString(key_type keyId) const
    {
        if (!has(keyId))
            return std::make_shared<std::string>("");

        auto declaration = get(keyId);

        return declaration->isEval()
               ? std::make_shared<std::string>(declaration->evaluate<std::string>(tags_, stringTable_))
               : declaration->value();
    }