[icinga-checkins] icinga.org: icinga2/master: Implement Convert class, move existing type conversion functionality there

git at icinga.org git at icinga.org
Tue Jan 29 14:20:07 CET 2013


Module: icinga2
Branch: master
Commit: 76f37c1d7130dce353afa77630e6ebeb22ff1150
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=76f37c1d7130dce353afa77630e6ebeb22ff1150

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Tue Jan 29 12:05:46 2013 +0100

Implement Convert class, move existing type conversion functionality there

Fixes #3580

---

 lib/base/Makefile.am           |    2 ++
 lib/base/qstring.cpp           |    5 -----
 lib/base/qstring.h             |    2 --
 lib/icinga/externalcommand.cpp |   26 +++++++++++++-------------
 4 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/lib/base/Makefile.am b/lib/base/Makefile.am
index 575a835..e853892 100644
--- a/lib/base/Makefile.am
+++ b/lib/base/Makefile.am
@@ -12,6 +12,8 @@ libbase_la_SOURCES =  \
 	component.h \
 	connection.cpp \
 	connection.h \
+	convert.cpp \
+	convert.h \
 	dictionary.cpp \
 	dictionary.h \
 	dynamicobject.cpp \
diff --git a/lib/base/qstring.cpp b/lib/base/qstring.cpp
index 30538c5..4ac2d20 100644
--- a/lib/base/qstring.cpp
+++ b/lib/base/qstring.cpp
@@ -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);
diff --git a/lib/base/qstring.h b/lib/base/qstring.h
index d6cbecf..154cb62 100644
--- a/lib/base/qstring.h
+++ b/lib/base/qstring.h
@@ -87,8 +87,6 @@ public:
 	Iterator End(void);
 	ConstIterator End(void) const;
 
-	double ToDouble(void) const;
-
 	static const size_t NPos;
 
 private:
diff --git a/lib/icinga/externalcommand.cpp b/lib/icinga/externalcommand.cpp
index e72e6ad..dcddf09 100644
--- a/lib/icinga/externalcommand.cpp
+++ b/lib/icinga/externalcommand.cpp
@@ -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);





More information about the icinga-checkins mailing list