made visit() and all getters private in all stores

This commit is contained in:
silverqx
2023-07-03 10:17:01 +02:00
parent 3f9266275f
commit e40284fde1
5 changed files with 31 additions and 18 deletions
@@ -21,9 +21,6 @@ TINYORM_BEGIN_COMMON_NAMESPACE
namespace Orm::Tiny::Concerns
{
template<typename Derived, AllRelationsConcept ...AllRelations>
class HasRelationships;
// FUTURE relationstore, cache results, eg. cache Relation instance and return copy of this cached Relation instance, Related parameter can be obtained from cached Relation instance silverqx
/*! Relation store, handles mapping from a relation name to the Model's relation
method, also calls visited method with Related parameter when needed. */
@@ -17,6 +17,9 @@ namespace Concerns
{
template<typename Derived, AllRelationsConcept ...AllRelations>
class HasRelationStore;
template<typename Derived, AllRelationsConcept ...AllRelations>
class HasRelationships;
}
namespace Relations
{
@@ -82,6 +85,8 @@ namespace Support::Stores
{
Q_DISABLE_COPY(BaseRelationStore)
// To access visit()
friend Concerns::HasRelationships<Derived, AllRelations...>;
// To access operator()
friend Derived;
@@ -95,6 +100,9 @@ namespace Support::Stores
TINY_RELATIONSTORES_ALIASES
// To access visit()
friend BelongsToManyRelatedTableStore;
protected:
/*! Constructor. */
BaseRelationStore(NotNull<HasRelationStore *> hasRelationStore,
@@ -104,9 +112,6 @@ namespace Support::Stores
/*! Default destructor. */
inline ~BaseRelationStore() = default;
/*! Visit the given relation. */
void visit(const QString &relation);
protected:
/*! Called from Model::u_relations to pass reference to the relation method,
an enter point of the visitation. */
@@ -116,9 +121,6 @@ namespace Support::Stores
/*! Currently held store type. */
inline RelationStoreType getStoreType() const noexcept;
/*! Reference to the parent HasRelationStore instance. */
NotNull<HasRelationStore *> m_hasRelationStore;
/* Static cast this to a child's instance type (CRTP) */
/*! Static cast this to a child's instance type (CRTP). */
inline Derived &model() noexcept;
@@ -131,6 +133,11 @@ namespace Support::Stores
inline const Model<Derived, AllRelations...> &basemodel() const noexcept;
private:
/*! Visit the given relation. */
void visit(const QString &relation);
/*! Reference to the parent HasRelationStore instance. */
NotNull<HasRelationStore *> m_hasRelationStore;
/*! Store type held by relation store. */
/*const*/ RelationStoreType m_storeType;
};
@@ -148,12 +155,6 @@ namespace Support::Stores
/* public */
template<typename Derived, AllRelationsConcept ...AllRelations>
void BaseRelationStore<Derived, AllRelations...>::visit(const QString &relation)
{
std::invoke(basemodel().getUserRelations().find(relation).value(), *this);
}
template<typename Derived, AllRelationsConcept ...AllRelations>
template<RelationshipMethod<Derived> Method>
void BaseRelationStore<Derived, AllRelations...>::operator()(const Method method)
@@ -266,6 +267,14 @@ namespace Support::Stores
return m_hasRelationStore->basemodel();
}
/* private */
template<typename Derived, AllRelationsConcept ...AllRelations>
void BaseRelationStore<Derived, AllRelations...>::visit(const QString &relation)
{
std::invoke(basemodel().getUserRelations().find(relation).value(), *this);
}
} // namespace Support::Stores
} // namespace Orm::Tiny
@@ -28,6 +28,9 @@ namespace Support::Stores
{
Q_DISABLE_COPY(BelongsToManyRelatedTableStore)
// To access visitWithResult()
friend Concerns::HasRelationships<Derived, AllRelations...>;
/*! Alias for the helper utils. */
using Helpers = Orm::Utils::Helpers;
/*! Alias for the NotNull. */
@@ -49,10 +52,10 @@ namespace Support::Stores
/*! Default destructor. */
inline ~BelongsToManyRelatedTableStore() = default;
private:
/*! Visit the given relation and return a result. */
std::optional<QString> visitWithResult(const QString &relation);
private:
/*! Method called after visitation. */
template<RelationshipMethod<Derived> Method>
void visited(Method /*unused*/);
@@ -18,6 +18,8 @@ namespace Orm::Tiny::Support::Stores
{
Q_DISABLE_COPY(LazyRelationStore)
// To access result()
friend Concerns::HasRelationships<Derived, AllRelations...>;
/*! Alias for the NotNull. */
template<typename T>
using NotNull = Orm::Utils::NotNull<T>;
@@ -36,11 +38,11 @@ namespace Orm::Tiny::Support::Stores
/*! Default destructor. */
inline ~LazyRelationStore() = default;
private:
/*! Get the result of lazy load. */
inline const std::variant<ModelsCollection<Related>, std::optional<Related>> &
result() const noexcept;
private:
/*! Method called after visitation. */
template<RelationshipMethod<Derived> Method>
void visited(Method method);
@@ -18,6 +18,8 @@ namespace Orm::Tiny::Support::Stores
{
Q_DISABLE_COPY(PushRelationStore)
// To access result(), setResult(), and models()
friend Concerns::HasRelationships<Derived, AllRelations...>;
/*! Alias for the NotNull. */
template<typename T>
using NotNull = Orm::Utils::NotNull<T>;
@@ -37,6 +39,7 @@ namespace Orm::Tiny::Support::Stores
/*! Default destructor. */
inline ~PushRelationStore() = default;
private:
/*! Get the result of a push. */
inline bool result() const noexcept;
/*! Set the result of a push. */
@@ -45,7 +48,6 @@ namespace Orm::Tiny::Support::Stores
/*! Get models to push, the reference to the relation in the m_relations hash. */
inline RelationsType<AllRelations...> &models() const noexcept;
private:
/*! Method called after visitation. */
template<RelationshipMethod<Derived> Method>
void visited(Method /*unused*/) const;