QxOrm  1.4.5
C++ Object Relational Mapping library
QxDump.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** https://www.qxorm.com/
00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
00005 **
00006 ** This file is part of the QxOrm library
00007 **
00008 ** This software is provided 'as-is', without any express or implied
00009 ** warranty. In no event will the authors be held liable for any
00010 ** damages arising from the use of this software
00011 **
00012 ** Commercial Usage
00013 ** Licensees holding valid commercial QxOrm licenses may use this file in
00014 ** accordance with the commercial license agreement provided with the
00015 ** Software or, alternatively, in accordance with the terms contained in
00016 ** a written agreement between you and Lionel Marty
00017 **
00018 ** GNU General Public License Usage
00019 ** Alternatively, this file may be used under the terms of the GNU
00020 ** General Public License version 3.0 as published by the Free Software
00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the
00022 ** packaging of this file. Please review the following information to
00023 ** ensure the GNU General Public License version 3.0 requirements will be
00024 ** met : http://www.gnu.org/copyleft/gpl.html
00025 **
00026 ** If you are unsure which license is appropriate for your use, or
00027 ** if you have questions regarding the use of this file, please contact :
00028 ** contact@qxorm.com
00029 **
00030 ****************************************************************************/
00031 
00032 #ifndef _QX_DUMP_H_
00033 #define _QX_DUMP_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <QxCommon/QxConfig.h>
00047 
00048 #include <QxSerialize/QxSerializeInvoker.h>
00049 #include <QxSerialize/QxSerializeQJson.h>
00050 #include <QxSerialize/QxArchive.h>
00051 
00052 #include <QxRegister/QxClassName.h>
00053 
00054 #ifdef _QX_ENABLE_BOOST_SERIALIZATION
00055 
00056 namespace qx {
00057 
00062 template <class T>
00063 void dump(const T & t, bool bJsonFormat = false)
00064 {
00065    QString sDump;
00066 
00067    if (bJsonFormat)
00068    {
00069 #ifndef _QX_NO_JSON
00070       sDump = qx::serialization::json::to_string(t);
00071 #else // _QX_NO_JSON
00072       sDump = "Unable to dump element in JSON format : you must work with Qt5 and not define _QX_NO_JSON compilation option in 'QxOrm.pri' configuration file";
00073 #endif // _QX_NO_JSON
00074    }
00075    else
00076    {
00077 #if _QX_SERIALIZE_POLYMORPHIC
00078       sDump = qx::serialization::polymorphic_xml::to_string(t);
00079 #elif _QX_SERIALIZE_XML
00080       sDump = qx::serialization::xml::to_string(t);
00081 #elif _QX_SERIALIZE_WIDE_XML
00082       sDump = qx::serialization::wide::xml::to_string(t);
00083 #else // _QX_SERIALIZE_POLYMORPHIC
00084       sDump = "Unable to dump element : you must define '_QX_ENABLE_BOOST_SERIALIZATION' and '_QX_ENABLE_BOOST_SERIALIZATION_XML' (or '_QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML') compilation options in 'QxOrm.pri' configuration file";
00085 #endif // _QX_SERIALIZE_POLYMORPHIC
00086    }
00087 
00088    QString sName = qx::QxClassName<T>::get();
00089    qDebug("[QxOrm] start dump '%s'", qPrintable(sName));
00090    qDebug("%s", qPrintable(sDump));
00091    qDebug("[QxOrm] end dump '%s'", qPrintable(sName));
00092 }
00093 
00094 } // namespace qx
00095 
00096 #else // _QX_ENABLE_BOOST_SERIALIZATION
00097 
00098 namespace qx {
00099 
00100 template <class T>
00101 void dump(const T & t, bool bJsonFormat = true)
00102 {
00103 #ifdef _QX_NO_JSON
00104    qDebug("[QxOrm] qx::dump() : %s", "not implemented when _QX_ENABLE_BOOST_SERIALIZATION compilation option is not defined (XML format) and _QX_NO_JSON compilation option is defined (JSON format)");
00105    Q_UNUSED(t); Q_UNUSED(bJsonFormat);
00106 #else // _QX_NO_JSON
00107    if (! bJsonFormat) { return; }
00108    QString sDump = qx::serialization::json::to_string(t);
00109    QString sName = qx::QxClassName<T>::get();
00110    qDebug("[QxOrm] start dump '%s'", qPrintable(sName));
00111    qDebug("%s", qPrintable(sDump));
00112    qDebug("[QxOrm] end dump '%s'", qPrintable(sName));
00113 #endif // _QX_NO_JSON
00114 }
00115 
00116 } // namespace qx
00117 
00118 #endif // _QX_ENABLE_BOOST_SERIALIZATION
00119 #endif // _QX_DUMP_H_