Allow passing a dynamic context to render().
This commit is contained in:
parent
647b282b26
commit
3374f41e87
3 changed files with 27 additions and 0 deletions
|
@ -16,6 +16,23 @@ struct config {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
|
template<class N>
|
||||||
|
class dynamic_t {
|
||||||
|
public:
|
||||||
|
virtual ~dynamic_t() = default;
|
||||||
|
const N& at (const std::string& name) const {
|
||||||
|
cache = this->get_value(name);
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
bool has(const std::string& name) const {
|
||||||
|
return this->has_value(name);
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
virtual N get_value(const std::string& name) const = 0;
|
||||||
|
virtual bool has_value(const std::string& name) const = 0;
|
||||||
|
mutable N cache;
|
||||||
|
};
|
||||||
|
|
||||||
template<class N>
|
template<class N>
|
||||||
class object_t {
|
class object_t {
|
||||||
public:
|
public:
|
||||||
|
@ -97,9 +114,11 @@ using node = boost::make_recursive_variant<
|
||||||
std::nullptr_t, std::string, int, double, bool,
|
std::nullptr_t, std::string, int, double, bool,
|
||||||
internal::lambda_t<boost::recursive_variant_>,
|
internal::lambda_t<boost::recursive_variant_>,
|
||||||
std::shared_ptr<internal::object_t<boost::recursive_variant_>>,
|
std::shared_ptr<internal::object_t<boost::recursive_variant_>>,
|
||||||
|
std::shared_ptr<internal::dynamic_t<boost::recursive_variant_>>,
|
||||||
std::map<const std::string, boost::recursive_variant_>,
|
std::map<const std::string, boost::recursive_variant_>,
|
||||||
std::vector<boost::recursive_variant_>>::type;
|
std::vector<boost::recursive_variant_>>::type;
|
||||||
using object = internal::object_t<node>;
|
using object = internal::object_t<node>;
|
||||||
|
using dynamic = internal::dynamic_t<node>;
|
||||||
using lambda = internal::lambda_t<node>;
|
using lambda = internal::lambda_t<node>;
|
||||||
using map = std::map<const std::string, node>;
|
using map = std::map<const std::string, node>;
|
||||||
using array = std::vector<node>;
|
using array = std::vector<node>;
|
||||||
|
|
|
@ -27,6 +27,10 @@ class get_token: public boost::static_visitor<const mstch::node&> {
|
||||||
return object->at(m_token);
|
return object->at(m_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const mstch::node& operator()(const std::shared_ptr<dynamic>& object) const {
|
||||||
|
return object->at(m_token);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string& m_token;
|
const std::string& m_token;
|
||||||
const mstch::node& m_node;
|
const mstch::node& m_node;
|
||||||
|
|
|
@ -24,6 +24,10 @@ class has_token: public boost::static_visitor<bool> {
|
||||||
return object->has(m_token);
|
return object->has(m_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator()(const std::shared_ptr<dynamic>& object) const {
|
||||||
|
return object->has(m_token);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string& m_token;
|
const std::string& m_token;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue