From e2a56cda9df1ef5ee3e53c67177b0efd5213b687 Mon Sep 17 00:00:00 2001
From: Ramin Yaghoubzadeh <ryaghoub@techfak.uni-bielefeld.de>
Date: Thu, 30 Aug 2012 14:56:11 +0200
Subject: [PATCH] C++: added bool casting for payloads. Added overloaded
 setters.

---
 ipaacalib/cpp/include/ipaaca/ipaaca.h |  9 ++++++++-
 ipaacalib/cpp/src/ipaaca.cc           | 28 +++++++++++++++++++++++++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/ipaacalib/cpp/include/ipaaca/ipaaca.h b/ipaacalib/cpp/include/ipaaca/ipaaca.h
index 3377b50..5f36ad5 100644
--- a/ipaacalib/cpp/include/ipaaca/ipaaca.h
+++ b/ipaacalib/cpp/include/ipaaca/ipaaca.h
@@ -39,6 +39,7 @@
 #include <boost/thread.hpp>
 #include <boost/shared_ptr.hpp>
 #include <boost/pointer_cast.hpp>
+#include <boost/lexical_cast.hpp>
 
 #include <rsc/runtime/TypeStringTools.h>
 #include <rsb/Factory.h>
@@ -409,12 +410,18 @@ class PayloadEntryProxy//{{{
 	public:
 		PayloadEntryProxy(Payload* payload, const std::string& key);
 		PayloadEntryProxy& operator=(const std::string& value);
+		PayloadEntryProxy& operator=(const char* value);
+		PayloadEntryProxy& operator=(double value);
+		PayloadEntryProxy& operator=(bool value);
 		operator std::string();
 		operator long();
 		operator double();
+		operator bool();
 		inline std::string to_str() { return operator std::string(); }
-		inline long to_int() { return operator long(); }
+		//inline long to_int() { return operator long(); }
+		inline long to_long() { return operator long(); }
 		inline double to_float() { return operator double(); }
+		inline bool to_bool() { return operator bool(); }
 };//}}}
 
 class Payload//{{{
diff --git a/ipaacalib/cpp/src/ipaaca.cc b/ipaacalib/cpp/src/ipaaca.cc
index bd246c4..2651353 100644
--- a/ipaacalib/cpp/src/ipaaca.cc
+++ b/ipaacalib/cpp/src/ipaaca.cc
@@ -993,20 +993,44 @@ PayloadEntryProxy::PayloadEntryProxy(Payload* payload, const std::string& key)
 }
 PayloadEntryProxy& PayloadEntryProxy::operator=(const std::string& value)
 {
+	std::cout << "operator=(string)" << std::endl;
 	_payload->set(_key, value);
 	return *this;
 }
+PayloadEntryProxy& PayloadEntryProxy::operator=(const char* value)
+{
+	std::cout << "operator=(const char*)" << std::endl;
+	_payload->set(_key, value);
+	return *this;
+}
+PayloadEntryProxy& PayloadEntryProxy::operator=(double value)
+{
+	std::cout << "operator=(double)" << std::endl;
+	_payload->set(_key, boost::lexical_cast<std::string>(value));
+	return *this;
+}
+PayloadEntryProxy& PayloadEntryProxy::operator=(bool value)
+{
+	std::cout << "operator=(bool)" << std::endl;
+	_payload->set(_key, boost::lexical_cast<std::string>(value));
+	return *this;
+}
 PayloadEntryProxy::operator std::string()
 {
 	return _payload->get(_key);
 }
+PayloadEntryProxy::operator bool()
+{
+	std::string s = operator std::string();
+	return ((s=="1")||(s=="true")||(s=="True"));
+}
 PayloadEntryProxy::operator long()
 {
-	return atol(operator std::string().c_str());
+	return boost::lexical_cast<long>(operator std::string().c_str());
 }
 PayloadEntryProxy::operator double()
 {
-	return atof(operator std::string().c_str());
+	return boost::lexical_cast<double>(operator std::string().c_str());
 }
 //}}}
 
-- 
GitLab