![]() |
QxOrm 1.1.9
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 _QX_CONSTRUCT_PTR_H_ 00027 #define _QX_CONSTRUCT_PTR_H_ 00028 00029 #ifdef _MSC_VER 00030 #pragma once 00031 #endif 00032 00040 #include <boost/scoped_ptr.hpp> 00041 #include <boost/shared_ptr.hpp> 00042 #include <boost/intrusive_ptr.hpp> 00043 #include <boost/type_traits/is_abstract.hpp> 00044 #include <boost/type_traits/remove_pointer.hpp> 00045 00046 #include <QtCore/qsharedpointer.h> 00047 00048 #if (QT_VERSION >= 0x040600) 00049 #include <QtCore/qscopedpointer.h> 00050 #endif // (QT_VERSION >= 0x040600) 00051 00052 #include <QxDao/QxDaoPointer.h> 00053 00054 namespace qx { 00055 namespace trait { 00056 00061 template <typename T> 00062 struct construct_ptr 00063 { 00064 00065 private: 00066 00067 typedef typename boost::remove_pointer<T>::type type_ptr; 00068 00069 public: 00070 00071 static inline void get(T & t) 00072 { new_ptr<boost::is_abstract<type_ptr>::value, 0>::get(t); } 00073 00074 private: 00075 00076 template <bool isAbstract /* = false */, int dummy> 00077 struct new_ptr 00078 { static inline void get(T & t) { t = new type_ptr(); } }; 00079 00080 template <int dummy> 00081 struct new_ptr<true, dummy> 00082 { static inline void get(T & t) { Q_UNUSED(t); qDebug("[QxOrm] qx::trait::construct_ptr<T> : %s", "cannot instantiate abstract class"); } }; 00083 00084 }; 00085 00086 template <typename T> 00087 struct construct_ptr< boost::scoped_ptr<T> > 00088 { static inline void get(boost::scoped_ptr<T> & t) { t.reset(new T()); } }; 00089 00090 template <typename T> 00091 struct construct_ptr< boost::shared_ptr<T> > 00092 { static inline void get(boost::shared_ptr<T> & t) { t.reset(new T()); } }; 00093 00094 template <typename T> 00095 struct construct_ptr< boost::intrusive_ptr<T> > 00096 { static inline void get(boost::intrusive_ptr<T> & t) { t.reset(new T()); } }; 00097 00098 template <typename T> 00099 struct construct_ptr< QSharedPointer<T> > 00100 { static inline void get(QSharedPointer<T> & t) { t = QSharedPointer<T>(new T()); } }; 00101 00102 #if (QT_VERSION >= 0x040600) 00103 template <typename T> 00104 struct construct_ptr< QScopedPointer<T> > 00105 { static inline void get(QScopedPointer<T> & t) { t = QScopedPointer<T>(new T()); } }; 00106 #endif // (QT_VERSION >= 0x040600) 00107 00108 template <typename T> 00109 struct construct_ptr< qx::dao::ptr<T> > 00110 { static inline void get(qx::dao::ptr<T> & t) { t = qx::dao::ptr<T>(new T()); } }; 00111 00112 } // namespace trait 00113 } // namespace qx 00114 00115 #endif // _QX_CONSTRUCT_PTR_H_