Move the cast functions into libbase

fixes #7807
This commit is contained in:
Gunnar Beutner 2014-11-24 07:09:51 +01:00
parent c5b5eccf49
commit 4d125edc0d
5 changed files with 21 additions and 88 deletions

View File

@ -47,7 +47,24 @@ REGISTER_SCRIPTFUNCTION(keys, &ScriptUtils::Keys);
REGISTER_SCRIPTFUNCTION(random, &Utility::Random); REGISTER_SCRIPTFUNCTION(random, &Utility::Random);
REGISTER_SCRIPTFUNCTION(__get_object, &ScriptUtils::GetObject); REGISTER_SCRIPTFUNCTION(__get_object, &ScriptUtils::GetObject);
REGISTER_SCRIPTFUNCTION(assert, &ScriptUtils::Assert); 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 ScriptUtils::Regex(const String& pattern, const String& text)
{ {
bool res = false; bool res = false;

View File

@ -36,6 +36,9 @@ namespace icinga
class I2_BASE_API ScriptUtils class I2_BASE_API ScriptUtils
{ {
public: 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 bool Regex(const String& pattern, const String& text);
static int Len(const Value& value); static int Len(const Value& value);
static Array::Ptr Union(const std::vector<Value>& arguments); static Array::Ptr Union(const std::vector<Value>& arguments);

View File

@ -22,7 +22,7 @@ else()
endif() endif()
set(methods_SOURCES set(methods_SOURCES
castfuncs.cpp clusterchecktask.cpp clusterzonechecktask.cpp clusterchecktask.cpp clusterzonechecktask.cpp
icingachecktask.cpp nullchecktask.cpp nulleventtask.cpp icingachecktask.cpp nullchecktask.cpp nulleventtask.cpp
pluginchecktask.cpp plugineventtask.cpp pluginnotificationtask.cpp pluginchecktask.cpp plugineventtask.cpp pluginnotificationtask.cpp
randomchecktask.cpp timeperiodtask.cpp ${WindowsSources} randomchecktask.cpp timeperiodtask.cpp ${WindowsSources}

View File

@ -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();
}

View File

@ -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 */