![]() |
QxOrm
1.2.8
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://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 <boost/any.hpp> 00047 #include <boost/function.hpp> 00048 #include <boost/lexical_cast.hpp> 00049 #include <boost/static_assert.hpp> 00050 #include <boost/type_traits/is_same.hpp> 00051 00052 #include <QxCommon/QxBool.h> 00053 #include <QxCommon/QxPropertyBag.h> 00054 00055 #include <QxCollection/QxCollection.h> 00056 00057 #include <QxFunction/QxFunctionError.h> 00058 #include <QxFunction/QxFunctionMacro.h> 00059 00060 #include <QxTraits/remove_attr.h> 00061 00062 namespace qx { 00063 00068 class IxFunction : public qx::QxPropertyBag 00069 { 00070 00071 protected: 00072 00073 QString m_sKey; 00074 QString m_sSeparator; 00075 00076 public: 00077 00078 typedef std::vector<boost::any> type_any_params; 00079 00080 IxFunction() : qx::QxPropertyBag(), m_sSeparator("|") { ; } 00081 virtual ~IxFunction() { ; } 00082 00083 QString getKey() const { return m_sKey; } 00084 QString getSeparator() const { return m_sSeparator; } 00085 00086 void setKey(const QString & s) { m_sKey = s; } 00087 void setSeparator(const QString & s) { m_sSeparator = s; } 00088 00089 virtual qx_bool invoke(const QString & params = QString(), boost::any * ret = NULL) const = 0; 00090 virtual qx_bool invoke(const type_any_params & params, boost::any * ret = NULL) const = 0; 00091 virtual qx_bool invoke(void * pOwner, const QString & params = QString(), boost::any * ret = NULL) const = 0; 00092 virtual qx_bool invoke(void * pOwner, const type_any_params & params, boost::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 boost::is_same<T, void> qx_verify_owner_tmp; 00103 BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value); 00104 if (! pOwner) { return qx_bool(false, 0, QX_FUNCTION_ERR_NULL_OWNER); } 00105 if (! dynamic_cast<T *>(static_cast<T *>(pOwner))) { return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_OWNER); } 00106 return true; 00107 } 00108 00109 template <class T> 00110 qx_bool isValid(const T & params) const 00111 { 00112 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00113 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00114 return true; 00115 } 00116 00117 template <class T, class U> 00118 qx_bool isValid(void * pOwner, const T & params, U * dummy) const 00119 { 00120 Q_UNUSED(dummy); 00121 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00122 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00123 bValid = isValidOwner<U>(pOwner, NULL); if (! bValid) { return bValid; }; 00124 return true; 00125 } 00126 00127 }; 00128 00129 typedef boost::shared_ptr<IxFunction> IxFunction_ptr; 00130 typedef QxCollection<QString, IxFunction_ptr> IxFunctionX; 00131 typedef boost::shared_ptr<IxFunctionX> IxFunctionX_ptr; 00132 00133 } // namespace qx 00134 00135 #endif // _IX_FUNCTION_H_