From 803ba6cc88fd39c0bc685098a9ebad3161fc943e Mon Sep 17 00:00:00 2001 From: Martijn Otto Date: Wed, 22 Apr 2015 14:24:00 +0200 Subject: [PATCH] Added publish method with r-value std::string --- include/channel.h | 1 + include/envelope.h | 20 +++++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/channel.h b/include/channel.h index 8024e0a..e5e85c3 100644 --- a/include/channel.h +++ b/include/channel.h @@ -338,6 +338,7 @@ public: */ bool publish(const std::string &exchange, const std::string &routingKey, const Envelope &envelope) { return _implementation->publish(exchange, routingKey, envelope); } bool publish(const std::string &exchange, const std::string &routingKey, const std::string &message) { return _implementation->publish(exchange, routingKey, Envelope(message)); } + bool publish(const std::string &exchange, const std::string &routingKey, std::string &&message) { return _implementation->publish(exchange, routingKey, Envelope(std::move(message))); } bool publish(const std::string &exchange, const std::string &routingKey, const char *message, size_t size) { return _implementation->publish(exchange, routingKey, Envelope(message, size)); } bool publish(const std::string &exchange, const std::string &routingKey, const char *message) { return _implementation->publish(exchange, routingKey, Envelope(message, strlen(message))); } diff --git a/include/envelope.h b/include/envelope.h index fbe646e..b1cdf6a 100644 --- a/include/envelope.h +++ b/include/envelope.h @@ -31,7 +31,7 @@ protected: * @var const char * */ const char *_body; - + /** * Size of the data * @var uint64_t @@ -41,26 +41,32 @@ protected: public: /** * Constructor - * + * * The data buffer that you pass to this constructor must be valid during * the lifetime of the Envelope object. - * + * * @param body * @param size */ Envelope(const char *body, uint64_t size) : MetaData(), _body(body), _bodySize(size) {} - + /** * Constructor based on a string * @param body */ Envelope(const std::string &body) : MetaData(), _str(body), _body(_str.data()), _bodySize(_str.size()) {} + /** + * Constructor based on a string + * @param body + */ + Envelope(std::string &&body) : MetaData(), _str(std::move(body)), _body(_str.data()), _bodySize(_str.size()) {} + /** * Destructor */ virtual ~Envelope() {} - + /** * Access to the full message data * @return buffer @@ -69,7 +75,7 @@ public: { return _body; } - + /** * Size of the body * @return uint64_t @@ -78,7 +84,7 @@ public: { return _bodySize; } - + /** * Body as a string * @return string