QxOrm  1.4.2
C++ Object Relational Mapping library
IxFunction.h
Go to the documentation of this file.
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    QString m_sDescription;    
00076 
00077 public:
00078 
00079    typedef std::vector<boost::any> type_any_params;
00080 
00081    IxFunction() : qx::QxPropertyBag(), m_sSeparator("|") { ; }
00082    virtual ~IxFunction() { ; }
00083 
00084    QString getKey() const                 { return m_sKey; }
00085    QString getSeparator() const           { return m_sSeparator; }
00086    QString getDescription() const         { return m_sDescription; }
00087 
00088    void setKey(const QString & s)         { m_sKey = s; }
00089    void setSeparator(const QString & s)   { m_sSeparator = s; }
00090    void setDescription(const QString & s) { m_sDescription = s; }
00091 
00092    virtual int getParamCount() const = 0;
00093 
00094    virtual qx_bool invoke(const QString & params = QString(), boost::any * ret = NULL) const = 0;
00095    virtual qx_bool invoke(const type_any_params & params, boost::any * ret = NULL) const = 0;
00096    virtual qx_bool invoke(void * pOwner, const QString & params = QString(), boost::any * ret = NULL) const = 0;
00097    virtual qx_bool invoke(void * pOwner, const type_any_params & params, boost::any * ret = NULL) const = 0;
00098 
00099    virtual qx_bool isValidFct() const = 0;
00100    virtual qx_bool isValidParams(const QString & params) const = 0;
00101    virtual qx_bool isValidParams(const type_any_params & params) const = 0;
00102 
00103    template <class T>
00104    qx_bool isValidOwner(void * pOwner, T * dummy) const
00105    {
00106       Q_UNUSED(dummy);
00107       typedef boost::is_same<T, void> qx_verify_owner_tmp;
00108       BOOST_STATIC_ASSERT(! qx_verify_owner_tmp::value);
00109       if (! pOwner) { return qx_bool(false, 0, QX_FUNCTION_ERR_NULL_OWNER); }
00110 #ifndef _QX_NO_RTTI
00111       if (! dynamic_cast<T *>(static_cast<T *>(pOwner))) { return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_OWNER); }
00112 #endif // _QX_NO_RTTI
00113       return true;
00114    }
00115 
00116    template <class T>
00117    qx_bool isValid(const T & params) const
00118    {
00119       qx_bool bValid = isValidFct(); if (! bValid) { return bValid; };
00120       bValid = isValidParams(params); if (! bValid) { return bValid; };
00121       return true;
00122    }
00123 
00124    template <class T, class U>
00125    qx_bool isValid(void * pOwner, const T & params, U * dummy) const
00126    {
00127       Q_UNUSED(dummy);
00128       qx_bool bValid = isValidFct(); if (! bValid) { return bValid; };
00129       bValid = isValidParams(params); if (! bValid) { return bValid; };
00130       bValid = isValidOwner<U>(pOwner, NULL); if (! bValid) { return bValid; };
00131       return true;
00132    }
00133 
00134 };
00135 
00136 typedef qx_shared_ptr<IxFunction> IxFunction_ptr;
00137 typedef QxCollection<QString, IxFunction_ptr> IxFunctionX;
00138 typedef qx_shared_ptr<IxFunctionX> IxFunctionX_ptr;
00139 
00140 } // namespace qx
00141 
00142 #endif // _IX_FUNCTION_H_