QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxBoostOptionalOnly.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_ENABLE_BOOST
33#ifndef _QX_BOOST_OPTIONAL_ONLY_H_
34#define _QX_BOOST_OPTIONAL_ONLY_H_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
47#include <boost/optional.hpp>
48#include <boost/none.hpp>
49
50#include <QxOrm.h>
51
52#define _QX_ENABLE_BOOST
54#undef _QX_ENABLE_BOOST
55
57
59
60namespace qx {
61namespace trait {
62
63template <typename T>
64struct get_sql_type< boost::optional<T> >
65{ static inline const char * get() { return qx::trait::get_sql_type<T>::get(); } };
66
67} // namespace trait
68} // namespace qx
69
70namespace qx {
71namespace cvt {
72namespace detail {
73
74#ifndef _QX_NO_JSON
75
76template <typename T> struct QxConvert_ToJson< boost::optional<T> > {
77static inline QJsonValue toJson(const boost::optional<T> & t, const QString & format)
78{ if (t) { return qx::cvt::to_json((* t), format); }; return QJsonValue(); } };
79
80template <typename T> struct QxConvert_FromJson< boost::optional<T> > {
81static inline qx_bool fromJson(const QJsonValue & j, boost::optional<T> & t, const QString & format)
82{
83 if (j.isNull()) { t = boost::none; return qx_bool(true); }
84 else if (! t) { t = T(); }
85 return qx::cvt::from_json(j, (* t), format);
86} };
87
88#endif // _QX_NO_JSON
89
90template <typename T> struct QxConvert_ToString< boost::optional<T> > {
91static inline QString toString(const boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
92{ if (t) { return qx::cvt::to_string((* t), format, index, ctx); }; return QString(); } };
93
94template <typename T> struct QxConvert_FromString< boost::optional<T> > {
95static inline qx_bool fromString(const QString & s, boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
96{ if (! t) { t = T(); }; return qx::cvt::from_string(s, (* t), format, index, ctx); } };
97
98template <typename T> struct QxConvert_ToVariant< boost::optional<T> > {
99static inline QVariant toVariant(const boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
100{ if (t) { return qx::cvt::to_variant((* t), format, index, ctx); }; return qx::trait::construct_null_qvariant<T>::get(); } };
101
102template <typename T> struct QxConvert_FromVariant< boost::optional<T> > {
103static inline qx_bool fromVariant(const QVariant & v, boost::optional<T> & t, const QString & format, int index, qx::cvt::context::ctx_type ctx)
104{
105 if (v.isNull()) { t = boost::none; return qx_bool(true); }
106 else if (! t) { t = T(); }
107 return qx::cvt::from_variant(v, (* t), format, index, ctx);
108} };
109
110} // namespace detail
111} // namespace cvt
112} // namespace qx
113
114#endif // _QX_BOOST_OPTIONAL_ONLY_H_
115#endif // _QX_ENABLE_BOOST
qx::QxBool qx_bool
Definition QxBool.h:150
Provide a Qt QDataStream serialization method (save/load) for type boost::optional<T>
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
qx::trait::construct_null_qvariant<T>::get() : create a NULL QVariant which matches QVariant::Type wi...
#define QX_REGISTER_CLASS_NAME_TEMPLATE_1(className)
qx_bool from_variant(const QVariant &v, T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
Definition QxConvert.h:80
QVariant to_variant(const T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
Definition QxConvert.h:79
QString to_string(const T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
Definition QxConvert.h:77
qx_bool from_json(const QJsonValue &j, T &t, const QString &format=QString())
Definition QxConvert.h:84
qx_bool from_string(const QString &s, T &t, const QString &format=QString(), int index=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
Definition QxConvert.h:78
QJsonValue to_json(const T &t, const QString &format=QString())
Definition QxConvert.h:83
Root namespace for all QxOrm library features.
static qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
static qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QJsonValue toJson(const T &t, const QString &format)
static QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
static const char * get()