QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxDataMemberX.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_DATA_MEMBER_X_H_
33#define _QX_DATA_MEMBER_X_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
50
51#include <QxDao/QxSqlRelation.h>
52
54
55#include <QxFactory/QxFactory.h>
56
61
62namespace qx {
63
68template <class T>
69class QxDataMemberX : public IxDataMemberX, public QxSingleton< QxDataMemberX<T> >
70{
71
72 friend class QxSingleton< QxDataMemberX<T> >;
73
74public:
75
78
79protected:
80
81 QxDataMemberX() : IxDataMemberX(), QxSingleton< QxDataMemberX<T> >(QString("qx::QxDataMemberX_") + qx::trait::get_class_name<T>::get_xml_tag()) { ; }
82 virtual ~QxDataMemberX() { ; }
83
84public:
85
86 virtual long count_WithDaoStrategy() const { return count_WithDaoStrategy_Helper(); }
87 virtual bool exist_WithDaoStrategy(const QString & sKey) const { return exist_WithDaoStrategy_Helper(sKey); }
88 virtual IxDataMember * get_WithDaoStrategy(long lIndex) const { return get_WithDaoStrategy_Helper(lIndex); }
89 virtual IxDataMember * get_WithDaoStrategy(const QString & sKey) const { return get_WithDaoStrategy_Helper(sKey); }
91
92 IxDataMember * id(type_primary_key T::* pDataMemberId, const QString & sKey, long lVersion = 0);
93 IxDataMember * id(const QString & sKey, long lVersion);
94 IxDataMember * add(const QString & sKey, long lVersion);
95
96 template <typename V, typename U> IxDataMember * add(V U::* pData, const QString & sKey, long lVersion = 0, bool bSerialize = true, bool bDao = true);
97 template <typename V, typename U> IxSqlRelation * relationOneToOne(V U::* pData, const QString & sKey, long lVersion = 0);
98 template <typename V, typename U> IxSqlRelation * relationManyToOne(V U::* pData, const QString & sKey, long lVersion = 0);
99 template <typename V, typename U> IxSqlRelation * relationOneToMany(V U::* pData, const QString & sKey, const QString & sForeignKey, long lVersion = 0);
100 template <typename V, typename U> IxSqlRelation * relationManyToMany(V U::* pData, const QString & sKey, const QString & sExtraTable, const QString & sForeignKeyOwner, const QString & sForeignKeyDataType, long lVersion = 0);
101
102 template <typename V, typename U> IxDataMember * pimpl(V U::* pData, const QString & sKey);
103 template <typename U> IxDataMember * id(type_primary_key U::* pDataMemberId, const QString & sKey, long lVersion, IxDataMember * pImpl);
104 template <typename V, typename U> IxDataMember * add(V U::* pData, const QString & sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember * pImpl);
105 template <typename V, typename U> IxSqlRelation * relationOneToOne(V U::* pData, const QString & sKey, long lVersion, IxDataMember * pImpl);
106 template <typename V, typename U> IxSqlRelation * relationManyToOne(V U::* pData, const QString & sKey, long lVersion, IxDataMember * pImpl);
107 template <typename V, typename U> IxSqlRelation * relationOneToMany(V U::* pData, const QString & sKey, const QString & sForeignKey, long lVersion, IxDataMember * pImpl);
108 template <typename V, typename U> IxSqlRelation * relationManyToMany(V U::* pData, const QString & sKey, const QString & sExtraTable, const QString & sForeignKeyOwner, const QString & sForeignKeyDataType, long lVersion, IxDataMember * pImpl);
109
110#ifdef _QX_ENABLE_BOOST_SERIALIZATION
111 template <class Archive> inline void toArchive(const T * pOwner, Archive & ar, const unsigned int file_version) const;
112 template <class Archive> inline void fromArchive(T * pOwner, Archive & ar, const unsigned int file_version);
113#endif // _QX_ENABLE_BOOST_SERIALIZATION
114
115private:
116
117 IxDataMember * initId(IxDataMember * pId, long lVersion);
118 IxDataMember * initData(IxDataMember * pData, long lVersion);
120
122
133
134 bool exist_WithDaoStrategy_Helper(const QString & sKey) const
135 {
139 { return (exist(sKey) || (getId_WithDaoStrategy() ? (getId_WithDaoStrategy()->getKey() == sKey) : false)); }
141 { return (exist(sKey) || getBaseClass_Helper()->exist_WithDaoStrategy(sKey)); }
142 qAssert(false); return false;
143 }
144
146 {
148 { return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? get(lIndex) : getBaseClass_Helper()->get_WithDaoStrategy(lIndex)); }
150 { return ((! getId() && (lIndex == count())) ? getId_WithDaoStrategy() : get(lIndex)); }
152 { return (((lIndex >= 0) && (lIndex < count())) ? get(lIndex) : getBaseClass_Helper()->get_WithDaoStrategy(lIndex - count())); }
153 qAssert(false); return NULL;
154 }
155
156 IxDataMember * get_WithDaoStrategy_Helper(const QString & sKey) const
157 {
161 { return ((getId_WithDaoStrategy() && (getId_WithDaoStrategy()->getKey() == sKey)) ? getId_WithDaoStrategy() : get(sKey)); }
163 { return (exist(sKey) ? get(sKey) : getBaseClass_Helper()->get_WithDaoStrategy(sKey)); }
164 qAssert(false); return NULL;
165 }
166
177
178};
179
180} // namespace qx
181
182#include "../../inl/QxDataMember/QxDataMemberX.inl"
183
184#endif // _QX_DATA_MEMBER_X_H_
Common interface for a list of IxDataMember class properties registered into QxOrm context (for examp...
Concrete class property registered into QxOrm context.
Concrete class property registered into QxOrm context (using private implementation idiom)
Connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library intr...
Concrete factory class to create object dynamically using the class name.
#define qAssert(x)
Definition QxMacro.h:52
Concrete class to define a thread-safe singleton of QxOrm library.
Base class for all relationships defined between 2 classes (or between 2 tables in database)
qx::IxDataMember : common interface for all class properties registered into QxOrm context
QString getKey() const
qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOr...
virtual long count_WithDaoStrategy() const =0
long count() const
bool exist(const QString &sKey) const
qx::dao::strategy::inheritance getDaoStrategy() const
virtual IxDataMember * getId_WithDaoStrategy() const =0
virtual bool exist_WithDaoStrategy(const QString &sKey) const =0
IxDataMember * getId() const
IxDataMember * get(long l) const
virtual IxDataMember * get_WithDaoStrategy(long lIndex) const =0
qx::IxSqlRelation : common interface for all relationships defined between 2 classes (or between 2 ta...
qx::QxDataMemberX<T> : concrete list of properties registered into QxOrm context for the class T
IxDataMember * get_WithDaoStrategy_Helper(const QString &sKey) const
IxSqlRelation * relationManyToOne(V U::*pData, const QString &sKey, long lVersion=0)
long count_WithDaoStrategy_Helper() const
IxDataMember * get_WithDaoStrategy_Helper(long lIndex) const
IxSqlRelation * relationOneToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl)
IxSqlRelation * relationManyToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl)
IxDataMember * initData(IxDataMember *pData, long lVersion)
IxSqlRelation * relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion, IxDataMember *pImpl)
virtual ~QxDataMemberX()
virtual IxDataMember * get_WithDaoStrategy(const QString &sKey) const
IxDataMemberX * getBaseClass_Helper() const
void toArchive(const T *pOwner, Archive &ar, const unsigned int file_version) const
void fromArchive(T *pOwner, Archive &ar, const unsigned int file_version)
IxDataMember * getId_WithDaoStrategy_Helper() const
virtual bool exist_WithDaoStrategy(const QString &sKey) const
IxSqlRelation * relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion=0)
IxSqlRelation * relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion, IxDataMember *pImpl)
IxDataMember * add(V U::*pData, const QString &sKey, long lVersion=0, bool bSerialize=true, bool bDao=true)
virtual IxDataMember * get_WithDaoStrategy(long lIndex) const
IxDataMember * id(type_primary_key U::*pDataMemberId, const QString &sKey, long lVersion, IxDataMember *pImpl)
qx::trait::get_base_class< T >::type type_base_class
virtual IxDataMember * getId_WithDaoStrategy() const
IxDataMember * initPImpl(IxDataMember *pImpl)
IxDataMember * add(const QString &sKey, long lVersion)
IxSqlRelation * relationOneToOne(V U::*pData, const QString &sKey, long lVersion=0)
IxDataMember * initId(IxDataMember *pId, long lVersion)
IxSqlRelation * relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion=0)
bool exist_WithDaoStrategy_Helper(const QString &sKey) const
virtual long count_WithDaoStrategy() const
IxDataMember * add(V U::*pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl)
qx::trait::get_primary_key< T >::type type_primary_key
IxDataMember * pimpl(V U::*pData, const QString &sKey)
IxDataMember * id(const QString &sKey, long lVersion)
IxDataMember * id(type_primary_key T::*pDataMemberId, const QString &sKey, long lVersion=0)
qx::QxSingleton<T> : concrete class to define a thread-safe singleton of type T
Definition QxSingleton.h:59
qx::trait::get_base_class<T>::type : retrieve base class of type T registered into QxOrm context and ...
qx::trait::get_primary_key<T>::type : return primary key type of T, by default primary key is long ty...
qx::trait::get_sql_type<T>::get() : return type name under const char * format used by database engin...
Root namespace for all QxOrm library features.
qx::trait::qt_meta_object<T>::get() : if T is based on QObject class, then return QMetaObject instanc...