]> granicus.if.org Git - icinga2/commitdiff
Implement Convert class, move existing type conversion functionality there
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 29 Jan 2013 11:05:46 +0000 (12:05 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Tue, 29 Jan 2013 11:05:46 +0000 (12:05 +0100)
Fixes #3580

lib/base/Makefile.am
lib/base/qstring.cpp
lib/base/qstring.h
lib/icinga/externalcommand.cpp

index 575a83546aa4a12174b29729838946b0aaa0ddf2..e853892e8d73443859c8b15ab3ab0186f5b25f91 100644 (file)
@@ -12,6 +12,8 @@ libbase_la_SOURCES =  \
        component.h \
        connection.cpp \
        connection.h \
+       convert.cpp \
+       convert.h \
        dictionary.cpp \
        dictionary.h \
        dynamicobject.cpp \
index 30538c509c833df0a01dc42d3121f4c6afc83155..4ac2d206a09e8a2d9ae06314ed68b794c1738cee 100644 (file)
@@ -159,11 +159,6 @@ String::ConstIterator String::End(void) const
        return m_Data.end();
 }
 
-double String::ToDouble(void) const
-{
-       return strtod(CStr(), NULL);
-}
-
 ostream& icinga::operator<<(ostream& stream, const String& str)
 {
        stream << static_cast<std::string>(str);
index d6cbecf4f7ad532e03d66e19774f3b25f31e2d32..154cb6245d2a05bf5910ec89943e3257ce82b6d1 100644 (file)
@@ -87,8 +87,6 @@ public:
        Iterator End(void);
        ConstIterator End(void) const;
 
-       double ToDouble(void) const;
-
        static const size_t NPos;
 
 private:
index e72e6ad8559accba8d0ef9e4d27f0232a47d7d24..dcddf090f4a7c243328ab7f8da034e060d287e6b 100644 (file)
@@ -40,7 +40,7 @@ void ExternalCommand::Execute(const String& line)
        String timestamp = line.SubStr(1, pos - 1);
        String args = line.SubStr(pos + 2, String::NPos);
 
-       double ts = timestamp.ToDouble();
+       double ts = Convert::ToDouble(timestamp);
 
        if (ts == 0)
                throw_exception(invalid_argument("Invalid timestamp in command: " + line));
@@ -121,7 +121,7 @@ void ExternalCommand::ProcessServiceCheckResult(double time, const vector<String
        if (!service->GetEnablePassiveChecks())
                throw_exception(invalid_argument("Got passive check result for service '" + arguments[1] + "' which has passive checks disabled."));
 
-       int exitStatus = arguments[2].ToDouble();
+       int exitStatus = Convert::ToDouble(arguments[2]);
        Dictionary::Ptr result = PluginCheckTask::ParseCheckOutput(arguments[3]);
        result->Set("state", PluginCheckTask::ExitStatusToState(exitStatus));
 
@@ -151,7 +151,7 @@ void ExternalCommand::ScheduleSvcCheck(double time, const vector<String>& argume
 
        Service::Ptr service = Service::GetByName(arguments[1]);
 
-       double planned_check = arguments[2].ToDouble();
+       double planned_check = Convert::ToDouble(arguments[2]);
 
        if (planned_check > service->GetNextCheck()) {
                Logger::Write(LogInformation, "icinga", "Ignoring reschedule request for service '" +
@@ -175,7 +175,7 @@ void ExternalCommand::ScheduleForcedSvcCheck(double time, const vector<String>&
 
        Logger::Write(LogInformation, "icinga", "Rescheduling next check for service '" + arguments[1] + "'");
        service->SetForceNextCheck(true);
-       service->SetNextCheck(arguments[2].ToDouble());
+       service->SetNextCheck(Convert::ToDouble(arguments[2]));
 }
 
 void ExternalCommand::EnableSvcCheck(double time, const vector<String>& arguments)
@@ -220,7 +220,7 @@ void ExternalCommand::ScheduleForcedHostSvcChecks(double time, const vector<Stri
        if (!Host::Exists(arguments[0]))
                throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
 
-       double planned_check = arguments[1].ToDouble();
+       double planned_check = Convert::ToDouble(arguments[1]);
 
        Host::Ptr host = Host::GetByName(arguments[0]);
 
@@ -245,7 +245,7 @@ void ExternalCommand::ScheduleHostSvcChecks(double time, const vector<String>& a
        if (!Host::Exists(arguments[0]))
                throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
 
-       double planned_check = arguments[1].ToDouble();
+       double planned_check = Convert::ToDouble(arguments[1]);
 
        Host::Ptr host = Host::GetByName(arguments[0]);
 
@@ -319,7 +319,7 @@ void ExternalCommand::AcknowledgeSvcProblem(double time, const vector<String>& a
        if (!Service::Exists(arguments[1]))
                throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
 
-       int sticky = arguments[2].ToDouble();
+       bool sticky = Convert::ToBool(arguments[2]);
 
        Service::Ptr service = Service::GetByName(arguments[1]);
 
@@ -339,8 +339,8 @@ void ExternalCommand::AcknowledgeSvcProblemExpire(double time, const vector<Stri
        if (!Service::Exists(arguments[1]))
                throw_exception(invalid_argument("The service '" + arguments[1] + "' does not exist."));
 
-       int sticky = arguments[2].ToDouble();
-       double timestamp = arguments[5].ToDouble();
+       bool sticky = Convert::ToBool(arguments[2]);
+       double timestamp = Convert::ToDouble(arguments[5]);
 
        Service::Ptr service = Service::GetByName(arguments[1]);
 
@@ -375,7 +375,7 @@ void ExternalCommand::AcknowledgeHostProblem(double time, const vector<String>&
        if (!Host::Exists(arguments[0]))
                throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
 
-       int sticky = arguments[0].ToDouble();
+       bool sticky = Convert::ToBool(arguments[0]);
 
        Host::Ptr host = Host::GetByName(arguments[0]);
 
@@ -395,8 +395,8 @@ void ExternalCommand::AcknowledgeHostProblemExpire(double time, const vector<Str
        if (!Host::Exists(arguments[0]))
                throw_exception(invalid_argument("The host '" + arguments[0] + "' does not exist."));
 
-       int sticky = arguments[1].ToDouble();
-       double timestamp = arguments[4].ToDouble();
+       bool sticky = Convert::ToBool(arguments[1]);
+       double timestamp = Convert::ToDouble(arguments[4]);
 
        Host::Ptr host = Host::GetByName(arguments[0]);
 
@@ -593,7 +593,7 @@ void ExternalCommand::ProcessFile(double time, const vector<String>& arguments)
                throw_exception(invalid_argument("Expected 2 arguments."));
 
        String file = arguments[0];
-       int del = arguments[1].ToDouble();
+       bool del = Convert::ToBool(arguments[1]);
 
        ifstream ifp;
        ifp.exceptions(ifstream::badbit);