This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] Initial implementation of 'format' expression
- Loading branch information
Showing
62 changed files
with
970 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -133,6 +133,7 @@ enum class Kind : int32_t { | |
Any, | ||
All, | ||
Comparison, | ||
FormatExpression, | ||
}; | ||
|
||
class Expression { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
|
||
#include <mbgl/style/expression/expression.hpp> | ||
#include <mbgl/style/expression/formatted.hpp> | ||
#include <mbgl/style/expression/parsing_context.hpp> | ||
#include <mbgl/style/conversion.hpp> | ||
|
||
#include <memory> | ||
|
||
namespace mbgl { | ||
namespace style { | ||
namespace expression { | ||
|
||
struct FormatExpressionSection { | ||
FormatExpressionSection(std::unique_ptr<Expression> text_, | ||
optional<std::unique_ptr<Expression>> fontScale_, | ||
optional<std::unique_ptr<Expression>> textFont_); | ||
|
||
std::shared_ptr<Expression> text; | ||
optional<std::shared_ptr<Expression>> fontScale; | ||
optional<std::shared_ptr<Expression>> textFont; | ||
}; | ||
|
||
class FormatExpression : public Expression { | ||
public: | ||
FormatExpression(std::vector<FormatExpressionSection> sections); | ||
|
||
EvaluationResult evaluate(const EvaluationContext&) const override; | ||
static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); | ||
|
||
void eachChild(const std::function<void(const Expression&)>&) const override; | ||
|
||
bool operator==(const Expression& e) const override; | ||
|
||
std::vector<optional<Value>> possibleOutputs() const override { | ||
// Technically the combinatoric set of all children | ||
// Usually, this.text will be undefined anyway | ||
return { nullopt }; | ||
} | ||
|
||
mbgl::Value serialize() const override; | ||
std::string getOperator() const override { return "format"; } | ||
private: | ||
std::vector<FormatExpressionSection> sections; | ||
std::unique_ptr<Expression> text; | ||
optional<std::unique_ptr<Expression>> fontScale; | ||
optional<std::unique_ptr<Expression>> textFont; | ||
}; | ||
|
||
} // namespace expression | ||
} // namespace style | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#pragma once | ||
|
||
#include <mbgl/style/conversion.hpp> | ||
#include <mbgl/util/font_stack.hpp> | ||
#include <mbgl/util/optional.hpp> | ||
#include <mbgl/util/variant.hpp> | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
namespace mbgl { | ||
namespace style { | ||
namespace expression { | ||
|
||
struct FormattedSection { | ||
FormattedSection(std::string text_, optional<double> fontScale_, optional<FontStack> fontStack_) | ||
: text(std::move(text_)) | ||
, fontScale(std::move(fontScale_)) | ||
, fontStack(std::move(fontStack_)) | ||
{} | ||
std::string text; | ||
optional<double> fontScale; | ||
optional<FontStack> fontStack; | ||
}; | ||
|
||
class Formatted { | ||
public: | ||
Formatted() {} | ||
|
||
Formatted(const char* plainU8String) { | ||
sections.emplace_back(std::string(plainU8String), nullopt, nullopt); | ||
} | ||
|
||
Formatted(std::vector<FormattedSection> sections_) | ||
: sections(std::move(sections_)) | ||
{} | ||
|
||
bool operator==(const Formatted& ) const; | ||
|
||
std::string toString() const; | ||
|
||
bool empty() const { | ||
return sections.empty(); | ||
} | ||
|
||
std::vector<FormattedSection> sections; | ||
}; | ||
|
||
} // namespace expression | ||
|
||
namespace conversion { | ||
|
||
template <> | ||
struct Converter<mbgl::style::expression::Formatted> { | ||
public: | ||
optional<mbgl::style::expression::Formatted> operator()(const Convertible& value, Error& error) const; | ||
}; | ||
|
||
} // namespace conversion | ||
|
||
} // namespace style | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.