18 template <
typename SchemaType>
24class RelationCollection
28 using container_type = std::vector<T>;
29 using size_type =
typename container_type::size_type;
30 using iterator =
typename container_type::iterator;
31 using const_iterator =
typename container_type::const_iterator;
33 RelationCollection() =
default;
35 RelationCollection(
const RelationCollection& other)
36 : values_(not other.values_ ? nullptr : std::make_shared<container_type>(*other.values_)),
37 loaded_(other.loaded_)
41 auto operator=(
const RelationCollection& other) -> RelationCollection&
49 not other.values_ ? std::shared_ptr<container_type>{} : std::make_shared<container_type>(*other.values_);
50 values_ = std::move(copiedValues);
51 loaded_ = other.loaded_;
55 RelationCollection(RelationCollection&&) noexcept = default;
56 auto operator=(RelationCollection&&) noexcept -> RelationCollection& = default;
58 explicit RelationCollection(container_type values)
59 : values_(std::make_shared<container_type>(std::move(values))), loaded_(true)
63 [[nodiscard]]
auto isLoaded() const noexcept ->
bool
68 auto values() -> container_type&
70 return mutableValues();
73 auto values() const -> const container_type&
75 return readableValues();
78 auto begin() -> iterator
80 return values().begin();
83 auto begin() const -> const_iterator
85 return values().begin();
88 auto cbegin() const -> const_iterator
90 return values().cbegin();
93 auto end() -> iterator
95 return values().end();
98 auto end() const -> const_iterator
100 return values().end();
103 auto cend() const -> const_iterator
105 return values().cend();
108 [[nodiscard]]
auto size() const noexcept -> size_type
110 return not values_ ? 0 : values_->size();
113 [[nodiscard]]
auto empty() const noexcept ->
bool
115 return not values_ or values_->empty();
118 auto operator[](size_type index) -> T&
120 return values()[index];
123 auto operator[](size_type index)
const ->
const T&
125 return values()[index];
129 friend class orm::Database;
131 friend class orm::OrmContext;
133 auto setLoaded(container_type values) ->
void
135 values_ = std::make_shared<container_type>(std::move(values));
139 auto mutableValues() -> container_type&
143 values_ = std::make_shared<container_type>();
149 auto readableValues() const -> const container_type&
153 values_ = std::make_shared<container_type>();
159 mutable std::shared_ptr<container_type> values_;
167 template <
typename T>
168 class OneToMany :
public detail::RelationCollection<T>
171 using detail::RelationCollection<T>::RelationCollection;
174 template <
typename T>
175 class ManyToMany :
public detail::RelationCollection<T>
178 using detail::RelationCollection<T>::RelationCollection;
184struct RelationCollectionTraits
186 inline static constexpr bool isCollection =
false;
187 inline static constexpr bool isOneToMany =
false;
192struct RelationCollectionTraits<
OneToMany<T>>
194 inline static constexpr bool isCollection =
true;
195 inline static constexpr bool isOneToMany =
true;
202 inline static constexpr bool isCollection =
true;
203 inline static constexpr bool isOneToMany =
false;
208inline constexpr bool isRelationCollection = RelationCollectionTraits<std::remove_cv_t<T>>::isCollection;
211struct OptionalRelationCollectionTraits
213 inline static constexpr bool value =
false;
217struct OptionalRelationCollectionTraits<std::optional<T>>
219 inline static constexpr bool value = isRelationCollection<T>;
223inline constexpr bool isOptionalRelationCollection = OptionalRelationCollectionTraits<std::remove_cv_t<T>>::value;
229 template <
typename T>
232 template <
typename T>
234 detail::isOptionalRelationCollection<std::remove_cvref_t<T>>;
236 template <
typename T>
237 using relation_target_t =
typename detail::RelationCollectionTraits<std::remove_cvref_t<T>>::Target;
239 template <
typename T>
typename detail::RelationCollectionTraits< std::remove_cvref_t< T > >::Target relation_target_t
constexpr bool is_one_to_many_v
constexpr bool is_relation_collection_v
constexpr bool is_optional_relation_collection_v