فهرست منبع

refactor: allow for ContextScope that is otherwise empty

Sam Jaffe 2 سال پیش
والد
کامیت
581f995364
2فایلهای تغییر یافته به همراه7 افزوده شده و 3 حذف شده
  1. 1 0
      include/reflection/context.h
  2. 6 3
      include/reflection/scope.h

+ 1 - 0
include/reflection/context.h

@@ -31,6 +31,7 @@ public:
   bool has(std::string_view id) const { return data_.count(id); }
 
   Object get(ContextScope const &scope) const {
+    if (scope.begin() == scope.end()) { return get(scope.context()); }
     return get(scope.context()).get(static_cast<Scope const &>(scope));
   }
 

+ 6 - 3
include/reflection/scope.h

@@ -22,13 +22,13 @@ public:
   template <typename C, typename = std::enable_if_t<IS_SCOPE_CONTAINER(C)>>
   Scope(std::string const & type_name, C const & path)
       : type_name_(type_name), path_(path.begin(), path.end()) {}
-
-  Scope(std::string const & type_name, std::vector<std::string> const & path)
-      : type_name_(type_name), path_(path) {}
   
   std::string_view type_name() const { return type_name_; }
   auto begin() const { return path_.begin(); }
   auto end() const { return path_.end(); }
+  
+protected:
+  Scope() = default;
 };
 
 class ContextScope : public Scope {
@@ -36,6 +36,9 @@ private:
   std::string context_;
   
 public:
+//  ContextScope() = default;
+  explicit ContextScope(std::string const & type_name) : context_(type_name) {}
+
   template <typename C, typename = std::enable_if_t<IS_SCOPE_CONTAINER(C)>>
   ContextScope(std::string const & context, std::string const & type_name,
                C const & path)