From: Gunnar Beutner Date: Mon, 24 Nov 2014 06:09:51 +0000 (+0100) Subject: Move the cast functions into libbase X-Git-Tag: v2.3.0~622 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d125edc0dc1a8648dd3bc53400437e429cb5f30;p=icinga2 Move the cast functions into libbase fixes #7807 --- diff --git a/lib/base/scriptutils.cpp b/lib/base/scriptutils.cpp index 56d685908..5f5a08bdd 100644 --- a/lib/base/scriptutils.cpp +++ b/lib/base/scriptutils.cpp @@ -47,7 +47,24 @@ REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys); REGISTER_SCRIPTFUNCTION(random, &Utility::Random); REGISTER_SCRIPTFUNCTION(__get_object, &ScriptUtils::GetObject); REGISTER_SCRIPTFUNCTION(assert, &ScriptUtils::Assert); +REGISTER_SCRIPTFUNCTION(string, &ScriptUtils::CastString); +REGISTER_SCRIPTFUNCTION(number, &ScriptUtils::CastNumber); +REGISTER_SCRIPTFUNCTION(bool, &ScriptUtils::CastBool); +String ScriptUtils::CastString(const Value& value) +{ + return value; +} + +double ScriptUtils::CastNumber(const Value& value) +{ + return value; +} + +bool ScriptUtils::CastBool(const Value& value) +{ + return value.ToBool(); +} bool ScriptUtils::Regex(const String& pattern, const String& text) { bool res = false; diff --git a/lib/base/scriptutils.hpp b/lib/base/scriptutils.hpp index a119d4269..debcdd607 100644 --- a/lib/base/scriptutils.hpp +++ b/lib/base/scriptutils.hpp @@ -36,6 +36,9 @@ namespace icinga class I2_BASE_API ScriptUtils { public: + static String CastString(const Value& value); + static double CastNumber(const Value& value); + static bool CastBool(const Value& value); static bool Regex(const String& pattern, const String& text); static int Len(const Value& value); static Array::Ptr Union(const std::vector& arguments); diff --git a/lib/methods/CMakeLists.txt b/lib/methods/CMakeLists.txt index 35b557138..bb3cf63cd 100644 --- a/lib/methods/CMakeLists.txt +++ b/lib/methods/CMakeLists.txt @@ -22,7 +22,7 @@ else() endif() set(methods_SOURCES - castfuncs.cpp clusterchecktask.cpp clusterzonechecktask.cpp + clusterchecktask.cpp clusterzonechecktask.cpp icingachecktask.cpp nullchecktask.cpp nulleventtask.cpp pluginchecktask.cpp plugineventtask.cpp pluginnotificationtask.cpp randomchecktask.cpp timeperiodtask.cpp ${WindowsSources} diff --git a/lib/methods/castfuncs.cpp b/lib/methods/castfuncs.cpp deleted file mode 100644 index a925edd9b..000000000 --- a/lib/methods/castfuncs.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2014 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. * - ******************************************************************************/ - -#include "methods/castfuncs.hpp" -#include "base/scriptfunction.hpp" - -using namespace icinga; - -REGISTER_SCRIPTFUNCTION(string, &CastFuncs::CastString); -REGISTER_SCRIPTFUNCTION(number, &CastFuncs::CastNumber); -REGISTER_SCRIPTFUNCTION(bool, &CastFuncs::CastBool); - -String CastFuncs::CastString(const Value& value) -{ - return value; -} - -double CastFuncs::CastNumber(const Value& value) -{ - return value; -} - -bool CastFuncs::CastBool(const Value& value) -{ - return value.ToBool(); -} diff --git a/lib/methods/castfuncs.hpp b/lib/methods/castfuncs.hpp deleted file mode 100644 index b8612afe7..000000000 --- a/lib/methods/castfuncs.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * Icinga 2 * - * Copyright (C) 2012-2014 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 CASTFUNCS_H -#define CASTFUNCS_H - -#include "methods/i2-methods.hpp" -#include "base/string.hpp" - -namespace icinga -{ - -/** - * @ingroup methods - */ -class I2_METHODS_API CastFuncs -{ -public: - static String CastString(const Value& value); - static double CastNumber(const Value& value); - static bool CastBool(const Value& value); - -private: - CastFuncs(void); -}; - -} - -#endif /* CASTFUNCS_H */