diff --git a/include/matador/object/collection_proxy.hpp b/include/matador/object/collection_proxy.hpp index 6b9ca45..791aae3 100644 --- a/include/matador/object/collection_proxy.hpp +++ b/include/matador/object/collection_proxy.hpp @@ -24,7 +24,9 @@ struct relation_iterator_traits; template < typename Type, typename OwnerType > struct relation_iterator_traits> { - + static Type& value(relation& re) { + return re.relation().value(); + } }; template @@ -33,6 +35,7 @@ public: using value_type = Type; using reference = Type&; using pointer = Type*; + using relation_type = RelationType; using iterator_category = std::forward_iterator_tag; collection_proxy_iterator() = default; @@ -52,6 +55,9 @@ public: return !operator==(other); } + relation_type& relation() { + return *it_; + } private: typename std::vector::iterator it_; }; @@ -70,13 +76,10 @@ public: virtual iterator begin() = 0; virtual iterator end() = 0; - virtual const_iterator begin() const = 0; - virtual const_iterator end() const = 0; - [[nodiscard]] virtual size_t size() const = 0; - [[nodiscard]] virtual bool empty() const = 0; -// virtual collection_proxy_iterator begin() = 0; -// virtual collection_proxy_iterator end() = 0; + [[nodiscard]] virtual size_t size() = 0; + [[nodiscard]] virtual bool empty() = 0; + [[nodiscard]] virtual const utils::identifier& owner_id() const = 0; protected: @@ -117,23 +120,19 @@ public: return items_.end(); } - const_iterator begin() const override { + void push_back(const value_type& value) override { resolve(); - return items_.begin(); + items_.push_back(value); + } + [[nodiscard]] size_t size() override { + resolve(); + return items_.size(); + } + [[nodiscard]] bool empty() override { + resolve(); + return items_.empty(); } - const_iterator end() const override { - resolve(); - return items_.end(); - } - // const std::vector& items() const { - // resolve(); - // return items_; - // } - // std::vector& items() { - // resolve(); - // return items_; - // } private: void resolve() { if (loaded_) { diff --git a/test/core/CMakeLists.txt b/test/core/CMakeLists.txt index e17f760..9a75a91 100644 --- a/test/core/CMakeLists.txt +++ b/test/core/CMakeLists.txt @@ -5,6 +5,7 @@ list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) add_executable(CoreTests ../backends/SchemaFixture.hpp logger/LoggerTest.cpp + object/CollectionTest.cpp object/ObjectCacheTest.cpp object/ObjectTest.cpp object/PrimaryKeyResolverTest.cpp diff --git a/test/core/object/CollectionTest.cpp b/test/core/object/CollectionTest.cpp new file mode 100644 index 0000000..015e0ae --- /dev/null +++ b/test/core/object/CollectionTest.cpp @@ -0,0 +1,7 @@ +#include + +#include "matador/object/collection.hpp" +#include "matador/object/object.hpp" + +TEST_CASE("Test collection", "[collection]") { +} \ No newline at end of file