QxOrm  1.5.0
C++ Object Relational Mapping library
QxDataMember_PImpl.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://www.qxorm.com/
00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
00005 **
00006 ** This file is part of the QxOrm library
00007 **
00008 ** This software is provided 'as-is', without any express or implied
00009 ** warranty. In no event will the authors be held liable for any
00010 ** damages arising from the use of this software
00011 **
00012 ** Commercial Usage
00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
00014 ** accordance with the commercial license agreement provided with the
00015 ** Software or, alternatively, in accordance with the terms contained in
00016 ** a written agreement between you and Lionel Marty
00017 **
00018 ** GNU General Public License Usage
00019 ** Alternatively, this file may be used under the terms of the GNU
00020 ** General Public License version 3.0 as published by the Free Software
00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
00022 ** packaging of this file. Please review the following information to
00023 ** ensure the GNU General Public License version 3.0 requirements will be
00024 ** met : http://www.gnu.org/copyleft/gpl.html
00025 **
00026 ** If you are unsure which license is appropriate for your use, or
00027 ** if you have questions regarding the use of this file, please contact :
00028 ** contact@qxorm.com
00029 **
00030 ****************************************************************************/
00031 
00032 #ifndef _QX_DATA_MEMBER_PIMPL_H_
00033 #define _QX_DATA_MEMBER_PIMPL_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <QxDataMember/IxDataMember.h>
00047 
00048 #define QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(ArchiveInput, ArchiveOutput) \
00049 virtual void toArchive(const void * pOwner, ArchiveOutput & ar) const Q_DECL_OVERRIDE { Q_UNUSED(pOwner); Q_UNUSED(ar); } \
00050 virtual void fromArchive(void * pOwner, ArchiveInput & ar) Q_DECL_OVERRIDE { Q_UNUSED(pOwner); Q_UNUSED(ar); }
00051 
00052 namespace qx {
00053 
00058 template <typename DataType, class Owner>
00059 class QxDataMember_PImpl : public IxDataMember
00060 {
00061 
00062 protected:
00063 
00064    typedef DataType Owner::* type_data_member_ptr;
00065 
00066    type_data_member_ptr m_pData; 
00067 
00068 public:
00069 
00070    QxDataMember_PImpl(type_data_member_ptr pData, const QString & sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { static_assert(std::is_pointer<DataType>::value, "std::is_pointer<DataType>::value"); this->setAccessDataPointer(true); }
00071    virtual ~QxDataMember_PImpl() { ; }
00072 
00073    virtual bool isEqual(const void * pOwner1, const void * pOwner2) const Q_DECL_OVERRIDE { Q_UNUSED(pOwner1); Q_UNUSED(pOwner2); return false; }
00074    virtual QVariant toVariant(const void * pOwner, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE          { Q_UNUSED(pOwner); Q_UNUSED(sFormat); Q_UNUSED(iIndexName); Q_UNUSED(ctx); return QVariant(); }
00075    virtual qx_bool fromVariant(void * pOwner, const QVariant & v, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE { Q_UNUSED(pOwner); Q_UNUSED(v); Q_UNUSED(sFormat); Q_UNUSED(iIndexName); Q_UNUSED(ctx); return qx_bool(true); }
00076    virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
00077 
00078 #ifndef _QX_NO_JSON
00079    virtual QJsonValue toJson(const void * pOwner, const QString & sFormat) const Q_DECL_OVERRIDE             { Q_UNUSED(pOwner); Q_UNUSED(sFormat); return QJsonValue(); }
00080    virtual qx_bool fromJson(void * pOwner, const QJsonValue & j, const QString & sFormat) Q_DECL_OVERRIDE    { Q_UNUSED(pOwner); Q_UNUSED(j); Q_UNUSED(sFormat); return qx_bool(true); }
00081 #endif // _QX_NO_JSON
00082 
00083 protected:
00084 
00085    inline DataType * getData(void * pOwner) const              { return (& ((static_cast<Owner *>(pOwner))->*m_pData)); }
00086    inline const DataType * getData(const void * pOwner) const  { return (& ((static_cast<const Owner *>(pOwner))->*m_pData)); }
00087 
00088    virtual qx::any getDataPtr(const void * pOwner) const Q_DECL_FINAL       { return (pOwner ? qx::any(* getData(pOwner)) : qx::any()); }
00089    virtual qx::any getDataPtr(void * pOwner) Q_DECL_FINAL                   { return (pOwner ? qx::any(* getData(pOwner)) : qx::any()); }
00090    virtual void * getDataVoidPtr(const void * pOwner) const Q_DECL_FINAL    { return (pOwner ? static_cast<void *>(const_cast<DataType>(* getData(pOwner))) : NULL); }
00091    virtual void * getDataVoidPtr(void * pOwner) Q_DECL_FINAL                { return (pOwner ? static_cast<void *>(* getData(pOwner)) : NULL); }
00092 
00093 public:
00094 
00095 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00096 
00097 #if _QX_SERIALIZE_POLYMORPHIC
00098    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
00099 #endif // _QX_SERIALIZE_POLYMORPHIC
00100 
00101 #if _QX_SERIALIZE_BINARY
00102    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
00103 #endif // _QX_SERIALIZE_BINARY
00104 
00105 #if _QX_SERIALIZE_TEXT
00106    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
00107 #endif // _QX_SERIALIZE_TEXT
00108 
00109 #if _QX_SERIALIZE_XML
00110    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
00111 #endif // _QX_SERIALIZE_XML
00112 
00113 #if _QX_SERIALIZE_PORTABLE_BINARY
00114    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
00115 #endif // _QX_SERIALIZE_PORTABLE_BINARY
00116 
00117 #if _QX_SERIALIZE_WIDE_BINARY
00118    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
00119 #endif // _QX_SERIALIZE_WIDE_BINARY
00120 
00121 #if _QX_SERIALIZE_WIDE_TEXT
00122    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
00123 #endif // _QX_SERIALIZE_WIDE_TEXT
00124 
00125 #if _QX_SERIALIZE_WIDE_XML
00126    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
00127 #endif // _QX_SERIALIZE_WIDE_XML
00128 
00129 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00130 
00131 };
00132 
00133 template <typename DataType, class Owner>
00134 class QxDataMember_PImpl<std::unique_ptr<DataType>, Owner> : public IxDataMember
00135 {
00136 
00137 protected:
00138 
00139    typedef std::unique_ptr<DataType> Owner::* type_data_member_ptr;
00140 
00141    type_data_member_ptr m_pData; 
00142 
00143 public:
00144 
00145    QxDataMember_PImpl(type_data_member_ptr pData, const QString & sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { this->setAccessDataPointer(true); }
00146    virtual ~QxDataMember_PImpl() { ; }
00147 
00148    virtual bool isEqual(const void * pOwner1, const void * pOwner2) const Q_DECL_OVERRIDE { Q_UNUSED(pOwner1); Q_UNUSED(pOwner2); return false; }
00149    virtual QVariant toVariant(const void * pOwner, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE          { Q_UNUSED(pOwner); Q_UNUSED(sFormat); Q_UNUSED(iIndexName); Q_UNUSED(ctx); return QVariant(); }
00150    virtual qx_bool fromVariant(void * pOwner, const QVariant & v, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE { Q_UNUSED(pOwner); Q_UNUSED(v); Q_UNUSED(sFormat); Q_UNUSED(iIndexName); Q_UNUSED(ctx); return qx_bool(true); }
00151    virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
00152 
00153 #ifndef _QX_NO_JSON
00154    virtual QJsonValue toJson(const void * pOwner, const QString & sFormat) const Q_DECL_OVERRIDE             { Q_UNUSED(pOwner); Q_UNUSED(sFormat); return QJsonValue(); }
00155    virtual qx_bool fromJson(void * pOwner, const QJsonValue & j, const QString & sFormat) Q_DECL_OVERRIDE    { Q_UNUSED(pOwner); Q_UNUSED(j); Q_UNUSED(sFormat); return qx_bool(true); }
00156 #endif // _QX_NO_JSON
00157 
00158 protected:
00159 
00160    inline std::unique_ptr<DataType> * getData(void * pOwner) const              { return (& ((static_cast<Owner *>(pOwner))->*m_pData)); }
00161    inline const std::unique_ptr<DataType> * getData(const void * pOwner) const  { return (& ((static_cast<const Owner *>(pOwner))->*m_pData)); }
00162 
00163    virtual qx::any getDataPtr(const void * pOwner) const Q_DECL_FINAL       { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
00164    virtual qx::any getDataPtr(void * pOwner) Q_DECL_FINAL                   { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
00165    virtual void * getDataVoidPtr(const void * pOwner) const Q_DECL_FINAL    { return (pOwner ? static_cast<void *>(const_cast<DataType *>(getData(pOwner)->get())) : NULL); }
00166    virtual void * getDataVoidPtr(void * pOwner) Q_DECL_FINAL                { return (pOwner ? static_cast<void *>(getData(pOwner)->get()) : NULL); }
00167 
00168 public:
00169 
00170 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00171 
00172 #if _QX_SERIALIZE_POLYMORPHIC
00173    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
00174 #endif // _QX_SERIALIZE_POLYMORPHIC
00175 
00176 #if _QX_SERIALIZE_BINARY
00177    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
00178 #endif // _QX_SERIALIZE_BINARY
00179 
00180 #if _QX_SERIALIZE_TEXT
00181    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
00182 #endif // _QX_SERIALIZE_TEXT
00183 
00184 #if _QX_SERIALIZE_XML
00185    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
00186 #endif // _QX_SERIALIZE_XML
00187 
00188 #if _QX_SERIALIZE_PORTABLE_BINARY
00189    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
00190 #endif // _QX_SERIALIZE_PORTABLE_BINARY
00191 
00192 #if _QX_SERIALIZE_WIDE_BINARY
00193    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
00194 #endif // _QX_SERIALIZE_WIDE_BINARY
00195 
00196 #if _QX_SERIALIZE_WIDE_TEXT
00197    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
00198 #endif // _QX_SERIALIZE_WIDE_TEXT
00199 
00200 #if _QX_SERIALIZE_WIDE_XML
00201    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
00202 #endif // _QX_SERIALIZE_WIDE_XML
00203 
00204 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00205 
00206 };
00207 
00208 template <typename DataType, class Owner>
00209 class QxDataMember_PImpl<std::shared_ptr<DataType>, Owner> : public IxDataMember
00210 {
00211 
00212 protected:
00213 
00214    typedef std::shared_ptr<DataType> Owner::* type_data_member_ptr;
00215 
00216    type_data_member_ptr m_pData; 
00217 
00218 public:
00219 
00220    QxDataMember_PImpl(type_data_member_ptr pData, const QString & sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { this->setAccessDataPointer(true); }
00221    virtual ~QxDataMember_PImpl() { ; }
00222 
00223    virtual bool isEqual(const void * pOwner1, const void * pOwner2) const Q_DECL_OVERRIDE { Q_UNUSED(pOwner1); Q_UNUSED(pOwner2); return false; }
00224    virtual QVariant toVariant(const void * pOwner, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE          { Q_UNUSED(pOwner); Q_UNUSED(sFormat); Q_UNUSED(iIndexName); Q_UNUSED(ctx); return QVariant(); }
00225    virtual qx_bool fromVariant(void * pOwner, const QVariant & v, const QString & sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE { Q_UNUSED(pOwner); Q_UNUSED(v); Q_UNUSED(sFormat); Q_UNUSED(iIndexName); Q_UNUSED(ctx); return qx_bool(true); }
00226    virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
00227 
00228 #ifndef _QX_NO_JSON
00229    virtual QJsonValue toJson(const void * pOwner, const QString & sFormat) const Q_DECL_OVERRIDE             { Q_UNUSED(pOwner); Q_UNUSED(sFormat); return QJsonValue(); }
00230    virtual qx_bool fromJson(void * pOwner, const QJsonValue & j, const QString & sFormat) Q_DECL_OVERRIDE    { Q_UNUSED(pOwner); Q_UNUSED(j); Q_UNUSED(sFormat); return qx_bool(true); }
00231 #endif // _QX_NO_JSON
00232 
00233 protected:
00234 
00235    inline std::shared_ptr<DataType> * getData(void * pOwner) const              { return (& ((static_cast<Owner *>(pOwner))->*m_pData)); }
00236    inline const std::shared_ptr<DataType> * getData(const void * pOwner) const  { return (& ((static_cast<const Owner *>(pOwner))->*m_pData)); }
00237 
00238    virtual qx::any getDataPtr(const void * pOwner) const Q_DECL_FINAL       { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
00239    virtual qx::any getDataPtr(void * pOwner) Q_DECL_FINAL                   { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
00240    virtual void * getDataVoidPtr(const void * pOwner) const Q_DECL_FINAL    { return (pOwner ? static_cast<void *>(const_cast<DataType *>(getData(pOwner)->get())) : NULL); }
00241    virtual void * getDataVoidPtr(void * pOwner) Q_DECL_FINAL                { return (pOwner ? static_cast<void *>(getData(pOwner)->get()) : NULL); }
00242 
00243 public:
00244 
00245 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00246 
00247 #if _QX_SERIALIZE_POLYMORPHIC
00248    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
00249 #endif // _QX_SERIALIZE_POLYMORPHIC
00250 
00251 #if _QX_SERIALIZE_BINARY
00252    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
00253 #endif // _QX_SERIALIZE_BINARY
00254 
00255 #if _QX_SERIALIZE_TEXT
00256    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
00257 #endif // _QX_SERIALIZE_TEXT
00258 
00259 #if _QX_SERIALIZE_XML
00260    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
00261 #endif // _QX_SERIALIZE_XML
00262 
00263 #if _QX_SERIALIZE_PORTABLE_BINARY
00264    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
00265 #endif // _QX_SERIALIZE_PORTABLE_BINARY
00266 
00267 #if _QX_SERIALIZE_WIDE_BINARY
00268    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
00269 #endif // _QX_SERIALIZE_WIDE_BINARY
00270 
00271 #if _QX_SERIALIZE_WIDE_TEXT
00272    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
00273 #endif // _QX_SERIALIZE_WIDE_TEXT
00274 
00275 #if _QX_SERIALIZE_WIDE_XML
00276    QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
00277 #endif // _QX_SERIALIZE_WIDE_XML
00278 
00279 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00280 
00281 };
00282 
00283 } // namespace qx
00284 
00285 #endif // _QX_DATA_MEMBER_PIMPL_H_