Sfoglia il codice sorgente

refactor: rename ContextStack<A,B,C> -> DynamicReferenceContext

Sam Jaffe 1 anno fa
parent
commit
7cd79a147a

+ 10 - 7
include/jvalidate/detail/context_stack.h

@@ -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;

+ 2 - 2
include/jvalidate/detail/reference_manager.h

@@ -6,7 +6,7 @@
 #include <unordered_map>
 
 #include <jvalidate/detail/anchor.h>
-#include <jvalidate/detail/context_stack.h>
+#include <jvalidate/detail/dynamic_reference_context.h>
 #include <jvalidate/detail/on_block_exit.h>
 #include <jvalidate/detail/out.h>
 #include <jvalidate/detail/parser_context.h>
@@ -29,7 +29,7 @@ private:
 
   std::map<RootReference, A> roots_;
 
-  ContextStack<URI, Anchor, Reference> active_dynamic_anchors_;
+  DynamicReferenceContext active_dynamic_anchors_;
   std::map<URI, std::map<Anchor, Reference>> dynamic_anchors_;
 
 public: