first commit
This commit is contained in:
199
include/QxCommon/QxAny.h
Normal file
199
include/QxCommon/QxAny.h
Normal file
@@ -0,0 +1,199 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_ANY_H_
|
||||
#define _QX_ANY_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxAny.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief qx::any : basic implementation of boost::any (written by Kevlin Henney) when boost dependency is not available
|
||||
*/
|
||||
|
||||
#ifndef _QX_NO_RTTI
|
||||
#include <typeinfo>
|
||||
#define QX_TYPE_ID(T) typeid(T)
|
||||
#else // _QX_NO_RTTI
|
||||
#include <QxTraits/get_class_name.h>
|
||||
#include <QxTraits/get_class_name_primitive.h>
|
||||
#define QX_TYPE_ID(T) std::string(qx::trait::get_class_name<T>::get())
|
||||
#endif // _QX_NO_RTTI
|
||||
|
||||
#ifndef Q_OS_WIN
|
||||
#if (__GNUC__ >= 4)
|
||||
#define QX_ANY_FORCE_HIDDEN_VISIBILITY __attribute__((visibility("hidden"))) // To avoid a GCC warning : 'qx::any::holder<T>' declared with greater visibility than the type of its field 'qx::any::holder<T>::held' [-Wattributes]
|
||||
#endif // (__GNUC__ >= 4)
|
||||
#endif // Q_OS_WIN
|
||||
|
||||
#ifndef QX_ANY_FORCE_HIDDEN_VISIBILITY
|
||||
#define QX_ANY_FORCE_HIDDEN_VISIBILITY /* Nothing */
|
||||
#endif // QX_ANY_FORCE_HIDDEN_VISIBILITY
|
||||
|
||||
namespace qx
|
||||
{
|
||||
|
||||
class any;
|
||||
template <typename ValueType>
|
||||
ValueType *any_cast(any *);
|
||||
template <typename ValueType>
|
||||
ValueType *unsafe_any_cast(any *);
|
||||
|
||||
class any
|
||||
{
|
||||
|
||||
template <typename ValueType>
|
||||
friend ValueType *qx::any_cast(any *);
|
||||
template <typename ValueType>
|
||||
friend ValueType *qx::unsafe_any_cast(any *);
|
||||
|
||||
public:
|
||||
#ifndef _QX_NO_RTTI
|
||||
typedef const std::type_info &type_check;
|
||||
#else // _QX_NO_RTTI
|
||||
typedef std::string type_check;
|
||||
#endif // _QX_NO_RTTI
|
||||
|
||||
any() : content(NULL) { ; }
|
||||
any(const any &other) : content(other.content ? other.content->clone() : NULL) { ; }
|
||||
~any()
|
||||
{
|
||||
if (content)
|
||||
{
|
||||
delete content;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
any(const ValueType &value) : content(new holder<typename std::remove_cv<typename std::decay<const ValueType>::type>::type>(value)) { ; }
|
||||
|
||||
any &swap(any &other)
|
||||
{
|
||||
std::swap(content, other.content);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
any &operator=(const ValueType &other)
|
||||
{
|
||||
any(other).swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
|
||||
any &operator=(any other)
|
||||
{
|
||||
any(other).swap(*this);
|
||||
return (*this);
|
||||
}
|
||||
bool empty() const { return (!content); }
|
||||
void clear() { any().swap(*this); }
|
||||
type_check type() const { return (content ? content->type() : QX_TYPE_ID(void)); }
|
||||
|
||||
private:
|
||||
struct placeholder
|
||||
{
|
||||
virtual ~placeholder() { ; }
|
||||
virtual type_check type() const = 0;
|
||||
virtual placeholder *clone() const = 0;
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
struct QX_ANY_FORCE_HIDDEN_VISIBILITY holder : public placeholder
|
||||
{
|
||||
holder(const ValueType &value) : held(value) { ; }
|
||||
virtual type_check type() const { return QX_TYPE_ID(ValueType); }
|
||||
virtual placeholder *clone() const { return new holder(held); }
|
||||
ValueType held;
|
||||
|
||||
private:
|
||||
holder &operator=(const holder &);
|
||||
};
|
||||
|
||||
placeholder *content;
|
||||
};
|
||||
|
||||
inline void swap(any &lhs, any &other) { lhs.swap(other); }
|
||||
|
||||
struct bad_any_cast : public std::exception
|
||||
{
|
||||
virtual const char *what() const throw() { return "qx::bad_any_cast : failed conversion using qx::any_cast"; }
|
||||
};
|
||||
|
||||
template <typename ValueType>
|
||||
ValueType *any_cast(any *operand)
|
||||
{
|
||||
return ((operand && (operand->type() == QX_TYPE_ID(ValueType))) ? (&static_cast<any::holder<typename std::remove_cv<ValueType>::type> *>(operand->content)->held) : NULL);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
const ValueType *any_cast(const any *operand)
|
||||
{
|
||||
return any_cast<ValueType>(const_cast<any *>(operand));
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
ValueType any_cast(any &operand)
|
||||
{
|
||||
typedef typename std::remove_reference<ValueType>::type nonref;
|
||||
nonref *result = any_cast<nonref>(&operand);
|
||||
if (!result)
|
||||
{
|
||||
throw qx::bad_any_cast();
|
||||
}
|
||||
return static_cast<ValueType>(*result);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
ValueType any_cast(const any &operand)
|
||||
{
|
||||
typedef typename std::remove_reference<ValueType>::type nonref;
|
||||
return any_cast<const nonref &>(const_cast<any &>(operand));
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
ValueType *unsafe_any_cast(any *operand)
|
||||
{
|
||||
return (&static_cast<any::holder<ValueType> *>(operand->content)->held);
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
const ValueType *unsafe_any_cast(const any *operand)
|
||||
{
|
||||
return unsafe_any_cast<ValueType>(const_cast<any *>(operand));
|
||||
}
|
||||
|
||||
} // namespace qx
|
||||
|
||||
#endif // _QX_ANY_H_
|
||||
162
include/QxCommon/QxAnyCastDynamic.h
Normal file
162
include/QxCommon/QxAnyCastDynamic.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_ANY_CAST_DYNAMIC_H_
|
||||
#define _QX_ANY_CAST_DYNAMIC_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxAnyCastDynamic.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief qx::any_cast_dynamic<T>::get() : provides a tool to use qx::any_cast and polymorphism
|
||||
*/
|
||||
|
||||
#include <QtCore/qsharedpointer.h>
|
||||
|
||||
#include <QxCommon/QxAny.h>
|
||||
|
||||
#include <QxDao/QxDaoPointer.h>
|
||||
|
||||
namespace qx
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
struct any_cast_dynamic
|
||||
{
|
||||
static T get(const qx::any &a) { return qx::any_cast<T>(a); }
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct any_cast_dynamic<T *>
|
||||
{
|
||||
static T *get(const qx::any &a)
|
||||
{
|
||||
if (a.empty())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
qx::any *b = const_cast<qx::any *>(&a);
|
||||
T **t = qx::unsafe_any_cast<T *>(b);
|
||||
if (!t)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return (*t);
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST
|
||||
|
||||
template <typename T>
|
||||
struct any_cast_dynamic<boost::shared_ptr<T>>
|
||||
{
|
||||
static boost::shared_ptr<T> get(const qx::any &a)
|
||||
{
|
||||
if (a.empty())
|
||||
{
|
||||
return boost::shared_ptr<T>();
|
||||
}
|
||||
qx::any *b = const_cast<qx::any *>(&a);
|
||||
boost::shared_ptr<T> *t = qx::unsafe_any_cast<boost::shared_ptr<T>>(b);
|
||||
if (!t)
|
||||
{
|
||||
return boost::shared_ptr<T>();
|
||||
}
|
||||
return (*t);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _QX_ENABLE_BOOST
|
||||
|
||||
template <typename T>
|
||||
struct any_cast_dynamic<QSharedPointer<T>>
|
||||
{
|
||||
static QSharedPointer<T> get(const qx::any &a)
|
||||
{
|
||||
if (a.empty())
|
||||
{
|
||||
return QSharedPointer<T>();
|
||||
}
|
||||
qx::any *b = const_cast<qx::any *>(&a);
|
||||
QSharedPointer<T> *t = qx::unsafe_any_cast<QSharedPointer<T>>(b);
|
||||
if (!t)
|
||||
{
|
||||
return QSharedPointer<T>();
|
||||
}
|
||||
return (*t);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct any_cast_dynamic<qx::dao::ptr<T>>
|
||||
{
|
||||
static qx::dao::ptr<T> get(const qx::any &a)
|
||||
{
|
||||
if (a.empty())
|
||||
{
|
||||
return qx::dao::ptr<T>();
|
||||
}
|
||||
qx::any *b = const_cast<qx::any *>(&a);
|
||||
qx::dao::ptr<T> *t = qx::unsafe_any_cast<qx::dao::ptr<T>>(b);
|
||||
if (!t)
|
||||
{
|
||||
return qx::dao::ptr<T>();
|
||||
}
|
||||
return (*t);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct any_cast_dynamic<std::shared_ptr<T>>
|
||||
{
|
||||
static std::shared_ptr<T> get(const qx::any &a)
|
||||
{
|
||||
if (a.empty())
|
||||
{
|
||||
return std::shared_ptr<T>();
|
||||
}
|
||||
qx::any *b = const_cast<qx::any *>(&a);
|
||||
std::shared_ptr<T> *t = qx::unsafe_any_cast<std::shared_ptr<T>>(b);
|
||||
if (!t)
|
||||
{
|
||||
return std::shared_ptr<T>();
|
||||
}
|
||||
return (*t);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace qx
|
||||
|
||||
#endif // _QX_ANY_CAST_DYNAMIC_H_
|
||||
190
include/QxCommon/QxBool.h
Normal file
190
include/QxCommon/QxBool.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_BOOL_H_
|
||||
#define _QX_BOOL_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxBool.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief qx_bool : QxOrm library boolean type with code and description message when an error occured
|
||||
*/
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION
|
||||
|
||||
#include <QtCore/qdatastream.h>
|
||||
|
||||
#include <QxSerialize/Qt/QxSerialize_QString.h>
|
||||
|
||||
#include <QxTraits/get_class_name.h>
|
||||
|
||||
namespace qx
|
||||
{
|
||||
class QxBool;
|
||||
} // namespace qx
|
||||
|
||||
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxBool &t) QX_USED;
|
||||
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxBool &t) QX_USED;
|
||||
|
||||
namespace qx
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCommon
|
||||
* \brief qx_bool : boolean type with code and description message when an error occured
|
||||
*/
|
||||
class QxBool
|
||||
{
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
|
||||
friend class boost::serialization::access;
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION
|
||||
|
||||
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxBool &t);
|
||||
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxBool &t);
|
||||
|
||||
private:
|
||||
bool m_bValue; //!< Data boolean value
|
||||
long m_lCode; //!< Error code when value is false
|
||||
QString m_sDesc; //!< Error description when value is false
|
||||
|
||||
public:
|
||||
QxBool() : m_bValue(false), m_lCode(0) { ; }
|
||||
QxBool(bool b) : m_bValue(b), m_lCode(0) { qAssert(checkInitialized(b)); }
|
||||
QxBool(long lCode, const QString &sDesc) : m_bValue(false), m_lCode(lCode), m_sDesc(sDesc) { ; }
|
||||
QxBool(bool bValue, long lCode, const QString &sDesc) : m_bValue(bValue), m_lCode(lCode), m_sDesc(sDesc) { qAssert(checkInitialized(bValue)); }
|
||||
QxBool(const QxBool &other) : m_bValue(other.getValue()), m_lCode(other.getCode()), m_sDesc(other.getDesc()) { ; }
|
||||
~QxBool() { ; }
|
||||
|
||||
inline bool getValue() const { return m_bValue; }
|
||||
inline long getCode() const { return m_lCode; }
|
||||
inline QString getDesc() const { return m_sDesc; }
|
||||
|
||||
inline void setValue(bool bValue)
|
||||
{
|
||||
m_bValue = bValue;
|
||||
qAssert(checkInitialized(bValue));
|
||||
}
|
||||
inline void setCode(long lCode) { m_lCode = lCode; }
|
||||
inline void setDesc(const QString &sDesc) { m_sDesc = sDesc; }
|
||||
|
||||
inline QxBool &operator=(const QxBool &other)
|
||||
{
|
||||
m_bValue = other.getValue();
|
||||
m_lCode = other.getCode();
|
||||
m_sDesc = other.getDesc();
|
||||
return (*this);
|
||||
}
|
||||
inline QxBool &operator=(const bool b)
|
||||
{
|
||||
m_bValue = b;
|
||||
qAssert(checkInitialized(b));
|
||||
return (*this);
|
||||
}
|
||||
|
||||
inline operator bool() const { return (m_bValue != false); }
|
||||
inline bool operator!() const { return (m_bValue == false); }
|
||||
|
||||
inline bool operator==(const QxBool &other) const { return ((m_bValue == other.getValue()) && (m_lCode == other.getCode()) && (m_sDesc == other.getDesc())); }
|
||||
inline bool operator==(const bool b) const
|
||||
{
|
||||
qAssert(checkInitialized(b));
|
||||
return (m_bValue == b);
|
||||
}
|
||||
inline bool operator!=(const QxBool &other) const { return ((m_bValue != other.getValue()) || (m_lCode != other.getCode()) || (m_sDesc != other.getDesc())); }
|
||||
inline bool operator!=(const bool b) const
|
||||
{
|
||||
qAssert(checkInitialized(b));
|
||||
return (m_bValue != b);
|
||||
}
|
||||
inline bool operator&&(const QxBool &other) const { return (m_bValue && other.getValue()); }
|
||||
inline bool operator&&(const bool b) const
|
||||
{
|
||||
qAssert(checkInitialized(b));
|
||||
return (m_bValue && b);
|
||||
}
|
||||
inline bool operator||(const QxBool &other) const { return (m_bValue || other.getValue()); }
|
||||
inline bool operator||(const bool b) const
|
||||
{
|
||||
qAssert(checkInitialized(b));
|
||||
return (m_bValue || b);
|
||||
}
|
||||
|
||||
QString toString() const { return (QString(m_bValue ? "1" : "0") + "|" + QString::number(static_cast<qlonglong>(m_lCode)) + "|" + m_sDesc); }
|
||||
|
||||
void fromString(const QString &s)
|
||||
{
|
||||
if (s.trimmed().isEmpty())
|
||||
{
|
||||
(*this) = QxBool();
|
||||
return;
|
||||
}
|
||||
bool bValue = s.startsWith("1");
|
||||
int iPos = s.indexOf("|", 2);
|
||||
if (iPos == -1)
|
||||
{
|
||||
(*this) = QxBool(bValue);
|
||||
return;
|
||||
}
|
||||
long lCode = s.mid(2, (iPos - 2)).toLong();
|
||||
QString sDesc = s.right(s.size() - (iPos + 1));
|
||||
(*this) = QxBool(bValue, lCode, sDesc);
|
||||
}
|
||||
|
||||
private:
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
|
||||
template <class Archive>
|
||||
void serialize(Archive &ar, const unsigned int file_version)
|
||||
{
|
||||
Q_UNUSED(file_version);
|
||||
ar &boost::serialization::make_nvp("value", m_bValue);
|
||||
ar &boost::serialization::make_nvp("code", m_lCode);
|
||||
ar &boost::serialization::make_nvp("desc", m_sDesc);
|
||||
}
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION
|
||||
|
||||
inline bool checkInitialized(const bool b) const { return ((static_cast<int>(b) == 0) || (static_cast<int>(b) == 1)); }
|
||||
};
|
||||
|
||||
} // namespace qx
|
||||
|
||||
typedef qx::QxBool qx_bool;
|
||||
QX_REGISTER_CLASS_NAME(qx_bool)
|
||||
|
||||
#endif // _QX_BOOL_H_
|
||||
264
include/QxCommon/QxCache.h
Normal file
264
include/QxCommon/QxCache.h
Normal file
@@ -0,0 +1,264 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_CACHE_H_
|
||||
#define _QX_CACHE_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxCache.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCache
|
||||
* \brief qx::cache : based on singleton pattern, provide basic thread-safe cache feature to backup and restore any kind of objects (for example, object fetched from database)
|
||||
*/
|
||||
|
||||
#include <QxCommon/QxBool.h>
|
||||
#include <QxCommon/QxAny.h>
|
||||
|
||||
#include <QxCollection/QxCollection.h>
|
||||
|
||||
#include <QxSingleton/QxSingleton.h>
|
||||
|
||||
namespace qx
|
||||
{
|
||||
namespace cache
|
||||
{
|
||||
namespace detail
|
||||
{
|
||||
|
||||
class QX_DLL_EXPORT QxCache : public qx::QxSingleton<QxCache>
|
||||
{
|
||||
|
||||
friend class qx::QxSingleton<QxCache>;
|
||||
|
||||
protected:
|
||||
typedef std::tuple<long, QDateTime, qx::any> type_qx_cache;
|
||||
typedef qx::QxCollection<QString, type_qx_cache> type_qx_lst_cache;
|
||||
|
||||
type_qx_lst_cache m_cache; //!< List of objects in cache under qx::any format
|
||||
QMutex m_oMutexCache; //!< Mutex => 'QxCache' is thread-safe
|
||||
long m_lMaxCost; //!< Max cost before deleting object in cache
|
||||
long m_lCurrCost; //!< Current cost in cache
|
||||
|
||||
public:
|
||||
QxCache();
|
||||
virtual ~QxCache();
|
||||
|
||||
long getCurrCost() const;
|
||||
long getMaxCost() const;
|
||||
void setMaxCost(long l);
|
||||
|
||||
long count() const;
|
||||
long size() const;
|
||||
bool isEmpty() const;
|
||||
bool exist(const QString &sKey) const;
|
||||
bool contains(const QString &sKey) const;
|
||||
qx::any at(const QString &sKey);
|
||||
long insertionCost(const QString &sKey);
|
||||
QDateTime insertionDateTime(const QString &sKey);
|
||||
void clear();
|
||||
|
||||
bool insert(const QString &sKey, const qx::any &anyObj, long lCost = 1, const QDateTime &dt = QDateTime());
|
||||
bool remove(const QString &sKey);
|
||||
|
||||
private:
|
||||
void updateCost();
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
} // namespace cache
|
||||
} // namespace qx
|
||||
|
||||
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::cache::detail::QxCache)
|
||||
|
||||
namespace qx
|
||||
{
|
||||
namespace cache
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Set the maximum allowed total cost of the cache to l. If the current total cost is greater than l, some objects are deleted immediately
|
||||
*/
|
||||
inline void max_cost(long l)
|
||||
{
|
||||
qx::cache::detail::QxCache::getSingleton()->setMaxCost(l);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return the maximum allowed total cost of the cache
|
||||
*/
|
||||
inline long max_cost()
|
||||
{
|
||||
return qx::cache::detail::QxCache::getSingleton()->getMaxCost();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return the current cost used by the cache
|
||||
*/
|
||||
inline long current_cost()
|
||||
{
|
||||
return qx::cache::detail::QxCache::getSingleton()->getCurrCost();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return the number of objects in the cache
|
||||
*/
|
||||
inline long count()
|
||||
{
|
||||
return qx::cache::detail::QxCache::getSingleton()->count();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return true if the cache contains no object; otherwise return false
|
||||
*/
|
||||
inline bool is_empty()
|
||||
{
|
||||
return qx::cache::detail::QxCache::getSingleton()->isEmpty();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Delete all the objects in the cache
|
||||
*/
|
||||
inline void clear()
|
||||
{
|
||||
qx::cache::detail::QxCache::getSingleton()->clear();
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return true if the cache contains an object associated with key sKey; otherwise return false
|
||||
*/
|
||||
inline bool exist(const QString &sKey)
|
||||
{
|
||||
return qx::cache::detail::QxCache::getSingleton()->exist(sKey);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Delete the object associated with key sKey. Return true if the object was found in the cache; otherwise return false
|
||||
*/
|
||||
inline bool remove(const QString &sKey)
|
||||
{
|
||||
return qx::cache::detail::QxCache::getSingleton()->remove(sKey);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Insert object t into the cache with key sKey, associated cost lCost and insertion date-time dt. Any object with the same key already in the cache will be removed
|
||||
*/
|
||||
template <typename T>
|
||||
inline bool set(const QString &sKey, T &t, long lCost = 1, const QDateTime &dt = QDateTime())
|
||||
{
|
||||
qx::any obj(t);
|
||||
return qx::cache::detail::QxCache::getSingleton()->insert(sKey, obj, lCost, dt);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return the object of type T associated with key sKey, or return default instance of T() if the key does not exist in the cache
|
||||
*/
|
||||
template <typename T>
|
||||
inline T get(const QString &sKey)
|
||||
{
|
||||
qx::any obj = qx::cache::detail::QxCache::getSingleton()->at(sKey);
|
||||
if (obj.empty())
|
||||
{
|
||||
return T();
|
||||
}
|
||||
try
|
||||
{
|
||||
return qx::any_cast<T>(obj);
|
||||
}
|
||||
catch (const qx::bad_any_cast &err)
|
||||
{
|
||||
Q_UNUSED(err);
|
||||
return T();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return T();
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return true if object t can be fetched with associated key sKey and insertion date-time dt; otherwise return false with an error description
|
||||
*/
|
||||
template <typename T>
|
||||
inline qx_bool get(const QString &sKey, T &t, QDateTime &dt)
|
||||
{
|
||||
dt = QDateTime();
|
||||
if (!qx::cache::exist(sKey))
|
||||
{
|
||||
return qx_bool(false, 0, "[QxOrm] qx::cache : key doesn't exist in cache");
|
||||
}
|
||||
qx::any obj = qx::cache::detail::QxCache::getSingleton()->at(sKey);
|
||||
dt = qx::cache::detail::QxCache::getSingleton()->insertionDateTime(sKey);
|
||||
try
|
||||
{
|
||||
t = qx::any_cast<T>(obj);
|
||||
return qx_bool(true);
|
||||
}
|
||||
catch (const qx::bad_any_cast &err)
|
||||
{
|
||||
Q_UNUSED(err);
|
||||
return qx_bool(false, 0, "[QxOrm] qx::cache : bad any cast exception");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return qx_bool(false, 0, "[QxOrm] qx::cache : unknown cast exception");
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Return true if object t can be fetched with associated key sKey; otherwise return false with an error description
|
||||
*/
|
||||
template <typename T>
|
||||
inline qx_bool get(const QString &sKey, T &t)
|
||||
{
|
||||
QDateTime dt;
|
||||
return qx::cache::get<T>(sKey, t, dt);
|
||||
}
|
||||
|
||||
} // namespace cache
|
||||
} // namespace qx
|
||||
|
||||
#endif // _QX_CACHE_H_
|
||||
184
include/QxCommon/QxConfig.h
Normal file
184
include/QxCommon/QxConfig.h
Normal file
@@ -0,0 +1,184 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_CONFIG_H_
|
||||
#define _QX_CONFIG_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxConfig.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief List of parameters to compile and build QxOrm library
|
||||
*/
|
||||
|
||||
#define QX_VERSION 0x010500
|
||||
#define QX_VERSION_STR "1.5.0"
|
||||
|
||||
#ifndef _QX_MODE_DEBUG
|
||||
#ifndef _QX_MODE_RELEASE
|
||||
#ifdef QT_NO_DEBUG
|
||||
#define _QX_MODE_RELEASE
|
||||
#else // QT_NO_DEBUG
|
||||
#define _QX_MODE_DEBUG
|
||||
#endif // QT_NO_DEBUG
|
||||
#endif // _QX_MODE_RELEASE
|
||||
#endif // _QX_MODE_DEBUG
|
||||
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#define _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#define _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
|
||||
#ifndef _QX_ENABLE_BOOST_SERIALIZATION
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#undef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#define _QX_SERIALIZE_POLYMORPHIC 1
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
#define _QX_SERIALIZE_POLYMORPHIC 0
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#define _QX_SERIALIZE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
#define _QX_SERIALIZE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#define _QX_SERIALIZE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
#define _QX_SERIALIZE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#define _QX_SERIALIZE_XML (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
#define _QX_SERIALIZE_XML (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_XML
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#define _QX_SERIALIZE_PORTABLE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
#define _QX_SERIALIZE_PORTABLE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#define _QX_SERIALIZE_WIDE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
#define _QX_SERIALIZE_WIDE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#define _QX_SERIALIZE_WIDE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
#define _QX_SERIALIZE_WIDE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#define _QX_SERIALIZE_WIDE_XML (!_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
#define _QX_SERIALIZE_WIDE_XML (!_QX_SERIALIZE_POLYMORPHIC && 0)
|
||||
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
|
||||
|
||||
#define _QX_AUTO_REGISTER_REPOSITORY 0
|
||||
#define _QX_USE_MEM_LEAK_DETECTION 0
|
||||
#define _QX_USE_EXPORT_DLL_BOOST_SERIALIZATION_SINGLETON 1
|
||||
#define _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER 0
|
||||
#define _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP 0
|
||||
#define _QX_WRITE_BOOST_CLASS_EXPORT_IN_HPP_FILE 0
|
||||
#define _QX_WRITE_BOOST_CLASS_EXPORT_IN_CPP_FILE 1
|
||||
#define _QX_INCLUDE_BOOST_SERIALIZE_EXPORT_HPP_INTO_QX_MEM_LEAK_HPP 1
|
||||
#define _QX_INCLUDE_BOOST_SERIALIZE_ARCHIVE_IMPL_IPP 0
|
||||
#define _QX_MEM_LEAK_ONLY_KNOWN_SRC_FILE 1
|
||||
#define _QX_SUPPORT_BOOST_SERIALIZE_SHARED_PTR_132 0
|
||||
#define _QX_USE_QX_CONVERT_EXPORT 0
|
||||
#define _QX_USE_GCC_EXPORT_ALL_SYMBOLS 0
|
||||
#define _QX_USE_GCC_VISIBILITY 0
|
||||
#define _QX_USE_ASSERT 1
|
||||
#define _QX_SUPPORT_COVARIANT_RETURN_TYPE 1
|
||||
#define _QX_USE_QX_SINGLETON_X 1
|
||||
|
||||
#ifdef _MSC_VER
|
||||
/* -- Link error with VC++ 9.0 => Qt uses "-Zc:wchar_t-" option to compile and boost serialization library is compiled without this option -- */
|
||||
#define _QX_USE_SERIALIZE_POLYMORPHIC_PATCH (_QX_SERIALIZE_POLYMORPHIC && 1)
|
||||
#else // _MSC_VER
|
||||
#define _QX_USE_SERIALIZE_POLYMORPHIC_PATCH 0
|
||||
#endif // _MSC_VER
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
#ifndef _QX_NO_JSON
|
||||
#define _QX_NO_JSON
|
||||
#endif // _QX_NO_JSON
|
||||
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
#endif // _QX_CONFIG_H_
|
||||
83
include/QxCommon/QxException.h
Normal file
83
include/QxCommon/QxException.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_EXCEPTION_H_
|
||||
#define _QX_EXCEPTION_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxException.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief Exception with error code and error description
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
|
||||
#include <QxCommon/QxBool.h>
|
||||
|
||||
namespace qx
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCommon
|
||||
* \brief qx::exception : exception with error code and error description
|
||||
*/
|
||||
class exception : public std::exception
|
||||
{
|
||||
|
||||
private:
|
||||
long m_code; //!< Error code
|
||||
QString m_desc; //!< Error description
|
||||
QString m_what; //!< Formatted error : code + "^" + description
|
||||
|
||||
public:
|
||||
exception(const QString &desc) : std::exception(), m_code(0), m_desc(desc) { updateWhat(); }
|
||||
exception(long code, const QString &desc) : std::exception(), m_code(code), m_desc(desc) { updateWhat(); }
|
||||
virtual ~exception() throw() { ; }
|
||||
|
||||
virtual const char *what() const throw() { return qPrintable(m_what); }
|
||||
|
||||
long getCode() const { return m_code; }
|
||||
QString getDescription() const { return m_desc; }
|
||||
qx_bool toQxBool() const { return qx_bool(m_code, m_desc); }
|
||||
|
||||
private:
|
||||
void updateWhat() { m_what = (QString::number(m_code) + QString("^") + m_desc); }
|
||||
};
|
||||
|
||||
} // namespace qx
|
||||
|
||||
#endif // _QX_EXCEPTION_H_
|
||||
64
include/QxCommon/QxExceptionCode.h
Normal file
64
include/QxCommon/QxExceptionCode.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_EXCEPTION_CODE_H_
|
||||
#define _QX_EXCEPTION_CODE_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxExceptionCode.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief Some errors codes defined by QxOrm library
|
||||
*/
|
||||
|
||||
#include <QxCommon/QxException.h>
|
||||
|
||||
#define QX_ERROR_UNKNOWN 1
|
||||
#define QX_ERROR_SERVICE_NOT_SPECIFIED 2
|
||||
#define QX_ERROR_SERVICE_INVALID 3
|
||||
#define QX_ERROR_SERVER_NOT_FOUND 4
|
||||
#define QX_ERROR_SERVICE_WRITE_ERROR 5
|
||||
#define QX_ERROR_SERVICE_READ_ERROR 6
|
||||
#define QX_ERROR_SERVICE_SSL_ENCRYPTED 7
|
||||
|
||||
#define QX_EXCEPTION_UNKNOWN qx::exception(QX_ERROR_UNKNOWN, "unknown error")
|
||||
#define QX_EXCEPTION_SERVICE_NOT_SPECIFIED qx::exception(QX_ERROR_SERVICE_NOT_SPECIFIED, "[QxOrm] empty service name")
|
||||
#define QX_EXCEPTION_SERVICE_INVALID qx::exception(QX_ERROR_SERVICE_INVALID, "[QxOrm] invalid service")
|
||||
#define QX_EXCEPTION_SERVER_NOT_FOUND qx::exception(QX_ERROR_SERVER_NOT_FOUND, "[QxOrm] unable to connect to server")
|
||||
#define QX_EXCEPTION_SERVICE_WRITE_ERROR qx::exception(QX_ERROR_SERVICE_WRITE_ERROR, "[QxOrm] unable to write request to socket")
|
||||
#define QX_EXCEPTION_SERVICE_READ_ERROR qx::exception(QX_ERROR_SERVICE_READ_ERROR, "[QxOrm] unable to read reply from socket")
|
||||
#define QX_EXCEPTION_SERVICE_SSL_ENCRYPTED qx::exception(QX_ERROR_SERVICE_SSL_ENCRYPTED, "[QxOrm] SSL socket encrypted error")
|
||||
|
||||
#endif // _QX_EXCEPTION_CODE_H_
|
||||
493
include/QxCommon/QxHashValue.h
Normal file
493
include/QxCommon/QxHashValue.h
Normal file
@@ -0,0 +1,493 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_HASH_VALUE_H_
|
||||
#define _QX_HASH_VALUE_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxHashValue.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief Specialize hash_value function for some Qt and boost types (used for example by qx::QxCollection<Key, Value> container)
|
||||
*/
|
||||
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qdatetime.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QtCore/qpair.h>
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
#define qx_hash_result uint
|
||||
#else // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
#define qx_hash_result std::size_t
|
||||
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
|
||||
inline std::size_t hash_value(const QString &s) { return qHash(s); }
|
||||
inline std::size_t hash_value(const QVariant &v) { return qHash(v.toString()); }
|
||||
inline std::size_t hash_value(const QDate &d) { return qHash(d.toJulianDay()); }
|
||||
inline std::size_t hash_value(const QTime &t) { return qHash(t.toString()); }
|
||||
inline std::size_t hash_value(const QDateTime &dt) { return qHash(dt.toString()); }
|
||||
|
||||
inline qx_hash_result qHash(const QVariant &v) { return static_cast<qx_hash_result>(hash_value(v)); }
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
inline qx_hash_result qHash(const QDate &d) { return static_cast<qx_hash_result>(hash_value(d)); }
|
||||
inline qx_hash_result qHash(const QTime &t) { return static_cast<qx_hash_result>(hash_value(t)); }
|
||||
inline qx_hash_result qHash(const QDateTime &dt) { return static_cast<qx_hash_result>(hash_value(dt)); }
|
||||
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
|
||||
|
||||
namespace qx
|
||||
{
|
||||
template <class T>
|
||||
inline void hash_combine(std::size_t &seed, const T &t)
|
||||
{
|
||||
seed ^= qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
|
||||
}
|
||||
} // namespace qx
|
||||
|
||||
template <typename T0, typename T1>
|
||||
inline std::size_t hash_value(const QPair<T0, T1> &p)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, p.first);
|
||||
qx::hash_combine(seed, p.second);
|
||||
return seed;
|
||||
}
|
||||
|
||||
#ifdef _QX_ENABLE_BOOST
|
||||
|
||||
namespace boost
|
||||
{
|
||||
namespace tuples
|
||||
{
|
||||
|
||||
template <typename T0, typename T1>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, class T1, typename T2>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
qx::hash_combine(seed, boost::get<4>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
qx::hash_combine(seed, boost::get<4>(tu));
|
||||
qx::hash_combine(seed, boost::get<5>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
qx::hash_combine(seed, boost::get<4>(tu));
|
||||
qx::hash_combine(seed, boost::get<5>(tu));
|
||||
qx::hash_combine(seed, boost::get<6>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
qx::hash_combine(seed, boost::get<4>(tu));
|
||||
qx::hash_combine(seed, boost::get<5>(tu));
|
||||
qx::hash_combine(seed, boost::get<6>(tu));
|
||||
qx::hash_combine(seed, boost::get<7>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
qx::hash_combine(seed, boost::get<4>(tu));
|
||||
qx::hash_combine(seed, boost::get<5>(tu));
|
||||
qx::hash_combine(seed, boost::get<6>(tu));
|
||||
qx::hash_combine(seed, boost::get<7>(tu));
|
||||
qx::hash_combine(seed, boost::get<8>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, boost::get<0>(tu));
|
||||
qx::hash_combine(seed, boost::get<1>(tu));
|
||||
qx::hash_combine(seed, boost::get<2>(tu));
|
||||
qx::hash_combine(seed, boost::get<3>(tu));
|
||||
qx::hash_combine(seed, boost::get<4>(tu));
|
||||
qx::hash_combine(seed, boost::get<5>(tu));
|
||||
qx::hash_combine(seed, boost::get<6>(tu));
|
||||
qx::hash_combine(seed, boost::get<7>(tu));
|
||||
qx::hash_combine(seed, boost::get<8>(tu));
|
||||
qx::hash_combine(seed, boost::get<9>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, class T1, typename T2>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
} // namespace tuples
|
||||
} // namespace boost
|
||||
|
||||
#endif // _QX_ENABLE_BOOST
|
||||
|
||||
// Compilation option '_QX_HASH_NO_STD_NAMESPACE'
|
||||
// Try to avoid compilation error, something like : error: no matching function for call to 'qHash(const std::tuple<...>&)'
|
||||
// This is due to C++ ADL to resolve specialized functions : qHash(T) should be implemented in the same namespace as T
|
||||
// For 'std' classes, it should be NOT allowed : the behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std
|
||||
// More details here : https://www.kdab.com/how-to-declare-a-qhash-overload/
|
||||
// And here : https://stackoverflow.com/questions/47460098/using-standard-library-types-as-keys-in-qhash-or-qset
|
||||
#ifndef _QX_HASH_NO_STD_NAMESPACE
|
||||
namespace std
|
||||
{
|
||||
#endif // _QX_HASH_NO_STD_NAMESPACE
|
||||
|
||||
#ifndef QT_NO_STL
|
||||
inline qx_hash_result qHash(const std::string &s)
|
||||
{
|
||||
QString tmp = QString::fromStdString(s);
|
||||
return qHash(tmp);
|
||||
}
|
||||
inline qx_hash_result qHash(const std::wstring &s)
|
||||
{
|
||||
QString tmp = QString::fromStdWString(s);
|
||||
return qHash(tmp);
|
||||
}
|
||||
#else // QT_NO_STL
|
||||
inline qx_hash_result qHash(const std::string &s)
|
||||
{
|
||||
QString tmp = QString::fromLatin1(s.data(), int(s.size()));
|
||||
return qHash(tmp);
|
||||
}
|
||||
inline qx_hash_result qHash(const std::wstring &s)
|
||||
{
|
||||
qAssert(false); /* Need STL compatibility ! */
|
||||
return 0;
|
||||
}
|
||||
#endif // QT_NO_STL
|
||||
|
||||
template <typename T0, typename T1>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, class T1, typename T2>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
qx::hash_combine(seed, std::get<4>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
qx::hash_combine(seed, std::get<4>(tu));
|
||||
qx::hash_combine(seed, std::get<5>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
qx::hash_combine(seed, std::get<4>(tu));
|
||||
qx::hash_combine(seed, std::get<5>(tu));
|
||||
qx::hash_combine(seed, std::get<6>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
qx::hash_combine(seed, std::get<4>(tu));
|
||||
qx::hash_combine(seed, std::get<5>(tu));
|
||||
qx::hash_combine(seed, std::get<6>(tu));
|
||||
qx::hash_combine(seed, std::get<7>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
qx::hash_combine(seed, std::get<4>(tu));
|
||||
qx::hash_combine(seed, std::get<5>(tu));
|
||||
qx::hash_combine(seed, std::get<6>(tu));
|
||||
qx::hash_combine(seed, std::get<7>(tu));
|
||||
qx::hash_combine(seed, std::get<8>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, std::get<0>(tu));
|
||||
qx::hash_combine(seed, std::get<1>(tu));
|
||||
qx::hash_combine(seed, std::get<2>(tu));
|
||||
qx::hash_combine(seed, std::get<3>(tu));
|
||||
qx::hash_combine(seed, std::get<4>(tu));
|
||||
qx::hash_combine(seed, std::get<5>(tu));
|
||||
qx::hash_combine(seed, std::get<6>(tu));
|
||||
qx::hash_combine(seed, std::get<7>(tu));
|
||||
qx::hash_combine(seed, std::get<8>(tu));
|
||||
qx::hash_combine(seed, std::get<9>(tu));
|
||||
return seed;
|
||||
}
|
||||
|
||||
#if ((QT_VERSION < QT_VERSION_CHECK(5, 7, 0)) || ((QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))))
|
||||
template <typename T0, typename T1>
|
||||
inline qx_hash_result qHash(const std::pair<T0, T1> &p)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
qx::hash_combine(seed, p.first);
|
||||
qx::hash_combine(seed, p.second);
|
||||
return static_cast<qx_hash_result>(seed);
|
||||
}
|
||||
#endif // ((QT_VERSION < QT_VERSION_CHECK(5, 7, 0)) || ((QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))))
|
||||
|
||||
template <typename T0, typename T1>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, class T1, typename T2>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
|
||||
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
|
||||
{
|
||||
return static_cast<qx_hash_result>(hash_value(tu));
|
||||
}
|
||||
|
||||
#ifndef _QX_HASH_NO_STD_NAMESPACE
|
||||
} // namespace std
|
||||
#endif // _QX_HASH_NO_STD_NAMESPACE
|
||||
|
||||
#endif // _QX_HASH_VALUE_H_
|
||||
298
include/QxCommon/QxMacro.h
Normal file
298
include/QxCommon/QxMacro.h
Normal file
@@ -0,0 +1,298 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_MACRO_H_
|
||||
#define _QX_MACRO_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxMacro.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief List of common macros used by QxOrm library
|
||||
*/
|
||||
|
||||
#include <QxCommon/QxConfig.h>
|
||||
|
||||
#ifndef qAssert
|
||||
#if _QX_USE_ASSERT
|
||||
#define qAssert Q_ASSERT
|
||||
#else // _QX_USE_ASSERT
|
||||
#define qAssert(x) /* Nothing */
|
||||
#endif // _QX_USE_ASSERT
|
||||
#endif // qAssert
|
||||
|
||||
#ifndef qAssertMsg
|
||||
#if _QX_USE_ASSERT
|
||||
#define qAssertMsg(test, where, what) Q_ASSERT_X(test, where, what)
|
||||
#else // _QX_USE_ASSERT
|
||||
#define qAssertMsg(test, where, what) /* Nothing */
|
||||
#endif // _QX_USE_ASSERT
|
||||
#endif // qAssertMsg
|
||||
|
||||
#ifndef QX_PRAGMA
|
||||
#ifdef __GNUC__
|
||||
#define QX_PRAGMA(x) _Pragma(#x)
|
||||
#endif // __GNUC__
|
||||
#ifdef _MSC_VER
|
||||
#define QX_PRAGMA(x) __pragma(x)
|
||||
#endif // _MSC_VER
|
||||
#ifndef QX_PRAGMA
|
||||
#define QX_PRAGMA(x) /* Nothing */
|
||||
#endif // QX_PRAGMA
|
||||
#endif // QX_PRAGMA
|
||||
|
||||
#ifndef QX_DLL_EXPORT_HELPER
|
||||
#ifdef Q_OS_WIN
|
||||
#define QX_DLL_EXPORT_HELPER __declspec(dllexport)
|
||||
#elif (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#define QX_DLL_EXPORT_HELPER __attribute__((visibility("default")))
|
||||
#else
|
||||
#define QX_DLL_EXPORT_HELPER /* Nothing */
|
||||
#endif // Q_OS_WIN
|
||||
#endif // QX_DLL_EXPORT_HELPER
|
||||
|
||||
#ifndef QX_DLL_IMPORT_HELPER
|
||||
#ifdef Q_OS_WIN
|
||||
#define QX_DLL_IMPORT_HELPER __declspec(dllimport)
|
||||
#elif (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#define QX_DLL_IMPORT_HELPER __attribute__((visibility("default")))
|
||||
#else
|
||||
#define QX_DLL_IMPORT_HELPER /* Nothing */
|
||||
#endif // Q_OS_WIN
|
||||
#endif // QX_DLL_IMPORT_HELPER
|
||||
|
||||
#ifdef __GNUC__
|
||||
#if _QX_USE_GCC_EXPORT_ALL_SYMBOLS
|
||||
#undef QX_DLL_EXPORT_HELPER
|
||||
#undef QX_DLL_IMPORT_HELPER
|
||||
#define QX_DLL_EXPORT_HELPER /* Nothing */
|
||||
#define QX_DLL_IMPORT_HELPER /* Nothing */
|
||||
#endif // _QX_USE_GCC_EXPORT_ALL_SYMBOLS
|
||||
#endif // __GNUC__
|
||||
|
||||
#ifdef _QX_STATIC_BUILD
|
||||
#undef QX_DLL_EXPORT_HELPER
|
||||
#undef QX_DLL_IMPORT_HELPER
|
||||
#define QX_DLL_EXPORT_HELPER /* Nothing */
|
||||
#define QX_DLL_IMPORT_HELPER /* Nothing */
|
||||
#endif // _QX_STATIC_BUILD
|
||||
|
||||
#ifndef QX_DLL_INTERNAL_HELPER
|
||||
#if (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#define QX_DLL_INTERNAL_HELPER __attribute__((visibility("hidden")))
|
||||
#else
|
||||
#define QX_DLL_INTERNAL_HELPER /* Nothing */
|
||||
#endif // (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#endif // QX_DLL_INTERNAL_HELPER
|
||||
|
||||
#ifndef QX_DLL_EXPORT_TEMPLATE_HELPER
|
||||
#ifdef _MSC_VER
|
||||
#define QX_DLL_EXPORT_TEMPLATE_HELPER QX_DLL_EXPORT_HELPER
|
||||
#else // _MSC_VER
|
||||
#define QX_DLL_EXPORT_TEMPLATE_HELPER /* Nothing */
|
||||
#endif // _MSC_VER
|
||||
#endif // QX_DLL_EXPORT_TEMPLATE_HELPER
|
||||
|
||||
#ifndef QX_DLL_IMPORT_TEMPLATE_HELPER
|
||||
#ifdef _MSC_VER
|
||||
#define QX_DLL_IMPORT_TEMPLATE_HELPER QX_DLL_IMPORT_HELPER
|
||||
#else // _MSC_VER
|
||||
#define QX_DLL_IMPORT_TEMPLATE_HELPER /* Nothing */
|
||||
#endif // _MSC_VER
|
||||
#endif // QX_DLL_IMPORT_TEMPLATE_HELPER
|
||||
|
||||
#ifndef QX_PRAGMA_VISIBILITY_BEGIN
|
||||
#ifndef Q_OS_WIN
|
||||
#if (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#define QX_PRAGMA_VISIBILITY_BEGIN QX_PRAGMA(GCC visibility push(default))
|
||||
#endif // (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#endif // Q_OS_WIN
|
||||
#ifndef QX_PRAGMA_VISIBILITY_BEGIN
|
||||
#define QX_PRAGMA_VISIBILITY_BEGIN /* Nothing */
|
||||
#endif // QX_PRAGMA_VISIBILITY_BEGIN
|
||||
#endif // QX_PRAGMA_VISIBILITY_BEGIN
|
||||
|
||||
#ifndef QX_PRAGMA_VISIBILITY_END
|
||||
#ifndef Q_OS_WIN
|
||||
#if (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#define QX_PRAGMA_VISIBILITY_END QX_PRAGMA(GCC visibility pop)
|
||||
#endif // (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
|
||||
#endif // Q_OS_WIN
|
||||
#ifndef QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_PRAGMA_VISIBILITY_END /* Nothing */
|
||||
#endif // QX_PRAGMA_VISIBILITY_END
|
||||
#endif // QX_PRAGMA_VISIBILITY_END
|
||||
|
||||
#define QX_DLL_EXPORT_TEMPLATE_HPP(CL, T) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(CL, T, P1) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<P1>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_HPP(CL, T, U, P1) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<U<P1>>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_P1_P2_HPP(CL, T, P1, P2) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<P1, P2>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_P2_HPP(CL, T, U, P1, P2) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<U<P1, P2>>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
|
||||
#define QX_DLL_EXPORT_TEMPLATE_CPP(CL, T) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_P1_CPP(CL, T, P1) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<P1>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_CPP(CL, T, U, P1) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<U<P1>>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_P1_P2_CPP(CL, T, P1, P2) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<P1, P2>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_P2_CPP(CL, T, U, P1, P2) \
|
||||
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<U<P1, P2>>; \
|
||||
QX_PRAGMA_VISIBILITY_END
|
||||
|
||||
#define QX_TEMPLATE_T(T) T<>
|
||||
#define QX_TEMPLATE_T_P1(T, P1) T<P1>
|
||||
#define QX_TEMPLATE_T_P1_P2(T, P1, P2) T<P1, P2>
|
||||
#define QX_TEMPLATE_T_P1_P2_P3(T, P1, P2, P3) T<P1, P2, P3>
|
||||
#define QX_TEMPLATE_T_U_P1(T, U, P1) T<U<P1>>
|
||||
#define QX_TEMPLATE_T_U_P1_P2(T, U, P1, P2) T<U<P1, P2>>
|
||||
#define QX_TEMPLATE_T_U_P1_P2_P3(T, U, P1, P2, P3) T<U<P1, P2, P3>>
|
||||
|
||||
#ifndef QX_DLL_EXPORT
|
||||
#ifdef _QX_BUILDING_QX_ORM
|
||||
#define QX_DLL_EXPORT QX_DLL_EXPORT_HELPER
|
||||
#else // _QX_BUILDING_QX_ORM
|
||||
#define QX_DLL_EXPORT QX_DLL_IMPORT_HELPER
|
||||
#endif // _QX_BUILDING_QX_ORM
|
||||
#endif // QX_DLL_EXPORT
|
||||
|
||||
#ifndef QX_DLL_EXPORT_QX_SINGLETON_HPP
|
||||
#ifdef _QX_BUILDING_QX_ORM
|
||||
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x) /* Nothing */
|
||||
#else // _QX_BUILDING_QX_ORM
|
||||
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x) QX_DLL_EXPORT_TEMPLATE_HPP(class, qx::QxSingleton<x>)
|
||||
#endif // _QX_BUILDING_QX_ORM
|
||||
#endif // QX_DLL_EXPORT_QX_SINGLETON_HPP
|
||||
|
||||
#ifndef QX_DLL_EXPORT_QX_SINGLETON_CPP
|
||||
#ifdef _QX_BUILDING_QX_ORM
|
||||
#define QX_DLL_EXPORT_QX_SINGLETON_CPP(x) QX_DLL_EXPORT_TEMPLATE_CPP(class, qx::QxSingleton<x>)
|
||||
#else // _QX_BUILDING_QX_ORM
|
||||
#define QX_DLL_EXPORT_QX_SINGLETON_CPP(x) /* Nothing */
|
||||
#endif // _QX_BUILDING_QX_ORM
|
||||
#endif // QX_DLL_EXPORT_QX_SINGLETON_CPP
|
||||
|
||||
#ifndef QX_DLL_EXPORT_INLINE_FCT
|
||||
#ifdef _MSC_VER
|
||||
#define QX_DLL_EXPORT_INLINE_FCT QX_DLL_EXPORT
|
||||
#else // _MSC_VER
|
||||
#define QX_DLL_EXPORT_INLINE_FCT /* Nothing */
|
||||
#endif // _MSC_VER
|
||||
#endif // QX_DLL_EXPORT_INLINE_FCT
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE inline
|
||||
#elif (defined(_MSC_VER) && (_MSC_VER >= 1920)) // MSVC 2019
|
||||
#define QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE inline
|
||||
#else
|
||||
#define QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE /* Nothing */
|
||||
#endif // __GNUC__
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define QX_STRNCPY strncpy_s
|
||||
#define QX_VSPRINTF vsprintf_s
|
||||
#else // _MSC_VER
|
||||
#define QX_STRNCPY strncpy
|
||||
#define QX_VSPRINTF vsprintf
|
||||
#endif // _MSC_VER
|
||||
|
||||
#ifdef _QX_MODE_RELEASE
|
||||
#ifndef NDEBUG
|
||||
#define NDEBUG
|
||||
#endif // NDEBUG
|
||||
#endif // _QX_MODE_RELEASE
|
||||
|
||||
// From file <boost/serialization/force_include.hpp> (written by Robert Ramey)
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
#if defined(__GNUC__) && (__GNUC__ >= 3)
|
||||
#define QX_USED __attribute__((__used__))
|
||||
#elif defined(__IBMCPP__) && (__IBMCPP__ >= 1110)
|
||||
#define QX_USED __attribute__((__used__))
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
#define QX_USED __attribute__((__used__))
|
||||
#endif
|
||||
#endif // ! defined(_WIN32) && ! defined(_WIN64)
|
||||
|
||||
#ifndef QX_USED
|
||||
#define QX_USED /* Nothing */
|
||||
#endif // QX_USED
|
||||
|
||||
#ifdef QT_NO_OPENSSL
|
||||
#ifndef QT_NO_SSL
|
||||
#define QT_NO_SSL /* Nothing */
|
||||
#endif // QT_NO_SSL
|
||||
#endif // QT_NO_OPENSSL
|
||||
|
||||
#ifndef Q_DECL_OVERRIDE
|
||||
#define Q_DECL_OVERRIDE /* Nothing */
|
||||
#endif // Q_DECL_OVERRIDE
|
||||
|
||||
#ifndef Q_DECL_FINAL
|
||||
#define Q_DECL_FINAL /* Nothing */
|
||||
#endif // Q_DECL_FINAL
|
||||
|
||||
#ifndef Q_DECL_HIDDEN
|
||||
#define Q_DECL_HIDDEN /* Nothing */
|
||||
#endif // Q_DECL_HIDDEN
|
||||
|
||||
#ifndef Q_DECL_NOEXCEPT
|
||||
#define Q_DECL_NOEXCEPT /* Nothing */
|
||||
#endif // Q_DECL_NOEXCEPT
|
||||
|
||||
#ifndef Q_NULLPTR
|
||||
#define Q_NULLPTR NULL
|
||||
#endif // Q_NULLPTR
|
||||
|
||||
// From 'QtCore' directory, 'qtversionchecks.h' file
|
||||
#ifndef QT_VERSION_CHECK
|
||||
#define QT_VERSION_CHECK(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
|
||||
#endif // QT_VERSION_CHECK
|
||||
|
||||
#endif // _QX_MACRO_H_
|
||||
367
include/QxCommon/QxMainPage.h
Normal file
367
include/QxCommon/QxMainPage.h
Normal file
@@ -0,0 +1,367 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
/* -- Main page for Doxygen documentation -- */
|
||||
|
||||
/*!
|
||||
* \mainpage QxOrm - C++ Object Relational Mapping library
|
||||
*
|
||||
* QxOrm is a C++ library designed to provide Object Relational Mapping (ORM) feature to C++/Qt developers (like Hibernate in Java, or NHibernate in .Net).<br>
|
||||
* QxOrm engine is based on a simple and non intrusive mapping function per class to provide :
|
||||
*
|
||||
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_30" target="_blank"><b>Persistence</b></a> (based on QtSql Qt module) ;
|
||||
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_60" target="_blank"><b>Serialization</b></a> (JSON, XML and binary, based on Qt and boost serialization engines) ;
|
||||
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Reflection</b></a> or <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Introspection</b></a> (invoke dynamically class methods and access to properties) ;
|
||||
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_96" target="_blank"><b>HTTP web server</b></a> : standalone multi-threaded HTTP 1.1 web server (support SSL/TLS, persistent connections, cookies, sessions, chunked responses, URL dispatcher/routing) ;
|
||||
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_97" target="_blank"><b>JSON API</b></a> : interoperability with other technology than C++/Qt (REST web services, QML applications, scripting language).
|
||||
*
|
||||
* QxOrm is developed by XDL Team, a software development engineer since 2003.<br>
|
||||
* QxOrm library has been accepted into the <a href="http://forum.qt.io/category/24/qt-ambassador-program" target="_blank">Qt Ambassador Program</a>.<br>
|
||||
* QxOrm library is available on <a href="https://github.com/QxOrm/QxOrm" target="_blank">GitHub</a>.
|
||||
*
|
||||
* For more information about QxOrm library (quick sample, tutorial and forum), please visit : <a href="https://www.qxorm.com/" target="_blank">https://www.qxorm.com/</a>.<br>
|
||||
* <a href="https://www.qxorm.com/qxorm_en/manual.html" target="_blank">A manual (user guide) to learn how to work with QxOrm library is available on QxOrm website</a>.
|
||||
* <br><br>
|
||||
*
|
||||
* \section quick_sample Quick sample using QxOrm library
|
||||
*
|
||||
* 1- <i>drug.h</i> file : drug class definition with 3 properties : <i>id</i>, <i>name</i> and <i>description</i>
|
||||
* \code
|
||||
#ifndef _CLASS_DRUG_H_
|
||||
#define _CLASS_DRUG_H_
|
||||
|
||||
class drug
|
||||
{
|
||||
public:
|
||||
long id;
|
||||
QString name;
|
||||
QString description;
|
||||
|
||||
drug() : id(0) { ; }
|
||||
virtual ~drug() { ; }
|
||||
};
|
||||
|
||||
QX_REGISTER_HPP_MY_TEST_EXE(drug, qx::trait::no_base_class_defined, 1)
|
||||
|
||||
// This macro is necessary to register 'drug' class in QxOrm context
|
||||
// param 1 : the current class to register => 'drug'
|
||||
// param 2 : the base class, if no base class, use the qx trait => 'qx::trait::no_base_class_defined'
|
||||
// param 3 : the class version used by serialization to provide 'ascendant compatibility'
|
||||
|
||||
#endif // _CLASS_DRUG_H_
|
||||
* \endcode
|
||||
*
|
||||
* <br>
|
||||
* 2- <i>drug.cpp</i> file : setting function implementation - <i>void qx::register_class()</i>
|
||||
* \code
|
||||
#include "precompiled.h" // Precompiled-header with '#include <QxOrm.h>' and '#include "export.h"'
|
||||
#include "drug.h" // Class definition 'drug'
|
||||
#include <QxOrm_Impl.h> // Automatic memory leak detection and boost serialization export macro
|
||||
|
||||
QX_REGISTER_CPP_MY_TEST_EXE(drug) // This macro is necessary to register 'drug' class in QxOrm context
|
||||
|
||||
namespace qx {
|
||||
template <> void register_class(QxClass<drug> & t)
|
||||
{
|
||||
t.id(& drug::id, "id"); // Register 'drug::id' <=> primary key in your database
|
||||
t.data(& drug::name, "name", 1); // Register 'drug::name' property with key 'name' and version '1'
|
||||
t.data(& drug::description, "desc"); // Register 'drug::description' property with key 'desc'
|
||||
}}
|
||||
* \endcode
|
||||
*
|
||||
* <br>
|
||||
* 3- <i>main.cpp</i> file : basic functionalities of QxOrm library with drug class
|
||||
* \code
|
||||
#include "precompiled.h"
|
||||
#include "drug.h"
|
||||
#include <QxOrm_Impl.h>
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
QApplication app(argc, argv); // Qt application
|
||||
|
||||
// Create 3 new drugs
|
||||
// It is possible to use 'boost' and 'Qt' smart pointer : 'boost::shared_ptr', 'QSharedPointer', etc...
|
||||
typedef std::shared_ptr<drug> drug_ptr;
|
||||
drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1";
|
||||
drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2";
|
||||
drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3";
|
||||
|
||||
// Insert drugs into container
|
||||
// It is possible to use a lot of containers from 'std', 'boost', 'Qt' and 'qx::QxCollection<Key, Value>'
|
||||
typedef std::vector<drug_ptr> type_lst_drug;
|
||||
type_lst_drug lst_drug;
|
||||
lst_drug.push_back(d1);
|
||||
lst_drug.push_back(d2);
|
||||
lst_drug.push_back(d3);
|
||||
|
||||
// Init parameters to communicate with a database
|
||||
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
|
||||
qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db");
|
||||
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
|
||||
qx::QxSqlDatabase::getSingleton()->setUserName("root");
|
||||
qx::QxSqlDatabase::getSingleton()->setPassword("");
|
||||
|
||||
// Create table 'drug' into database to store drugs
|
||||
QSqlError daoError = qx::dao::create_table<drug>();
|
||||
|
||||
// Insert drugs from container to database
|
||||
// 'id' property of 'd1', 'd2' and 'd3' are auto-updated
|
||||
daoError = qx::dao::insert(lst_drug);
|
||||
|
||||
// Modify and update the second drug into database
|
||||
d2->name = "name2 modified";
|
||||
d2->description = "desc2 modified";
|
||||
daoError = qx::dao::update(d2);
|
||||
|
||||
// Delete the first drug from database
|
||||
daoError = qx::dao::delete_by_id(d1);
|
||||
|
||||
// Count drugs into database
|
||||
long lDrugCount = qx::dao::count<drug>();
|
||||
|
||||
// Fetch drug with id '3' into a new variable
|
||||
drug_ptr d_tmp; d_tmp.reset(new drug());
|
||||
d_tmp->id = 3;
|
||||
daoError = qx::dao::fetch_by_id(d_tmp);
|
||||
|
||||
// Export drugs from container to a file under XML format (serialization)
|
||||
qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml");
|
||||
|
||||
// Import drugs from XML file into a new container
|
||||
type_lst_drug lst_drug_tmp;
|
||||
qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml");
|
||||
|
||||
// Clone a drug
|
||||
drug_ptr d_clone = qx::clone(* d1);
|
||||
|
||||
// Create a new drug by class name (factory)
|
||||
qx::any d_any = qx::create("drug");
|
||||
|
||||
// Insert drugs container into 'qx::cache'
|
||||
qx::cache::set("drugs", lst_drug);
|
||||
|
||||
// Remove all elements from 'qx::cache'
|
||||
qx::cache::clear();
|
||||
|
||||
// Create a dummy memory leak
|
||||
drug * pDummy = new drug();
|
||||
|
||||
return 0;
|
||||
}
|
||||
* \endcode
|
||||
*
|
||||
* <br>
|
||||
* 4- execute program and trace output debug
|
||||
* \code
|
||||
[QxOrm] qx::QxSqlDatabase : create new database connection in thread '3616' with key '{d315250c-b5c9-46e0-9402-f800368a6673}'
|
||||
[QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)
|
||||
[QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc)
|
||||
[QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis
|
||||
[QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id
|
||||
[QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug
|
||||
[QxOrm] sql query (0 ms) : SELECT drug.id AS drug_id_0, drug.name AS drug_name_0, drug.desc AS drug_desc_0 FROM drug WHERE drug_id_0 = :id
|
||||
[QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74)
|
||||
[QxOrm] **** 1 memory leaks found ****
|
||||
* \endcode
|
||||
*
|
||||
* <br>
|
||||
* 5- <i>export_drugs.xml</i> file created by the program
|
||||
* \code
|
||||
<std.vector-boost.shared_ptr-drug-- class_id="0" tracking_level="0" version="0">
|
||||
<count>3</count>
|
||||
<item_version>1</item_version>
|
||||
<item class_id="1" tracking_level="0" version="1">
|
||||
<px class_id="2" tracking_level="1" version="1" object_id="_0">
|
||||
<id>1</id>
|
||||
<name class_id="3" tracking_level="0" version="0">name1</name>
|
||||
<desc>desc1</desc>
|
||||
</px>
|
||||
</item>
|
||||
<item>
|
||||
<px class_id_reference="2" object_id="_1">
|
||||
<id>2</id>
|
||||
<name>name2 modified</name>
|
||||
<desc>desc2 modified</desc>
|
||||
</px>
|
||||
</item>
|
||||
<item>
|
||||
<px class_id_reference="2" object_id="_2">
|
||||
<id>3</id>
|
||||
<name>name3</name>
|
||||
<desc>desc3</desc>
|
||||
</px>
|
||||
</item>
|
||||
</std.vector-boost.shared_ptr-drug-->
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
/*!
|
||||
* \brief Root namespace for all QxOrm library features
|
||||
*/
|
||||
namespace qx
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Provide basic thread-safe cache feature to backup and restore any kind of objects (for example, object fetched from database)
|
||||
*/
|
||||
namespace cache
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCache
|
||||
* \brief Internal helper tools for qx::cache namespace
|
||||
*/
|
||||
namespace detail
|
||||
{
|
||||
} // namespace detail
|
||||
|
||||
} // namespace cache
|
||||
|
||||
/*!
|
||||
* \ingroup QxDao
|
||||
* \brief Database communication used by persistence engine (ORM - Object Relational Mapping)
|
||||
*/
|
||||
namespace dao
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxDao
|
||||
* \brief Internal helper tools for qx::dao namespace
|
||||
*/
|
||||
namespace detail
|
||||
{
|
||||
} // namespace detail
|
||||
|
||||
} // namespace dao
|
||||
|
||||
/*!
|
||||
* \ingroup QxFunction
|
||||
* \brief Register function into QxOrm context used by introspection engine
|
||||
*/
|
||||
namespace function
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxFunction
|
||||
* \brief Internal helper tools for qx::function namespace
|
||||
*/
|
||||
namespace detail
|
||||
{
|
||||
} // namespace detail
|
||||
|
||||
} // namespace function
|
||||
|
||||
/*!
|
||||
* \ingroup QxMemLeak
|
||||
* \brief QxOrm library memory leak detection (by Wu Yongwei)
|
||||
*/
|
||||
namespace memory
|
||||
{
|
||||
} // namespace memory
|
||||
|
||||
/*!
|
||||
* \ingroup QxSerialize
|
||||
* \brief QxOrm library serialization engine based on boost::serialization library
|
||||
*/
|
||||
namespace serialization
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxSerialize
|
||||
* \brief Internal helper tools for qx::serialization namespace
|
||||
*/
|
||||
namespace detail
|
||||
{
|
||||
} // namespace detail
|
||||
|
||||
/*!
|
||||
* \ingroup QxSerialize
|
||||
* \brief QxOrm library serialization engine for wide archive
|
||||
*/
|
||||
namespace wide
|
||||
{
|
||||
} // namespace wide
|
||||
|
||||
} // namespace serialization
|
||||
|
||||
/*!
|
||||
* \ingroup QxService
|
||||
* \brief QxOrm library services engine to provide easy and powerful way to create C++ application server (to transfer data over network)
|
||||
*/
|
||||
namespace service
|
||||
{
|
||||
} // namespace service
|
||||
|
||||
/*!
|
||||
* \ingroup QxTraits
|
||||
* \brief QxOrm library traits (template metaprogramming) not available in boost::type_traits library
|
||||
*/
|
||||
namespace trait
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxTraits
|
||||
* \brief Internal helper tools for qx::trait namespace
|
||||
*/
|
||||
namespace detail
|
||||
{
|
||||
} // namespace detail
|
||||
|
||||
} // namespace trait
|
||||
|
||||
/*!
|
||||
* \ingroup QxCollection
|
||||
* \brief Foreach-style (based on BOOST_FOREACH macro) to iterate over all stl, boost and Qt containers + qx::QxCollection<Key, Value> QxOrm library container
|
||||
*/
|
||||
namespace foreach
|
||||
{
|
||||
} // namespace foreach
|
||||
|
||||
/*!
|
||||
* \ingroup QxCommon
|
||||
* \brief Provide global functions to convert any kind of objects to/from QString and QVariant format
|
||||
*/
|
||||
namespace cvt
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCommon
|
||||
* \brief Internal helper tools for qx::cvt namespace
|
||||
*/
|
||||
namespace detail
|
||||
{
|
||||
} // namespace detail
|
||||
|
||||
} // namespace cvt
|
||||
|
||||
} // namespace qx
|
||||
105
include/QxCommon/QxPropertyBag.h
Normal file
105
include/QxCommon/QxPropertyBag.h
Normal file
@@ -0,0 +1,105 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** https://www.qxorm.com/
|
||||
** Copyright (C) 2013 XDL Team (ic-east.com)
|
||||
**
|
||||
** This file is part of the QxOrm library
|
||||
**
|
||||
** This software is provided 'as-is', without any express or implied
|
||||
** warranty. In no event will the authors be held liable for any
|
||||
** damages arising from the use of this software
|
||||
**
|
||||
** Commercial Usage
|
||||
** Licensees holding valid commercial QxOrm licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and XDL Team
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3.0 as published by the Free Software
|
||||
** Foundation and appearing in the file 'license.gpl3.txt' included in the
|
||||
** packaging of this file. Please review the following information to
|
||||
** ensure the GNU General Public License version 3.0 requirements will be
|
||||
** met : http://www.gnu.org/copyleft/gpl.html
|
||||
**
|
||||
** If you are unsure which license is appropriate for your use, or
|
||||
** if you have questions regarding the use of this file, please contact :
|
||||
** ic-east.com
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef _QX_PROPERTY_BAG_H_
|
||||
#define _QX_PROPERTY_BAG_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxPropertyBag.h
|
||||
* \author XDL Team
|
||||
* \ingroup QxCommon
|
||||
* \brief Used by introspection engine (IxClass, IxDataMember, IxFunction, etc.) to add meta-data (property bag)
|
||||
*/
|
||||
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qvariant.h>
|
||||
|
||||
namespace qx
|
||||
{
|
||||
|
||||
/*!
|
||||
* \ingroup QxCommon
|
||||
* \brief qx::QxPropertyBag : used by introspection engine (IxClass, IxDataMember, IxFunction, etc.) to add meta-data (property bag)
|
||||
*/
|
||||
class QxPropertyBag
|
||||
{
|
||||
|
||||
protected:
|
||||
typedef QHash<QString, QVariant> type_hash_prop_bag;
|
||||
typedef std::shared_ptr<type_hash_prop_bag> type_hash_prop_bag_ptr;
|
||||
|
||||
type_hash_prop_bag_ptr m_lstPropertyBag; //!< List of all properties in the bag (meta-data)
|
||||
|
||||
public:
|
||||
QxPropertyBag() { ; }
|
||||
virtual ~QxPropertyBag() { ; }
|
||||
|
||||
void setPropertyBag(const QString &key, const QVariant &value)
|
||||
{
|
||||
initPropertyBag();
|
||||
m_lstPropertyBag->insert(key, value);
|
||||
}
|
||||
QVariant getPropertyBag(const QString &key) const { return ((m_lstPropertyBag && m_lstPropertyBag->contains(key)) ? m_lstPropertyBag->value(key) : QVariant()); }
|
||||
void removePropertyBag(const QString &key)
|
||||
{
|
||||
if (m_lstPropertyBag)
|
||||
{
|
||||
m_lstPropertyBag->remove(key);
|
||||
}
|
||||
}
|
||||
void clearPropertyBag()
|
||||
{
|
||||
if (m_lstPropertyBag)
|
||||
{
|
||||
m_lstPropertyBag->clear();
|
||||
}
|
||||
}
|
||||
long countPropertyBag() const { return (m_lstPropertyBag ? m_lstPropertyBag->count() : 0); }
|
||||
QList<QString> getAllPropertyBagKeys() const { return (m_lstPropertyBag ? m_lstPropertyBag->keys() : QList<QString>()); }
|
||||
|
||||
private:
|
||||
inline void initPropertyBag()
|
||||
{
|
||||
if (!m_lstPropertyBag)
|
||||
{
|
||||
m_lstPropertyBag = std::make_shared<type_hash_prop_bag>();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace qx
|
||||
|
||||
#endif // _QX_PROPERTY_BAG_H_
|
||||
250
include/QxCommon/QxSimpleCrypt.h
Normal file
250
include/QxCommon/QxSimpleCrypt.h
Normal file
@@ -0,0 +1,250 @@
|
||||
/*
|
||||
Copyright (c) 2011, Andre Somers
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
* Neither the name of the Rathenau Instituut, Andre Somers nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL ANDRE SOMERS BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef _QX_SIMPLECRYPT_H_
|
||||
#define _QX_SIMPLECRYPT_H_
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
/*!
|
||||
* \file QxSimpleCrypt.h
|
||||
* \author Andre Somers
|
||||
* \ingroup QxCommon
|
||||
* \brief qx::QxSimpleCrypt : simple encryption and decryption of strings and byte arrays
|
||||
*/
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qvector.h>
|
||||
#include <QtCore/qbytearray.h>
|
||||
|
||||
namespace qx {
|
||||
|
||||
/**
|
||||
@ingroup QxCommon
|
||||
@short Simple encryption and decryption of strings and byte arrays
|
||||
|
||||
This class provides a simple implementation of encryption and decryption
|
||||
of strings and byte arrays : http://qt-project.org/wiki/Simple_encryption
|
||||
|
||||
@warning The encryption provided by this class is NOT strong encryption. It may
|
||||
help to shield things from curious eyes, but it will NOT stand up to someone
|
||||
determined to break the encryption. Don't say you were not warned.
|
||||
|
||||
The class uses a 64 bit key. Simply create an instance of the class, set the key,
|
||||
and use the encryptToString() method to calculate an encrypted version of the input string.
|
||||
To decrypt that string again, use an instance of QxSimpleCrypt initialized with
|
||||
the same key, and call the decryptToString() method with the encrypted string. If the key
|
||||
matches, the decrypted version of the string will be returned again.
|
||||
|
||||
If you do not provide a key, or if something else is wrong, the encryption and
|
||||
decryption function will return an empty string or will return a string containing nonsense.
|
||||
lastError() will return a value indicating if the method was succesful, and if not, why not.
|
||||
|
||||
QxSimpleCrypt is prepared for the case that the encryption and decryption
|
||||
algorithm is changed in a later version, by prepending a version identifier to the cypertext.
|
||||
*/
|
||||
class QX_DLL_EXPORT QxSimpleCrypt
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
CompressionMode describes if compression will be applied to the data to be
|
||||
encrypted.
|
||||
*/
|
||||
enum CompressionMode {
|
||||
CompressionAuto, /*!< Only apply compression if that results in a shorter plaintext. */
|
||||
CompressionAlways, /*!< Always apply compression. Note that for short inputs, a compression may result in longer data */
|
||||
CompressionNever /*!< Never apply compression. */
|
||||
};
|
||||
|
||||
/**
|
||||
IntegrityProtectionMode describes measures taken to make it possible to detect problems with the data
|
||||
or wrong decryption keys.
|
||||
|
||||
Measures involve adding a checksum or a cryptograhpic hash to the data to be encrypted. This
|
||||
increases the length of the resulting cypertext, but makes it possible to check if the plaintext
|
||||
appears to be valid after decryption.
|
||||
*/
|
||||
enum IntegrityProtectionMode {
|
||||
ProtectionNone, /*!< The integerity of the encrypted data is not protected. It is not really possible to detect a wrong key, for instance. */
|
||||
ProtectionChecksum,/*!< A simple checksum is used to verify that the data is in order. If not, an empty string is returned. */
|
||||
ProtectionHash /*!< A cryptographic hash is used to verify the integrity of the data. This method produces a much stronger, but longer check */
|
||||
};
|
||||
|
||||
/**
|
||||
Error describes the type of error that occured.
|
||||
*/
|
||||
enum Error {
|
||||
ErrorNoError, /*!< No error occurred. */
|
||||
ErrorNoKeySet, /*!< No key was set. You can not encrypt or decrypt without a valid key. */
|
||||
ErrorUnknownVersion, /*!< The version of this data is unknown, or the data is otherwise not valid. */
|
||||
ErrorIntegrityFailed, /*!< The integrity check of the data failed. Perhaps the wrong key was used. */
|
||||
};
|
||||
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
Constructs a QxSimpleCrypt instance without a valid key set on it.
|
||||
*/
|
||||
QxSimpleCrypt();
|
||||
/**
|
||||
Constructor.
|
||||
|
||||
Constructs a QxSimpleCrypt instance and initializes it with the given @arg key.
|
||||
*/
|
||||
explicit QxSimpleCrypt(quint64 key);
|
||||
|
||||
/**
|
||||
(Re-) initializes the key with the given @arg key.
|
||||
*/
|
||||
void setKey(quint64 key);
|
||||
/**
|
||||
Returns true if QxSimpleCrypt has been initialized with a key.
|
||||
*/
|
||||
bool hasKey() const {return !m_keyParts.isEmpty();}
|
||||
|
||||
/**
|
||||
Sets the compression mode to use when encrypting data. The default mode is Auto.
|
||||
|
||||
Note that decryption is not influenced by this mode, as the decryption recognizes
|
||||
what mode was used when encrypting.
|
||||
*/
|
||||
void setCompressionMode(CompressionMode mode) {m_compressionMode = mode;}
|
||||
/**
|
||||
Returns the CompressionMode that is currently in use.
|
||||
*/
|
||||
CompressionMode compressionMode() const {return m_compressionMode;}
|
||||
|
||||
/**
|
||||
Sets the integrity mode to use when encrypting data. The default mode is Checksum.
|
||||
|
||||
Note that decryption is not influenced by this mode, as the decryption recognizes
|
||||
what mode was used when encrypting.
|
||||
*/
|
||||
void setIntegrityProtectionMode(IntegrityProtectionMode mode) {m_protectionMode = mode;}
|
||||
/**
|
||||
Returns the IntegrityProtectionMode that is currently in use.
|
||||
*/
|
||||
IntegrityProtectionMode integrityProtectionMode() const {return m_protectionMode;}
|
||||
|
||||
/**
|
||||
Returns the last error that occurred.
|
||||
*/
|
||||
Error lastError() const {return m_lastError;}
|
||||
|
||||
/**
|
||||
Encrypts the @arg plaintext string with the key the class was initialized with, and returns
|
||||
a cyphertext the result. The result is a base64 encoded version of the binary array that is the
|
||||
actual result of the string, so it can be stored easily in a text format.
|
||||
*/
|
||||
QString encryptToString(const QString& plaintext) ;
|
||||
/**
|
||||
Encrypts the @arg plaintext QByteArray with the key the class was initialized with, and returns
|
||||
a cyphertext the result. The result is a base64 encoded version of the binary array that is the
|
||||
actual result of the encryption, so it can be stored easily in a text format.
|
||||
*/
|
||||
QString encryptToString(QByteArray plaintext) ;
|
||||
/**
|
||||
Encrypts the @arg plaintext string with the key the class was initialized with, and returns
|
||||
a binary cyphertext in a QByteArray the result.
|
||||
|
||||
This method returns a byte array, that is useable for storing a binary format. If you need
|
||||
a string you can store in a text file, use encryptToString() instead.
|
||||
*/
|
||||
QByteArray encryptToByteArray(const QString& plaintext) ;
|
||||
/**
|
||||
Encrypts the @arg plaintext QByteArray with the key the class was initialized with, and returns
|
||||
a binary cyphertext in a QByteArray the result.
|
||||
|
||||
This method returns a byte array, that is useable for storing a binary format. If you need
|
||||
a string you can store in a text file, use encryptToString() instead.
|
||||
*/
|
||||
QByteArray encryptToByteArray(QByteArray plaintext) ;
|
||||
|
||||
/**
|
||||
Decrypts a cyphertext string encrypted with this class with the set key back to the
|
||||
plain text version.
|
||||
|
||||
If an error occured, such as non-matching keys between encryption and decryption,
|
||||
an empty string or a string containing nonsense may be returned.
|
||||
*/
|
||||
QString decryptToString(const QString& cyphertext) ;
|
||||
/**
|
||||
Decrypts a cyphertext string encrypted with this class with the set key back to the
|
||||
plain text version.
|
||||
|
||||
If an error occured, such as non-matching keys between encryption and decryption,
|
||||
an empty string or a string containing nonsense may be returned.
|
||||
*/
|
||||
QByteArray decryptToByteArray(const QString& cyphertext) ;
|
||||
/**
|
||||
Decrypts a cyphertext binary encrypted with this class with the set key back to the
|
||||
plain text version.
|
||||
|
||||
If an error occured, such as non-matching keys between encryption and decryption,
|
||||
an empty string or a string containing nonsense may be returned.
|
||||
*/
|
||||
QString decryptToString(QByteArray cypher) ;
|
||||
/**
|
||||
Decrypts a cyphertext binary encrypted with this class with the set key back to the
|
||||
plain text version.
|
||||
|
||||
If an error occured, such as non-matching keys between encryption and decryption,
|
||||
an empty string or a string containing nonsense may be returned.
|
||||
*/
|
||||
QByteArray decryptToByteArray(QByteArray cypher) ;
|
||||
|
||||
// enum to describe options that have been used for the encryption. Currently only one, but
|
||||
// that only leaves room for future extensions like adding a cryptographic hash...
|
||||
enum CryptoFlag{CryptoFlagNone = 0,
|
||||
CryptoFlagCompression = 0x01,
|
||||
CryptoFlagChecksum = 0x02,
|
||||
CryptoFlagHash = 0x04
|
||||
};
|
||||
Q_DECLARE_FLAGS(CryptoFlags, CryptoFlag);
|
||||
|
||||
private:
|
||||
|
||||
void splitKey();
|
||||
|
||||
quint64 m_key;
|
||||
QVector<char> m_keyParts;
|
||||
CompressionMode m_compressionMode;
|
||||
IntegrityProtectionMode m_protectionMode;
|
||||
Error m_lastError;
|
||||
|
||||
};
|
||||
|
||||
} // namespace qx
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(qx::QxSimpleCrypt::CryptoFlags)
|
||||
|
||||
#endif // _QX_SIMPLECRYPT_H_
|
||||
Reference in New Issue
Block a user