![]() |
QxOrm 1.1.6
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 00048 #include <QxCollection/QxCollection.h> 00049 00050 #include <QxFunction/QxFunctionError.h> 00051 #include <QxFunction/QxFunctionMacro.h> 00052 00053 #include <QxTraits/remove_attr.h> 00054 00055 namespace qx { 00056 00061 class IxFunction 00062 { 00063 00064 protected: 00065 00066 QString m_sSeparator; 00067 00068 public: 00069 00070 typedef std::vector<boost::any> type_any_params; 00071 00072 IxFunction() : m_sSeparator("|") { ; } 00073 virtual ~IxFunction() { ; } 00074 00075 QString getSeparator() const { return m_sSeparator; } 00076 void setSeparator(const QString & s) { m_sSeparator = s; } 00077 00078 virtual qx_bool invoke(const QString & params = QString(), boost::any * ret = NULL) const = 0; 00079 virtual qx_bool invoke(const type_any_params & params, boost::any * ret = NULL) const = 0; 00080 virtual qx_bool invoke(void * pOwner, const QString & params = QString(), boost::any * ret = NULL) const = 0; 00081 virtual qx_bool invoke(void * pOwner, const type_any_params & params, boost::any * ret = NULL) const = 0; 00082 00083 virtual qx_bool isValidFct() const = 0; 00084 virtual qx_bool isValidParams(const QString & params) const = 0; 00085 virtual qx_bool isValidParams(const type_any_params & params) const = 0; 00086 00087 template <class T> 00088 qx_bool isValidOwner(void * pOwner, T * dummy) const 00089 { 00090 Q_UNUSED(dummy); 00091 typedef boost::is_same<T, void> qx_verify_owner_tmp; 00092 BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value); 00093 if (! pOwner) { return qx_bool(false, 0, QX_FUNCTION_ERR_NULL_OWNER); } 00094 if (! dynamic_cast<T *>(static_cast<T *>(pOwner))) { return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_OWNER); } 00095 return true; 00096 } 00097 00098 template <class T> 00099 qx_bool isValid(const T & params) const 00100 { 00101 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00102 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00103 return true; 00104 } 00105 00106 template <class T, class U> 00107 qx_bool isValid(void * pOwner, const T & params, U * dummy) const 00108 { 00109 Q_UNUSED(dummy); 00110 qx_bool bValid = isValidFct(); if (! bValid) { return bValid; }; 00111 bValid = isValidParams(params); if (! bValid) { return bValid; }; 00112 bValid = isValidOwner<U>(pOwner, NULL); if (! bValid) { return bValid; }; 00113 return true; 00114 } 00115 00116 }; 00117 00118 typedef boost::shared_ptr<IxFunction> IxFunction_ptr; 00119 typedef QxCollection<QString, IxFunction_ptr> IxFunctionX; 00120 typedef boost::shared_ptr<IxFunctionX> IxFunctionX_ptr; 00121 00122 } // namespace qx 00123 00124 #endif // _IX_FUNCTION_H_