Skip to content
Snippets Groups Projects
Commit e2a56cda authored by Ramin Yaghoubzadeh's avatar Ramin Yaghoubzadeh
Browse files

C++: added bool casting for payloads. Added overloaded setters.

parent 52d54644
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <boost/thread.hpp> #include <boost/thread.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/pointer_cast.hpp> #include <boost/pointer_cast.hpp>
#include <boost/lexical_cast.hpp>
#include <rsc/runtime/TypeStringTools.h> #include <rsc/runtime/TypeStringTools.h>
#include <rsb/Factory.h> #include <rsb/Factory.h>
...@@ -409,12 +410,18 @@ class PayloadEntryProxy//{{{ ...@@ -409,12 +410,18 @@ class PayloadEntryProxy//{{{
public: public:
PayloadEntryProxy(Payload* payload, const std::string& key); PayloadEntryProxy(Payload* payload, const std::string& key);
PayloadEntryProxy& operator=(const std::string& value); PayloadEntryProxy& operator=(const std::string& value);
PayloadEntryProxy& operator=(const char* value);
PayloadEntryProxy& operator=(double value);
PayloadEntryProxy& operator=(bool value);
operator std::string(); operator std::string();
operator long(); operator long();
operator double(); operator double();
operator bool();
inline std::string to_str() { return operator std::string(); } 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 double to_float() { return operator double(); }
inline bool to_bool() { return operator bool(); }
};//}}} };//}}}
class Payload//{{{ class Payload//{{{
......
...@@ -993,20 +993,44 @@ PayloadEntryProxy::PayloadEntryProxy(Payload* payload, const std::string& key) ...@@ -993,20 +993,44 @@ PayloadEntryProxy::PayloadEntryProxy(Payload* payload, const std::string& key)
} }
PayloadEntryProxy& PayloadEntryProxy::operator=(const std::string& value) PayloadEntryProxy& PayloadEntryProxy::operator=(const std::string& value)
{ {
std::cout << "operator=(string)" << std::endl;
_payload->set(_key, value); _payload->set(_key, value);
return *this; 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() PayloadEntryProxy::operator std::string()
{ {
return _payload->get(_key); return _payload->get(_key);
} }
PayloadEntryProxy::operator bool()
{
std::string s = operator std::string();
return ((s=="1")||(s=="true")||(s=="True"));
}
PayloadEntryProxy::operator long() PayloadEntryProxy::operator long()
{ {
return atol(operator std::string().c_str()); return boost::lexical_cast<long>(operator std::string().c_str());
} }
PayloadEntryProxy::operator double() PayloadEntryProxy::operator double()
{ {
return atof(operator std::string().c_str()); return boost::lexical_cast<double>(operator std::string().c_str());
} }
//}}} //}}}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment