Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fixup CI compile & clang-tidy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Anand Thakker committed Aug 17, 2017
1 parent 49abc3f commit ce48199
Show file tree
Hide file tree
Showing 18 changed files with 129 additions and 69 deletions.
4 changes: 2 additions & 2 deletions include/mbgl/style/expression/array_assertion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace expression {

class ArrayAssertion : public Expression {
public:
ArrayAssertion(type::Array type, std::unique_ptr<Expression> input_) :
Expression(type),
ArrayAssertion(type::Array type_, std::unique_ptr<Expression> input_) :
Expression(type_),
input(std::move(input_))
{}

Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/style/expression/case.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Case : public Expression {
public:
using Branch = std::pair<std::unique_ptr<Expression>, std::unique_ptr<Expression>>;

Case(type::Type type, std::vector<Branch> cases_, std::unique_ptr<Expression> otherwise_
) : Expression(type),
Case(type::Type type_, std::vector<Branch> cases_, std::unique_ptr<Expression> otherwise_
) : Expression(type_),
cases(std::move(cases_)),
otherwise(std::move(otherwise_))
{}
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/style/expression/coalesce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace expression {
class Coalesce : public Expression {
public:
using Args = std::vector<std::unique_ptr<Expression>>;
Coalesce(const type::Type& type, Args args_) :
Expression(type),
Coalesce(const type::Type& type_, Args args_) :
Expression(type_),
args(std::move(args_))
{}

Expand Down
31 changes: 15 additions & 16 deletions include/mbgl/style/expression/compound_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ struct Signature<R (const EvaluationParameters&, Params...)> : SignatureBase {
if(!arg) return arg.error();
}
// TODO: assert correct runtime type of each arg value
const R& result = evaluate(evaluationParameters, detail::get<Params>(*(evaluated.at(I)))...);
if (!result) return result.error();
return *result;
const R& value = evaluate(evaluationParameters, detail::get<Params>(*(evaluated.at(I)))...);
if (!value) return value.error();
return *value;
}

R (*evaluate)(const EvaluationParameters&, Params...);
Expand Down Expand Up @@ -115,9 +115,9 @@ struct Signature<R (const Varargs<T>&)> : SignatureBase {
if(!evaluatedArg) return evaluatedArg.error();
evaluated.push_back(*evaluatedArg);
}
const R& result = evaluate(evaluated);
if (!result) return result.error();
return *result;
const R& value = evaluate(evaluated);
if (!value) return value.error();
return *value;
}

R (*evaluate)(const Varargs<T>&);
Expand Down Expand Up @@ -154,9 +154,9 @@ struct Signature<R (Params...)> : SignatureBase {
if(!arg) return arg.error();
}
// TODO: assert correct runtime type of each arg value
const R& result = evaluate(detail::get<Params>(*(evaluated.at(I)))...);
if (!result) return result.error();
return *result;
const R& value = evaluate(detail::get<Params>(*(evaluated.at(I)))...);
if (!value) return value.error();
return *value;
}
};

Expand All @@ -173,7 +173,7 @@ struct Signature<R (T::*)(Params...) const>
template <class T, class R, class... Params>
struct Signature<R (T::*)(Params...)>
: Signature<R (Params...)>
{ using Signature<R (T::*)(Params...)>::Signature; };
{ using Signature<R (Params...)>::Signature; };

template <class Lambda>
struct Signature<Lambda, std::enable_if_t<std::is_class<Lambda>::value>>
Expand All @@ -182,14 +182,13 @@ struct Signature<Lambda, std::enable_if_t<std::is_class<Lambda>::value>>

class CompoundExpressionBase : public Expression {
public:
CompoundExpressionBase(std::string name_, type::Type type) :
Expression(std::move(type)),
CompoundExpressionBase(std::string name_, type::Type type_) :
Expression(std::move(type_)),
name(std::move(name_))
{}

std::string getName() { return name; }

virtual ~CompoundExpressionBase() override = default;

private:
std::string name;
};
Expand All @@ -199,10 +198,10 @@ class CompoundExpression : public CompoundExpressionBase {
public:
using Args = typename Signature::Args;

CompoundExpression(const std::string& name,
CompoundExpression(const std::string& name_,
Signature signature_,
typename Signature::Args args_) :
CompoundExpressionBase(name, signature_.result),
CompoundExpressionBase(name_, signature_.result),
signature(signature_),
args(std::move(args_))
{}
Expand Down
6 changes: 3 additions & 3 deletions include/mbgl/style/expression/curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class Curve : public Expression {
public:
using Interpolator = InterpolatorT;

Curve(const type::Type& type,
Curve(const type::Type& type_,
Interpolator interpolator_,
std::unique_ptr<Expression> input_,
std::map<float, std::unique_ptr<Expression>> stops_
) : Expression(type),
) : Expression(type_),
interpolator(std::move(interpolator_)),
input(std::move(input_)),
stops(std::move(stops_))
Expand Down Expand Up @@ -124,7 +124,7 @@ class Curve : public Expression {
}

bool isZoomCurve() const {
if (CompoundExpressionBase* z = dynamic_cast<CompoundExpressionBase*>(input.get())) {
if (auto z = dynamic_cast<CompoundExpressionBase*>(input.get())) {
return z->getName() == "zoom";
}
return false;
Expand Down
10 changes: 8 additions & 2 deletions include/mbgl/style/expression/expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ struct EvaluationError {
};

struct EvaluationParameters {
EvaluationParameters(float zoom_) : zoom(zoom_), feature(nullptr) {}
EvaluationParameters(GeometryTileFeature const * feature_) : zoom(optional<float>()), feature(feature_) {}
EvaluationParameters(float zoom_, GeometryTileFeature const * feature_) :
zoom(zoom_), feature(feature_)
{}

optional<float> zoom;
GeometryTileFeature const * feature = nullptr;
GeometryTileFeature const * feature;
};

template<typename T>
Expand Down Expand Up @@ -76,7 +82,7 @@ struct EvaluationResult : public Result<Value> {

class Expression {
public:
Expression(type::Type type_) : type(type_) {}
Expression(type::Type type_) : type(std::move(type_)) {}
virtual ~Expression() = default;

virtual bool isFeatureConstant() const = 0;
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/expression/literal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace expression {
class Literal : public Expression {
public:
Literal(Value value_) : Expression(typeOf(value_)), value(value_) {}
Literal(type::Array type, std::vector<Value> value_) : Expression(type), value(value_) {}
Literal(type::Array type_, std::vector<Value> value_) : Expression(type_), value(value_) {}
EvaluationResult evaluate(const EvaluationParameters&) const override {
return value;
}
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/style/expression/match.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ class Match : public Expression {
public:
using Cases = std::unordered_map<T, std::shared_ptr<Expression>>;

Match(type::Type type,
Match(type::Type type_,
std::unique_ptr<Expression> input_,
Cases cases_,
std::unique_ptr<Expression> otherwise_
) : Expression(type),
) : Expression(type_),
input(std::move(input_)),
cases(std::move(cases_)),
otherwise(std::move(otherwise_))
Expand Down
4 changes: 2 additions & 2 deletions include/mbgl/style/expression/parse/curve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace expression {
namespace detail {

// used for storing intermediate state during parsing
struct ExponentialInterpolation { float base; std::string name = "exponential"; };
struct ExponentialInterpolation { float base; std::string name; };
struct StepInterpolation {};

} // namespace detail
Expand Down Expand Up @@ -59,7 +59,7 @@ struct ParseCurve {
ctx.error("Exponential interpolation requires a numeric base.");
return ParseResult();
}
interpolation = detail::ExponentialInterpolation { static_cast<float>(*base) };
interpolation = detail::ExponentialInterpolation { static_cast<float>(*base), "exponential" };
} else {
ctx.error("Unknown interpolation type " + (interpName ? *interpName : ""));
return ParseResult();
Expand Down
1 change: 0 additions & 1 deletion include/mbgl/style/expression/value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ std::string stringify(const Value& value);
template <typename T>
type::Type valueTypeToExpressionType();


} // namespace expression
} // namespace style
} // namespace mbgl
2 changes: 1 addition & 1 deletion include/mbgl/style/function/camera_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CameraFunction {
{}

T evaluate(float zoom) const {
auto result = expression->evaluate<T>(expression::EvaluationParameters { zoom });
auto result = expression->evaluate<T>(expression::EvaluationParameters(zoom, nullptr));
if (!result) return T();
return *result;
}
Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/function/composite_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class CompositeFunction {

template <class Feature>
T evaluate(float zoom, const Feature& feature, T finalDefaultValue) const {
auto result = expression->evaluate<T>(expression::EvaluationParameters { {zoom}, &feature });
auto result = expression->evaluate<T>(expression::EvaluationParameters({zoom}, &feature));
if (!result) {
return finalDefaultValue;
}
Expand Down
3 changes: 2 additions & 1 deletion include/mbgl/style/function/convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ class ErrorExpression : public Expression {
std::string message;
};

}
} // namespace detail


// Create expressions representing 'classic' (i.e. stop-based) style functions

Expand Down
2 changes: 1 addition & 1 deletion include/mbgl/style/function/source_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SourceFunction {

template <class Feature>
T evaluate(const Feature& feature, T finalDefaultValue) const {
auto result = expression->evaluate<T>(expression::EvaluationParameters { optional<float>(), &feature });
auto result = expression->evaluate<T>(expression::EvaluationParameters(&feature));
if (!result) {
return finalDefaultValue;
}
Expand Down
11 changes: 9 additions & 2 deletions platform/darwin/src/MGLConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,15 @@ inline OptionalNSObjectValue objectMember(const id value, const char *key) {
}
}

// Not implemented (unneeded for MGLStyleFunction conversion):
// optional<Error> eachMember(const NSObject*, Fn&&)
inline optional<Error> eachMember(const id value, std::function<optional<Error>(const std::string&, const id)> Fn) {
NSCAssert([value isKindOfClass:[NSDictionary class]], @"Value must be an NSDictionary for get(string).");
for (NSString* key in value) {
const id member = [value objectForKey: key];
optional<Error> err = Fn(std::string(static_cast<const char *>([value UTF8String])), member);
if (err) return err;
}
return optional<Error>();
}

inline bool _isBool(const id value) {
if (![value isKindOfClass:[NSNumber class]]) return false;
Expand Down
10 changes: 7 additions & 3 deletions src/mbgl/style/expression/compound_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ static std::pair<std::string, Definition> define(std::string name, Evals... eval
expand_pack(definition.push_back(std::make_unique<Signature<Evals>>(evalFunctions)));
const auto& t0 = definition.at(0)->result;
for (const auto& signature : definition) {
// TODO replace with real ==
assert(toString(t0) == toString(signature->result));
assert(t0 == signature->result);
(void)signature;
(void)t0;
}
return std::pair<std::string, Definition>(name, std::move(definition));
}
Expand All @@ -61,7 +62,10 @@ static std::pair<std::string, Definition> defineFeatureFunction(std::string name
const auto& t0 = definition.at(0)->result;
for (const auto& signature : definition) {
// TODO replace with real ==
assert(toString(t0) == toString(signature->result));
assert(t0 == signature->result);
(void)signature;
(void)t0;

}
return std::pair<std::string, Definition>(name, std::move(definition));
}
Expand Down
96 changes: 70 additions & 26 deletions src/mbgl/style/expression/value.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,36 +268,80 @@ template <> type::Type valueTypeToExpressionType<std::vector<Value>>() { return

template Value toExpressionValue(const mbgl::Value&);

// instantiate templates fromExpressionValue<T>, toExpressionValue<T>, and valueTypeToExpressionType<T>
template <typename T>
struct instantiate {
void noop(const T& t) {
fromExpressionValue<T>(toExpressionValue(t));
valueTypeToExpressionType<T>();
}
};

// for to_rgba expression
template struct instantiate<std::array<double, 4>>;
template type::Type valueTypeToExpressionType<std::array<double, 4>>();
template optional<std::array<double, 4>> fromExpressionValue<std::array<double, 4>>(const Value&);
template Value toExpressionValue(const std::array<double, 4>&);

// layout/paint property types
template struct instantiate<float>;
template struct instantiate<std::array<float, 2>>;
template struct instantiate<std::array<float, 4>>;
template struct instantiate<std::vector<float>>;
template struct instantiate<std::vector<std::string>>;
template struct instantiate<AlignmentType>;
template struct instantiate<CirclePitchScaleType>;
template struct instantiate<IconTextFitType>;
template struct instantiate<LineCapType>;
template struct instantiate<LineJoinType>;
template struct instantiate<SymbolPlacementType>;
template struct instantiate<TextAnchorType>;
template struct instantiate<TextJustifyType>;
template struct instantiate<TextTransformType>;
template struct instantiate<TranslateAnchorType>;
template struct instantiate<LightAnchorType>;
template struct instantiate<Position>;
template type::Type valueTypeToExpressionType<float>();
template optional<float> fromExpressionValue<float>(const Value&);
template Value toExpressionValue(const float&);

template type::Type valueTypeToExpressionType<std::array<float, 2>>();
template optional<std::array<float, 2>> fromExpressionValue<std::array<float, 2>>(const Value&);
template Value toExpressionValue(const std::array<float, 2>&);

template type::Type valueTypeToExpressionType<std::array<float, 4>>();
template optional<std::array<float, 4>> fromExpressionValue<std::array<float, 4>>(const Value&);
template Value toExpressionValue(const std::array<float, 4>&);

template type::Type valueTypeToExpressionType<std::vector<float>>();
template optional<std::vector<float>> fromExpressionValue<std::vector<float>>(const Value&);
template Value toExpressionValue(const std::vector<float>&);

template type::Type valueTypeToExpressionType<std::vector<std::string>>();
template optional<std::vector<std::string>> fromExpressionValue<std::vector<std::string>>(const Value&);
template Value toExpressionValue(const std::vector<std::string>&);

template type::Type valueTypeToExpressionType<AlignmentType>();
template optional<AlignmentType> fromExpressionValue<AlignmentType>(const Value&);
template Value toExpressionValue(const AlignmentType&);

template type::Type valueTypeToExpressionType<CirclePitchScaleType>();
template optional<CirclePitchScaleType> fromExpressionValue<CirclePitchScaleType>(const Value&);
template Value toExpressionValue(const CirclePitchScaleType&);

template type::Type valueTypeToExpressionType<IconTextFitType>();
template optional<IconTextFitType> fromExpressionValue<IconTextFitType>(const Value&);
template Value toExpressionValue(const IconTextFitType&);

template type::Type valueTypeToExpressionType<LineCapType>();
template optional<LineCapType> fromExpressionValue<LineCapType>(const Value&);
template Value toExpressionValue(const LineCapType&);

template type::Type valueTypeToExpressionType<LineJoinType>();
template optional<LineJoinType> fromExpressionValue<LineJoinType>(const Value&);
template Value toExpressionValue(const LineJoinType&);

template type::Type valueTypeToExpressionType<SymbolPlacementType>();
template optional<SymbolPlacementType> fromExpressionValue<SymbolPlacementType>(const Value&);
template Value toExpressionValue(const SymbolPlacementType&);

template type::Type valueTypeToExpressionType<TextAnchorType>();
template optional<TextAnchorType> fromExpressionValue<TextAnchorType>(const Value&);
template Value toExpressionValue(const TextAnchorType&);

template type::Type valueTypeToExpressionType<TextJustifyType>();
template optional<TextJustifyType> fromExpressionValue<TextJustifyType>(const Value&);
template Value toExpressionValue(const TextJustifyType&);

template type::Type valueTypeToExpressionType<TextTransformType>();
template optional<TextTransformType> fromExpressionValue<TextTransformType>(const Value&);
template Value toExpressionValue(const TextTransformType&);

template type::Type valueTypeToExpressionType<TranslateAnchorType>();
template optional<TranslateAnchorType> fromExpressionValue<TranslateAnchorType>(const Value&);
template Value toExpressionValue(const TranslateAnchorType&);

template type::Type valueTypeToExpressionType<LightAnchorType>();
template optional<LightAnchorType> fromExpressionValue<LightAnchorType>(const Value&);
template Value toExpressionValue(const LightAnchorType&);

template type::Type valueTypeToExpressionType<Position>();
template optional<Position> fromExpressionValue<Position>(const Value&);
template Value toExpressionValue(const Position&);

} // namespace expression
} // namespace style
Expand Down
Loading

0 comments on commit ce48199

Please sign in to comment.