![]() |
QxOrm 1.1.8
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** http://sourceforge.net/projects/qxorm/ 00005 ** Original file by Lionel Marty 00006 ** 00007 ** This file is part of the QxOrm library 00008 ** 00009 ** This software is provided 'as-is', without any express or implied 00010 ** warranty. In no event will the authors be held liable for any 00011 ** damages arising from the use of this software. 00012 ** 00013 ** GNU Lesser General Public License Usage 00014 ** This file must be used under the terms of the GNU Lesser 00015 ** General Public License version 2.1 as published by the Free Software 00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the 00017 ** packaging of this file. Please review the following information to 00018 ** ensure the GNU Lesser General Public License version 2.1 requirements 00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 00020 ** 00021 ** If you have questions regarding the use of this file, please contact : 00022 ** contact@qxorm.com 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef _IX_DATA_MEMBER_H_ 00027 #define _IX_DATA_MEMBER_H_ 00028 00029 #ifdef _MSC_VER 00030 #pragma once 00031 #endif 00032 00040 #ifdef _MSC_VER 00041 #pragma warning(push) 00042 #pragma warning(disable:4996) 00043 #endif // _MSC_VER 00044 00045 #include <boost/any.hpp> 00046 00047 #include <QxCommon/QxBool.h> 00048 00049 #include <QxSerialize/boost/QxSerializeInclude.h> 00050 00051 #include <QxDao/IxSqlRelation.h> 00052 00053 #ifdef _MSC_VER 00054 #pragma warning(pop) 00055 #endif // _MSC_VER 00056 00057 #define QX_CONSTRUCT_IX_DATA_MEMBER() \ 00058 m_iPrecision(6), m_iMinLength(-1), m_iMaxLength(-1), m_bRequired(false), \ 00059 m_bReadOnly(false), m_bAutoIncrement(false), m_bNotNull(false), \ 00060 m_bIsPrimaryKey(false), m_pName(NULL), m_pParent(NULL) 00061 00062 #define QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput) \ 00063 virtual void toArchive(const void * pOwner, ArchiveOutput & ar) const = 0; \ 00064 virtual void fromArchive(void * pOwner, ArchiveInput & ar) = 0; 00065 00066 namespace qx { 00067 00068 class IxDataMemberX; 00069 00074 class QX_DLL_EXPORT IxDataMember 00075 { 00076 00077 protected: 00078 00079 QString m_sKey; 00080 QString m_sName; 00081 QString m_sNameParent; 00082 QString m_sDescription; 00083 QString m_sFormat; 00084 QString m_sSqlType; 00085 QString m_sSqlAlias; 00086 long m_lVersion; 00087 bool m_bSerialize; 00088 bool m_bDao; 00089 QVariant m_vDefaultValue; 00090 QVariant m_vMinValue; 00091 QVariant m_vMaxValue; 00092 int m_iPrecision; 00093 int m_iMinLength; 00094 int m_iMaxLength; 00095 bool m_bRequired; 00096 bool m_bReadOnly; 00097 bool m_bAutoIncrement; 00098 bool m_bNotNull; 00099 bool m_bIsPrimaryKey; 00100 00101 QByteArray m_byteName; 00102 const char * m_pName; 00103 QStringList m_lstNames; 00104 00105 boost::scoped_ptr<IxSqlRelation> m_pSqlRelation; 00106 IxDataMemberX * m_pParent; 00107 00108 public: 00109 00110 IxDataMember(const QString & sKey) : m_sKey(sKey), m_lVersion(-1), m_bSerialize(true), m_bDao(true), QX_CONSTRUCT_IX_DATA_MEMBER() { qAssert(! m_sKey.isEmpty()); updateNamePtr(); } 00111 IxDataMember(const QString & sKey, long lVersion, bool bSerialize, bool bDao) : m_sKey(sKey), m_lVersion(lVersion), m_bSerialize(bSerialize), m_bDao(bDao), QX_CONSTRUCT_IX_DATA_MEMBER() { qAssert(! m_sKey.isEmpty()); updateNamePtr(); } 00112 virtual ~IxDataMember() = 0; 00113 00114 inline QString getKey() const { return m_sKey; } 00115 inline QString getName() const { return (m_sName.isEmpty() ? m_sKey : m_sName); } 00116 inline int getNameCount() const { return m_lstNames.count(); } 00117 inline QString getNameParent() const { return m_sNameParent; } 00118 inline const char * getNamePtr() const { return m_pName; } 00119 inline QString getDescription() const { return m_sDescription; } 00120 inline QString getFormat() const { return m_sFormat; } 00121 inline long getVersion() const { return m_lVersion; } 00122 inline bool getSerialize() const { return m_bSerialize; } 00123 inline bool getDao() const { return m_bDao; } 00124 inline QVariant getDefaultValue() const { return m_vDefaultValue; } 00125 inline QVariant getMinValue() const { return m_vMinValue; } 00126 inline QVariant getMaxValue() const { return m_vMaxValue; } 00127 inline int getPrecision() const { return m_iPrecision; } 00128 inline int getMinLength() const { return m_iMinLength; } 00129 inline int getMaxLength() const { return m_iMaxLength; } 00130 inline bool getRequired() const { return m_bRequired; } 00131 inline bool getReadOnly() const { return m_bReadOnly; } 00132 inline bool getAutoIncrement() const { return m_bAutoIncrement; } 00133 inline bool getNotNull() const { return m_bNotNull; } 00134 inline bool getIsPrimaryKey() const { return m_bIsPrimaryKey; } 00135 inline IxDataMemberX * getParent() const { return m_pParent; } 00136 inline IxSqlRelation * getSqlRelation() const { return m_pSqlRelation.get(); } 00137 inline bool hasSqlRelation() const { return (m_pSqlRelation.get() != NULL); } 00138 00139 inline void setName(const QString & sName) { m_sName = sName; updateNamePtr(); } 00140 inline void setNameParent(const QString & sName) { m_sNameParent = sName; } 00141 inline void setDescription(const QString & sDesc) { m_sDescription = sDesc; } 00142 inline void setFormat(const QString & sFormat) { m_sFormat = sFormat; } 00143 inline void setSqlType(const QString & sSqlType) { m_sSqlType = sSqlType; } 00144 inline void setSqlAlias(const QString & sSqlAlias) { m_sSqlAlias = sSqlAlias; } 00145 inline void setVersion(long lVersion) { m_lVersion = lVersion; } 00146 inline void setSerialize(bool bSerialize) { m_bSerialize = bSerialize; } 00147 inline void setDao(bool bDao) { m_bDao = bDao; } 00148 inline void setDefaultValue(const QVariant & var) { m_vDefaultValue = var; } 00149 inline void setMinValue(const QVariant & var) { m_vMinValue = var; } 00150 inline void setMaxValue(const QVariant & var) { m_vMaxValue = var; } 00151 inline void setPrecision(int iPrecision) { m_iPrecision = iPrecision; } 00152 inline void setMinLength(int iMinLength) { m_iMinLength = iMinLength; } 00153 inline void setMaxLength(int iMaxLength) { m_iMaxLength = iMaxLength; } 00154 inline void setRequired(bool bRequired) { m_bRequired = bRequired; } 00155 inline void setReadOnly(bool bReadOnly) { m_bReadOnly = bReadOnly; } 00156 inline void setAutoIncrement(bool bAutoIncrement) { m_bAutoIncrement = bAutoIncrement; } 00157 inline void setNotNull(bool bNotNull) { m_bNotNull = bNotNull; } 00158 inline void setIsPrimaryKey(bool bIsPrimaryKey) { m_bIsPrimaryKey = bIsPrimaryKey; } 00159 inline void setParent(IxDataMemberX * pParent) { m_pParent = pParent; } 00160 inline void setSqlRelation(IxSqlRelation * pSqlRelation) { m_pSqlRelation.reset(pSqlRelation); } 00161 00162 QString getName(int iIndex, const QString & sOtherName = QString()) const; 00163 QString getSqlAlias(const QString & sTable = QString(), bool bClauseWhere = false, int iIndexName = 0) const; 00164 QString getSqlType(int iIndexName = -1) const; 00165 QString getSqlTypeAndParams(int iIndexName = -1) const; 00166 QString getSqlPlaceHolder(const QString & sAppend = QString(), int iIndexName = 0, const QString & sSep = QString(", "), const QString & sOtherName = QString()) const; 00167 void setSqlPlaceHolder(QSqlQuery & query, void * pOwner, const QString & sAppend = QString(), const QString & sOtherName = QString()) const; 00168 QString getSqlAliasEqualToPlaceHolder(const QString & sTable = QString(), bool bClauseWhere = false, const QString & sAppend = QString(), const QString & sSep = QString(" AND ")) const; 00169 QString getSqlNameEqualToPlaceHolder(const QString & sAppend = QString(), const QString & sSep = QString(" AND ")) const; 00170 QString getSqlTablePointNameAsAlias(const QString & sTable, const QString & sSep = QString(", ")) const; 00171 QString getSqlName(const QString & sSep = QString(", "), const QString & sOtherName = QString()) const; 00172 QString getSqlNameAndTypeAndParams(const QString & sSep = QString(", "), const QString & sOtherName = QString()) const; 00173 00174 virtual bool isEqual(const void * pOwner1, const void * pOwner2) const = 0; 00175 virtual boost::any getDataPtr(const void * pOwner) const = 0; 00176 virtual boost::any getDataPtr(void * pOwner) = 0; 00177 virtual void * getDataVoidPtr(const void * pOwner) const = 0; 00178 virtual void * getDataVoidPtr(void * pOwner) = 0; 00179 virtual qx_bool isValid(const void * pOwner) const = 0; 00180 virtual qx_bool isValid(void * pOwner) = 0; 00181 00182 virtual QString toString(const void * pOwner, const QString & sFormat, int iIndexName = -1) const = 0; 00183 virtual qx_bool fromString(void * pOwner, const QString & s, const QString & sFormat, int iIndexName = -1) = 0; 00184 virtual QVariant toVariant(const void * pOwner, const QString & sFormat, int iIndexName = -1) const = 0; 00185 virtual qx_bool fromVariant(void * pOwner, const QVariant & v, const QString & sFormat, int iIndexName = -1) = 0; 00186 00187 inline QString toString(const void * pOwner, int iIndexName = -1) const { return this->toString(pOwner, m_sFormat, iIndexName); } 00188 inline qx_bool fromString(void * pOwner, const QString & s, int iIndexName = -1) { return this->fromString(pOwner, s, m_sFormat, iIndexName); } 00189 inline QVariant toVariant(const void * pOwner, int iIndexName = -1) const { return this->toVariant(pOwner, m_sFormat, iIndexName); } 00190 inline qx_bool fromVariant(void * pOwner, const QVariant & v, int iIndexName = -1) { return this->fromVariant(pOwner, v, m_sFormat, iIndexName); } 00191 00192 #if _QX_SERIALIZE_POLYMORPHIC 00193 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive) 00194 #endif // _QX_SERIALIZE_POLYMORPHIC 00195 00196 #if _QX_SERIALIZE_BINARY 00197 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::binary_iarchive, boost::archive::binary_oarchive) 00198 #endif // _QX_SERIALIZE_BINARY 00199 00200 #if _QX_SERIALIZE_TEXT 00201 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::text_iarchive, boost::archive::text_oarchive) 00202 #endif // _QX_SERIALIZE_TEXT 00203 00204 #if _QX_SERIALIZE_XML 00205 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::xml_iarchive, boost::archive::xml_oarchive) 00206 #endif // _QX_SERIALIZE_XML 00207 00208 #if _QX_SERIALIZE_PORTABLE_BINARY 00209 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(eos::portable_iarchive, eos::portable_oarchive) 00210 #endif // _QX_SERIALIZE_PORTABLE_BINARY 00211 00212 #if _QX_SERIALIZE_WIDE_BINARY 00213 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::binary_wiarchive, boost::archive::binary_woarchive) 00214 #endif // _QX_SERIALIZE_WIDE_BINARY 00215 00216 #if _QX_SERIALIZE_WIDE_TEXT 00217 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::text_wiarchive, boost::archive::text_woarchive) 00218 #endif // _QX_SERIALIZE_WIDE_TEXT 00219 00220 #if _QX_SERIALIZE_WIDE_XML 00221 QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::xml_wiarchive, boost::archive::xml_woarchive) 00222 #endif // _QX_SERIALIZE_WIDE_XML 00223 00224 private: 00225 00226 inline void updateNamePtr() 00227 { 00228 QString sNamePtr = (m_sName.isEmpty() ? m_sKey : m_sName); 00229 sNamePtr.replace("|", "-"); // valid xml tag 00230 m_byteName = sNamePtr.toAscii(); 00231 m_pName = m_byteName.constData(); 00232 m_lstNames = (m_sName.isEmpty() ? m_sKey.split("|") : m_sName.split("|")); 00233 } 00234 00235 template<class Archive> 00236 void serialize(Archive & ar, const unsigned int version); 00237 00238 }; 00239 00240 typedef boost::shared_ptr<IxDataMember> IxDataMember_ptr; 00241 00242 } // namespace qx 00243 00244 QX_DLL_EXPORT_INLINE_FCT inline bool operator< (const qx::IxDataMember & i1, const qx::IxDataMember & i2); 00245 QX_DLL_EXPORT_INLINE_FCT inline bool operator> (const qx::IxDataMember & i1, const qx::IxDataMember & i2); 00246 00247 #endif // _IX_DATA_MEMBER_H_