QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxAnyCastDynamic.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_ANY_CAST_DYNAMIC_H_
33#define _QX_ANY_CAST_DYNAMIC_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QtCore/qsharedpointer.h>
47
48#include <QxCommon/QxAny.h>
49
50#include <QxDao/QxDaoPointer.h>
51
52namespace qx {
53
54template <typename T>
56{ static T get(const qx::any & a) { return qx::any_cast<T>(a); } };
57
58template <typename T>
60{
61 static T * get(const qx::any & a)
62 {
63 if (a.empty()) { return NULL; }
64 qx::any * b = const_cast<qx::any *>(& a);
65 T ** t = qx::unsafe_any_cast<T *>(b);
66 if (! t) { return NULL; }
67 return (* t);
68 }
69};
70
71#ifdef _QX_ENABLE_BOOST
72
73template <typename T>
74struct any_cast_dynamic< boost::shared_ptr<T> >
75{
76 static boost::shared_ptr<T> get(const qx::any & a)
77 {
78 if (a.empty()) { return boost::shared_ptr<T>(); }
79 qx::any * b = const_cast<qx::any *>(& a);
80 boost::shared_ptr<T> * t = qx::unsafe_any_cast< boost::shared_ptr<T> >(b);
81 if (! t) { return boost::shared_ptr<T>(); }
82 return (* t);
83 }
84};
85
86#endif // _QX_ENABLE_BOOST
87
88template <typename T>
89struct any_cast_dynamic< QSharedPointer<T> >
90{
91 static QSharedPointer<T> get(const qx::any & a)
92 {
93 if (a.empty()) { return QSharedPointer<T>(); }
94 qx::any * b = const_cast<qx::any *>(& a);
95 QSharedPointer<T> * t = qx::unsafe_any_cast< QSharedPointer<T> >(b);
96 if (! t) { return QSharedPointer<T>(); }
97 return (* t);
98 }
99};
100
101template <typename T>
103{
104 static qx::dao::ptr<T> get(const qx::any & a)
105 {
106 if (a.empty()) { return qx::dao::ptr<T>(); }
107 qx::any * b = const_cast<qx::any *>(& a);
109 if (! t) { return qx::dao::ptr<T>(); }
110 return (* t);
111 }
112};
113
114template <typename T>
115struct any_cast_dynamic< std::shared_ptr<T> >
116{
117 static std::shared_ptr<T> get(const qx::any & a)
118 {
119 if (a.empty()) { return std::shared_ptr<T>(); }
120 qx::any * b = const_cast<qx::any *>(& a);
121 std::shared_ptr<T> * t = qx::unsafe_any_cast< std::shared_ptr<T> >(b);
122 if (! t) { return std::shared_ptr<T>(); }
123 return (* t);
124 }
125};
126
127} // namespace qx
128
129#endif // _QX_ANY_CAST_DYNAMIC_H_
qx::any : basic implementation of boost::any (written by Kevlin Henney) when boost dependency is not ...
qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) wi...
bool empty() const
Definition QxAny.h:98
qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) wi...
Root namespace for all QxOrm library features.
ValueType * any_cast(any *)
Definition QxAny.h:133
ValueType * unsafe_any_cast(any *)
Definition QxAny.h:157
static QSharedPointer< T > get(const qx::any &a)
static T * get(const qx::any &a)
static boost::shared_ptr< T > get(const qx::any &a)
static qx::dao::ptr< T > get(const qx::any &a)
static std::shared_ptr< T > get(const qx::any &a)
static T get(const qx::any &a)