scope.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // scope.h
  3. // reflection
  4. //
  5. // Created by Sam Jaffe on 2/20/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <string>
  10. #include <string_view>
  11. #include <vector>
  12. namespace reflection {
  13. class Scope {
  14. private:
  15. std::string type_name_;
  16. std::vector<std::string> path_;
  17. public:
  18. template <typename C, typename = std::enable_if_t<IS_SCOPE_CONTAINER(C)>>
  19. Scope(std::string const & type_name, C const & path)
  20. : type_name_(type_name), path_(path.begin(), path.end()) {}
  21. Scope(std::string const & type_name, std::vector<std::string> const & path)
  22. : type_name_(type_name), path_(path) {}
  23. std::string_view type_name() const { return type_name_; }
  24. auto begin() const { return path_.begin(); }
  25. auto end() const { return path_.end(); }
  26. };
  27. class ContextScope : public Scope {
  28. private:
  29. std::string context_;
  30. public:
  31. template <typename C, typename = std::enable_if_t<IS_SCOPE_CONTAINER(C)>>
  32. ContextScope(std::string const & context, std::string const & type_name,
  33. C const & path)
  34. : context_(context), Scope(type_name, path) {}
  35. std::string_view context() const { return context_; }
  36. };
  37. }