|
|
@@ -4,16 +4,19 @@
|
|
|
#include <map>
|
|
|
#include <optional>
|
|
|
|
|
|
+#include <jvalidate/detail/anchor.h>
|
|
|
#include <jvalidate/detail/on_block_exit.h>
|
|
|
+#include <jvalidate/detail/reference.h>
|
|
|
+#include <jvalidate/uri.h>
|
|
|
|
|
|
namespace jvalidate::detail {
|
|
|
-template <typename Source, typename Key, typename Value> class ContextStack {
|
|
|
+class DynamicReferenceContext {
|
|
|
private:
|
|
|
- std::deque<Source> sources_;
|
|
|
- std::map<Key, std::deque<std::optional<Value>>> data_;
|
|
|
+ std::deque<URI> sources_;
|
|
|
+ std::map<Anchor, std::deque<std::optional<Reference>>> data_;
|
|
|
|
|
|
public:
|
|
|
- OnBlockExit scope(Source const & source, std::map<Key, Value> const & frame) {
|
|
|
+ OnBlockExit scope(URI const & source, std::map<Anchor, Reference> const & frame) {
|
|
|
if (frame.empty() && data_.empty()) {
|
|
|
return nullptr;
|
|
|
}
|
|
|
@@ -45,16 +48,16 @@ public:
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- bool contains(Key const & key) const { return data_.contains(key); }
|
|
|
+ bool contains(Anchor const & key) const { return data_.contains(key); }
|
|
|
|
|
|
- std::optional<Value> lookup(Source const & source, Key const & key) const {
|
|
|
+ std::optional<Reference> lookup(URI const & source, Anchor const & key) const {
|
|
|
if (auto it = data_.find(key); it != data_.end()) {
|
|
|
return it->second.at(index_of(source));
|
|
|
}
|
|
|
return std::nullopt;
|
|
|
}
|
|
|
|
|
|
- size_t index_of(Source const & source) const {
|
|
|
+ size_t index_of(URI const & source) const {
|
|
|
for (size_t i = sources_.size(); i-- > 0;) {
|
|
|
if (sources_[i] == source) {
|
|
|
return i;
|