QxOrm
1.5.0
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** https://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifndef _IX_FUNCTION_H_ 00033 #define _IX_FUNCTION_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <QxCommon/QxAny.h> 00047 #include <QxCommon/QxBool.h> 00048 #include <QxCommon/QxPropertyBag.h> 00049 00050 #include <QxCollection/QxCollection.h> 00051 00052 #include <QxFunction/QxFunctionError.h> 00053 #include <QxFunction/QxFunctionMacro.h> 00054 00055 #include <QxTraits/remove_attr.h> 00056 00057 namespace qx { 00058 00063 class IxFunction : public qx::QxPropertyBag 00064 { 00065 00066 protected: 00067 00068 QString m_sKey; 00069 QString m_sSeparator; 00070 QString m_sDescription; 00071 00072 public: 00073 00074 typedef std::vector<qx::any> type_any_params; 00075 00076 IxFunction() : qx::QxPropertyBag(), m_sSeparator("|") { ; } 00077 virtual ~IxFunction() { ; } 00078 00079 QString getKey() const { return m_sKey; } 00080 QString getSeparator() const { return m_sSeparator; } 00081 QString getDescription() const { return m_sDescription; } 00082 00083 void setKey(const QString & s) { m_sKey = s; } 00084 void setSeparator(const QString & s) { m_sSeparator = s; } 00085 void setDescription(const QString & s) { m_sDescription = s; } 00086 00087 virtual int getParamCount() const = 0; 00088 00089 virtual qx_bool invoke(const QString & params = QString(), qx::any * ret = NULL) const = 0; 00090 virtual qx_bool invoke(const type_any_params & params, qx::any * ret = NULL) const = 0; 00091 virtual qx_bool invoke(void * pOwner, const QString & params = QString(), qx::any * ret = NULL) const = 0; 00092 virtual qx_bool invoke(void * pOwner, const type_any_params & params, qx::any * ret = NULL) const = 0; 00093 00094 virtual qx_bool isValidFct() const = 0; 00095 virtual qx_bool isValidParams(const QString & params) const = 0; 00096 virtual qx_bool isValidParams(const type_any_params & params) const = 0; 00097 00098 template <class T> 00099 qx_bool isValidOwner(void * pOwner, T * dummy) const 00100 { 00101 Q_UNUSED(dummy); 00102 typedef std::is_same<T, void> qx_verify_owner_tmp; 00103 static_assert(! qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value"); 00104 if (! pOwner) { return qx_bool(false, 0, QX_FUNCTION_ERR_NULL_OWNER); } 00105 #ifndef _QX_NO_RTTI 00106 if (! dynamic_cast<T *>(static_cast<T *>(pOwner))) { return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_OWNER); } 00107 #endif // _QX_NO_RTTI 00108 return true; 00109 } 00110 00111 template <class T> 00112 qx_bool isValid(const T & params) const 00113 { 00114 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00115 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00116 return true; 00117 } 00118 00119 template <class T, class U> 00120 qx_bool isValid(void * pOwner, const T & params, U * dummy) const 00121 { 00122 Q_UNUSED(dummy); 00123 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00124 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00125 bValid = isValidOwner<U>(pOwner, NULL); if (! bValid) { return bValid; }; 00126 return true; 00127 } 00128 00129 }; 00130 00131 typedef std::shared_ptr<IxFunction> IxFunction_ptr; 00132 typedef QxCollection<QString, IxFunction_ptr> IxFunctionX; 00133 typedef std::shared_ptr<IxFunctionX> IxFunctionX_ptr; 00134 00135 } // namespace qx 00136 00137 #endif // _IX_FUNCTION_H_