File indexing completed on 2024-04-14 15:05:39

0001 /*
0002  * This file is part of TelepathyLoggerQt
0003  *
0004  * Copyright (C) 2011 Collabora Ltd. <http://www.collabora.co.uk/>
0005  *
0006  * This library is free software; you can redistribute it and/or modify
0007  * it under the terms of the GNU Lesser General Public License as published
0008  * by the Free Software Foundation; either version 2.1 of the License, or
0009  * (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU Lesser General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 #ifndef _TelepathyLoggerQt_global_h_HEADER_GUARD_
0020 #define _TelepathyLoggerQt_global_h_HEADER_GUARD_
0021 
0022 #include <QSharedPointer>
0023 
0024 #include <TelepathyLoggerQt_export.h>
0025 
0026 class TELEPATHY_LOGGER_QT_EXPORT TPLoggerQtWrapper {
0027   public:
0028     template<typename TplClass, typename TplQtClass>
0029     static QSharedPointer<TplQtClass> wrap(TplClass *tplObj, bool ref = false) {
0030         return QSharedPointer<TplQtClass>(new TplQtClass(tplObj, ref));
0031     }
0032     template<typename TplClass, typename TplQtClass>
0033     static TplQtClass* wrap2(TplClass *tplObj, bool ref = false) {
0034         return new TplQtClass(tplObj, ref);
0035     }
0036 
0037     template<typename TplClass, typename TplQtClass>
0038     static TplClass* unwrap(const QSharedPointer<TplQtClass> &obj) {
0039         return reinterpret_cast<TplClass*>(obj->m_tplPtr);
0040     }
0041     template<typename TplClass, typename TplQtClass>
0042     static TplClass* unwrap(TplQtClass *obj) {
0043         return reinterpret_cast<TplClass*>(obj->m_tplPtr);
0044     }
0045 };
0046 
0047 #define QTELEPATHYLOGGERQT_WRAPPER_IMPL_BASECLASS(Class) \
0048   protected: \
0049     friend class ::TPLoggerQtWrapper; \
0050     Class(struct _Tpl##Class *tplPtr, bool ref): \
0051         Object(tplPtr, ref) \
0052     { }
0053 
0054 #define QTELEPATHYLOGGERQT_WRAPPER_IMPL_SUBCLASSED(Class, Superclass) \
0055   friend class ::TPLoggerQtWrapper; \
0056   private: \
0057     Class(struct _Tpl##Class *tplPtr, bool ref): \
0058         Superclass(reinterpret_cast<struct _Tpl##Superclass*>(tplPtr), ref) \
0059     { }
0060 
0061 
0062 #define QTELEPATHYLOGGERQT_WRAPPER_GET_IMPL(_1, _2, NAME, ...) NAME
0063 
0064 #define QTELEPATHYLOGGERQT_WRAPPER(...) \
0065     QTELEPATHYLOGGERQT_WRAPPER_GET_IMPL( \
0066         __VA_ARGS__, \
0067         QTELEPATHYLOGGERQT_WRAPPER_IMPL_SUBCLASSED, \
0068         QTELEPATHYLOGGERQT_WRAPPER_IMPL_BASECLASS)(__VA_ARGS__)
0069 
0070 #endif