![]() |
QxOrm
1.2.3
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** http://sourceforge.net/projects/qxorm/ 00005 ** Original file by Lionel Marty 00006 ** 00007 ** This file is part of the QxOrm library 00008 ** 00009 ** This software is provided 'as-is', without any express or implied 00010 ** warranty. In no event will the authors be held liable for any 00011 ** damages arising from the use of this software. 00012 ** 00013 ** GNU Lesser General Public License Usage 00014 ** This file must be used under the terms of the GNU Lesser 00015 ** General Public License version 2.1 as published by the Free Software 00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the 00017 ** packaging of this file. Please review the following information to 00018 ** ensure the GNU Lesser General Public License version 2.1 requirements 00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 00020 ** 00021 ** If you have questions regarding the use of this file, please contact : 00022 ** contact@qxorm.com 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef _IX_FUNCTION_H_ 00027 #define _IX_FUNCTION_H_ 00028 00029 #ifdef _MSC_VER 00030 #pragma once 00031 #endif 00032 00040 #include <boost/any.hpp> 00041 #include <boost/function.hpp> 00042 #include <boost/lexical_cast.hpp> 00043 #include <boost/static_assert.hpp> 00044 #include <boost/type_traits/is_same.hpp> 00045 00046 #include <QxCommon/QxBool.h> 00047 #include <QxCommon/QxPropertyBag.h> 00048 00049 #include <QxCollection/QxCollection.h> 00050 00051 #include <QxFunction/QxFunctionError.h> 00052 #include <QxFunction/QxFunctionMacro.h> 00053 00054 #include <QxTraits/remove_attr.h> 00055 00056 namespace qx { 00057 00062 class IxFunction : public qx::QxPropertyBag 00063 { 00064 00065 protected: 00066 00067 QString m_sKey; 00068 QString m_sSeparator; 00069 00070 public: 00071 00072 typedef std::vector<boost::any> type_any_params; 00073 00074 IxFunction() : qx::QxPropertyBag(), m_sSeparator("|") { ; } 00075 virtual ~IxFunction() { ; } 00076 00077 QString getKey() const { return m_sKey; } 00078 QString getSeparator() const { return m_sSeparator; } 00079 00080 void setKey(const QString & s) { m_sKey = s; } 00081 void setSeparator(const QString & s) { m_sSeparator = s; } 00082 00083 virtual qx_bool invoke(const QString & params = QString(), boost::any * ret = NULL) const = 0; 00084 virtual qx_bool invoke(const type_any_params & params, boost::any * ret = NULL) const = 0; 00085 virtual qx_bool invoke(void * pOwner, const QString & params = QString(), boost::any * ret = NULL) const = 0; 00086 virtual qx_bool invoke(void * pOwner, const type_any_params & params, boost::any * ret = NULL) const = 0; 00087 00088 virtual qx_bool isValidFct() const = 0; 00089 virtual qx_bool isValidParams(const QString & params) const = 0; 00090 virtual qx_bool isValidParams(const type_any_params & params) const = 0; 00091 00092 template <class T> 00093 qx_bool isValidOwner(void * pOwner, T * dummy) const 00094 { 00095 Q_UNUSED(dummy); 00096 typedef boost::is_same<T, void> qx_verify_owner_tmp; 00097 BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value); 00098 if (! pOwner) { return qx_bool(false, 0, QX_FUNCTION_ERR_NULL_OWNER); } 00099 if (! dynamic_cast<T *>(static_cast<T *>(pOwner))) { return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_OWNER); } 00100 return true; 00101 } 00102 00103 template <class T> 00104 qx_bool isValid(const T & params) const 00105 { 00106 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00107 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00108 return true; 00109 } 00110 00111 template <class T, class U> 00112 qx_bool isValid(void * pOwner, const T & params, U * dummy) const 00113 { 00114 Q_UNUSED(dummy); 00115 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00116 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00117 bValid = isValidOwner<U>(pOwner, NULL); if (! bValid) { return bValid; }; 00118 return true; 00119 } 00120 00121 }; 00122 00123 typedef boost::shared_ptr<IxFunction> IxFunction_ptr; 00124 typedef QxCollection<QString, IxFunction_ptr> IxFunctionX; 00125 typedef boost::shared_ptr<IxFunctionX> IxFunctionX_ptr; 00126 00127 } // namespace qx 00128 00129 #endif // _IX_FUNCTION_H_