| QxOrm 1.2.4 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxAnyCastDynamic.h
Go to the documentation of this file.

    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_ANY_CAST_DYNAMIC_H_
    00027 #define _QX_ANY_CAST_DYNAMIC_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <boost/any.hpp>
    00041 #include <boost/shared_ptr.hpp>
    00042
    00043 #include <QtCore/qsharedpointer.h>
    00044
    00045 #include <QxDao/QxDaoPointer.h>
    00046
    00047 namespace qx {
    00048
    00049 template <typename T>
    00050 struct any_cast_dynamic
    00051 { static T get(const boost::any & a) { return boost::any_cast<T>(a); } };
    00052
    00053 template <typename T>
    00054 struct any_cast_dynamic<T *>
    00055 {
    00056    static T * get(const boost::any & a)
    00057    {
    00058       if (a.empty()) { return NULL; }
    00059       boost::any * b = const_cast<boost::any *>(& a);
    00060       T ** t = boost::unsafe_any_cast<T *>(b);
    00061       if (! t) { return NULL; }
    00062       return (* t);
    00063    }
    00064 };
    00065
    00066 template <typename T>
    00067 struct any_cast_dynamic< boost::shared_ptr<T> >
    00068 {
    00069    static boost::shared_ptr<T> get(const boost::any & a)
    00070    {
    00071       if (a.empty()) { return boost::shared_ptr<T>(); }
    00072       boost::any * b = const_cast<boost::any *>(& a);
    00073       boost::shared_ptr<T> * t = boost::unsafe_any_cast< boost::shared_ptr<T> >(b);
    00074       if (! t) { return boost::shared_ptr<T>(); }
    00075       return (* t);
    00076    }
    00077 };
    00078
    00079 template <typename T>
    00080 struct any_cast_dynamic< QSharedPointer<T> >
    00081 {
    00082    static QSharedPointer<T> get(const boost::any & a)
    00083    {
    00084       if (a.empty()) { return QSharedPointer<T>(); }
    00085       boost::any * b = const_cast<boost::any *>(& a);
    00086       QSharedPointer<T> * t = boost::unsafe_any_cast< QSharedPointer<T> >(b);
    00087       if (! t) { return QSharedPointer<T>(); }
    00088       return (* t);
    00089    }
    00090 };
    00091
    00092 template <typename T>
    00093 struct any_cast_dynamic< qx::dao::ptr<T> >
    00094 {
    00095    static qx::dao::ptr<T> get(const boost::any & a)
    00096    {
    00097       if (a.empty()) { return qx::dao::ptr<T>(); }
    00098       boost::any * b = const_cast<boost::any *>(& a);
    00099       qx::dao::ptr<T> * t = boost::unsafe_any_cast< qx::dao::ptr<T> >(b);
    00100       if (! t) { return qx::dao::ptr<T>(); }
    00101       return (* t);
    00102    }
    00103 };
    00104
    00105 } // namespace qx
    00106
    00107 #endif // _QX_ANY_CAST_DYNAMIC_H_