Skip to content

Commit

Permalink
made visit() and all getters private in all stores
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Jul 3, 2023
1 parent 3f92662 commit e40284f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
3 changes: 0 additions & 3 deletions include/orm/tiny/concerns/hasrelationstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
33 changes: 21 additions & 12 deletions include/orm/tiny/support/stores/baserelationstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ namespace Concerns
{
template<typename Derived, AllRelationsConcept ...AllRelations>
class HasRelationStore;

template<typename Derived, AllRelationsConcept ...AllRelations>
class HasRelationships;
}
namespace Relations
{
Expand Down Expand Up @@ -82,6 +85,8 @@ namespace Support::Stores
{
Q_DISABLE_COPY(BaseRelationStore)

// To access visit()
friend Concerns::HasRelationships<Derived, AllRelations...>;
// To access operator()
friend Derived;

Expand All @@ -95,6 +100,9 @@ namespace Support::Stores

TINY_RELATIONSTORES_ALIASES

// To access visit()
friend BelongsToManyRelatedTableStore;

protected:
/*! Constructor. */
BaseRelationStore(NotNull<HasRelationStore *> hasRelationStore,
Expand All @@ -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. */
Expand All @@ -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;
Expand All @@ -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;
};
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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*/);
Expand Down
4 changes: 3 additions & 1 deletion include/orm/tiny/support/stores/lazyrelationstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion include/orm/tiny/support/stores/pushrelationstore.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -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. */
Expand All @@ -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;
Expand Down

0 comments on commit e40284f

Please sign in to comment.