/****************************************************************************** * Icinga 2 * * Copyright (C) 2012-2013 Icinga Development Team (http://www.icinga.org/) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License * * as published by the Free Software Foundation; either version 2 * * of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the Free Software Foundation * * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ******************************************************************************/ #ifndef SCRIPTFUNCTIONWRAPPER_H #define SCRIPTFUNCTIONWRAPPER_H #include "base/i2-base.h" #include "base/value.h" #include #include #include namespace icinga { Value ScriptFunctionWrapperVV(void (*function)(void), const std::vector& arguments); boost::function& arguments)> I2_BASE_API WrapScriptFunction(void (*function)(void)); template Value ScriptFunctionWrapperR(TR (*function)(void), const std::vector&) { return function(); } template boost::function& arguments)> WrapScriptFunction(TR (*function)(void)) { return boost::bind(&ScriptFunctionWrapperR, function, _1); } template Value ScriptFunctionWrapperV(void (*function)(T0), const std::vector& arguments) { if (arguments.size() < 1) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); function(static_cast(arguments[0])); return Empty; } template boost::function& arguments)> WrapScriptFunction(void (*function)(T0)) { return boost::bind(&ScriptFunctionWrapperV, function, _1); } template Value ScriptFunctionWrapperR(TR (*function)(T0), const std::vector& arguments) { if (arguments.size() < 1) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); return function(static_cast(arguments[0])); } template boost::function& arguments)> WrapScriptFunction(TR (*function)(T0)) { return boost::bind(&ScriptFunctionWrapperR, function, _1); } template Value ScriptFunctionWrapperV(void (*function)(T0, T1), const std::vector& arguments) { if (arguments.size() < 2) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); function(static_cast(arguments[0]), static_cast(arguments[1])); return Empty; } template boost::function& arguments)> WrapScriptFunction(void (*function)(T0, T1)) { return boost::bind(&ScriptFunctionWrapperV, function, _1); } template Value ScriptFunctionWrapperR(TR (*function)(T0, T1), const std::vector& arguments) { if (arguments.size() < 2) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); return function(static_cast(arguments[0]), static_cast(arguments[1])); } template boost::function& arguments)> WrapScriptFunction(TR (*function)(T0, T1)) { return boost::bind(&ScriptFunctionWrapperR, function, _1); } template Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2), const std::vector& arguments) { if (arguments.size() < 3) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); function(static_cast(arguments[0]), static_cast(arguments[1]), static_cast(arguments[2])); return Empty; } template boost::function& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2)) { return boost::bind(&ScriptFunctionWrapperV, function, _1); } template Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2), const std::vector& arguments) { if (arguments.size() < 3) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); return function(static_cast(arguments[0]), static_cast(arguments[1]), static_cast(arguments[2])); } template boost::function& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2)) { return boost::bind(&ScriptFunctionWrapperR, function, _1); } template Value ScriptFunctionWrapperV(void (*function)(T0, T1, T2, T3), const std::vector& arguments) { if (arguments.size() < 4) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); function(static_cast(arguments[0]), static_cast(arguments[1]), static_cast(arguments[2]), static_cast(arguments[3])); return Empty; } template boost::function& arguments)> WrapScriptFunction(void (*function)(T0, T1, T2, T3)) { return boost::bind(&ScriptFunctionWrapperV, function, _1); } template Value ScriptFunctionWrapperR(TR (*function)(T0, T1, T2, T3), const std::vector& arguments) { if (arguments.size() < 4) BOOST_THROW_EXCEPTION(std::invalid_argument("Too few arguments for function.")); return function(static_cast(arguments[0]), static_cast(arguments[1]), static_cast(arguments[2]), static_cast(arguments[3])); } template boost::function& arguments)> WrapScriptFunction(TR (*function)(T0, T1, T2, T3)) { return boost::bind(&ScriptFunctionWrapperR, function, _1); } boost::function& arguments)> I2_BASE_API WrapScriptFunction(Value (*function)(const std::vector&)); } #endif /* SCRIPTFUNCTION_H */