field.hxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef NAMED_VARIABLE_HXX
  2. #define NAMED_VARIABLE_HXX
  3. #include "variable.hxx"
  4. #include "../binom_impl/types.hxx"
  5. namespace binom {
  6. namespace priv {
  7. template<class Driven>
  8. class FieldBase {
  9. Driven& downcast() noexcept {return *reinterpret_cast<Driven*>(this);}
  10. const Driven& downcast() const noexcept {return *reinterpret_cast<const Driven*>(this);}
  11. public:
  12. Variable operator*() noexcept {return downcast().getVariableRef().move();}
  13. Variable* operator->() noexcept {return &downcast().getVariableRef();}
  14. const Variable operator*() const noexcept {return downcast().getVariableRef().move();}
  15. const Variable* operator->() const noexcept {return &downcast().getVariableRef();}
  16. Variable getValue() noexcept {return downcast().getVariableRef().move();}
  17. Variable getKey() noexcept {return downcast().getKeyRef();}
  18. const Variable getValue() const noexcept {return downcast().getVariableRef().move();}
  19. const Variable getKey() const noexcept {return downcast().getKeyRef();}
  20. Variable setValue(Variable value) noexcept {return downcast().setValueImpl(value.move());}
  21. KeyValue setKey(KeyValue key) noexcept {return downcast().setKeyImpl(std::move(key));}
  22. Variable operator=(Variable value) noexcept {return downcast().setValueImpl(value.move());}
  23. };
  24. }
  25. class FieldInit : public priv::FieldBase<FieldInit> {
  26. template<typename Driven>
  27. friend class priv::FieldBase;
  28. friend class priv::MultiMapImplementation;
  29. KeyValue key;
  30. Variable variable;
  31. Variable& getVariableRef() noexcept;
  32. KeyValue& getKeyRef() noexcept;
  33. const Variable& getVariableRef() const noexcept;
  34. const KeyValue& getKeyRef() const noexcept;
  35. Variable setValueImpl(Variable value) noexcept;
  36. KeyValue setKeyImpl(KeyValue key) noexcept;
  37. public:
  38. FieldInit(KeyValue key, Variable variable);
  39. FieldInit(const FieldInit&& named_variable);
  40. template<class FieldInitDriven>
  41. requires extended_type_traits::is_crtp_base_of_v<FieldBase, FieldInitDriven>
  42. FieldInit(const FieldInitDriven& other)
  43. : key(other.getKeyRef()), variable(other.getVariableRef()) {}
  44. template<class FieldInitDriven>
  45. requires extended_type_traits::is_crtp_base_of_v<FieldBase, FieldInitDriven>
  46. FieldInit(FieldInitDriven&& other)
  47. : key(std::move(other.getKeyRef())), variable(std::move(other.getVariableRef())) {}
  48. };
  49. class FieldRef : public priv::FieldBase<FieldRef> {
  50. template<typename Driven> friend class priv::FieldBase;
  51. friend class priv::MapImplementation;
  52. friend class priv::MultiMapImplementation;
  53. friend class priv::TableImplementation;
  54. friend class index::Index;
  55. friend class index::Iterator;
  56. friend class index::ConstIterator;
  57. friend class index::ReverseIterator;
  58. friend class index::ConstReverseIterator;
  59. index::Field* data;
  60. Variable getVariableRef() noexcept;
  61. const Variable getVariableRef() const noexcept;
  62. const KeyValue getKeyRef() const noexcept;
  63. Variable setValueImpl(Variable value) noexcept;
  64. KeyValue setKeyImpl(KeyValue key) noexcept;
  65. FieldRef(const index::Field& data);
  66. public:
  67. FieldRef(decltype (nullptr));
  68. FieldRef(const FieldRef& other);
  69. FieldRef(FieldRef& other);
  70. Variable getOwner();
  71. const Variable getOwner() const;
  72. bool isIndexed() const;
  73. using priv::FieldBase<FieldRef>::operator=;
  74. };
  75. }
  76. #endif // NAMED_VARIABLE_HXX