Use ClonablePtr on TopicConfiguration

This commit is contained in:
Matias Fontanini
2016-05-31 07:39:13 -07:00
parent 82393b558e
commit a74d46094f
2 changed files with 4 additions and 18 deletions

View File

@@ -1,26 +1,22 @@
#ifndef CPPKAFKA_TOPIC_CONFIGURATION_H
#define CPPKAFKA_TOPIC_CONFIGURATION_H
#include <memory>
#include <string>
#include <librdkafka/rdkafka.h>
#include "clonable_ptr.h"
namespace cppkafka {
class TopicConfiguration {
public:
TopicConfiguration();
TopicConfiguration(const TopicConfiguration& rhs);
TopicConfiguration(TopicConfiguration&& rhs) noexcept = default;
TopicConfiguration& operator=(const TopicConfiguration& rhs);
TopicConfiguration& operator=(TopicConfiguration&& rhs) noexcept = default;
void set(const std::string& name, const std::string& value);
rd_kafka_topic_conf_t* get_handle() const;
private:
using HandlePtr = std::unique_ptr<rd_kafka_topic_conf_t,
decltype(&rd_kafka_topic_conf_destroy)>;
using HandlePtr = ClonablePtr<rd_kafka_topic_conf_t, decltype(&rd_kafka_topic_conf_destroy),
decltype(&rd_kafka_topic_conf_dup)>;
TopicConfiguration(rd_kafka_topic_conf_t* ptr);
static HandlePtr make_handle(rd_kafka_topic_conf_t* ptr);

View File

@@ -16,16 +16,6 @@ TopicConfiguration::TopicConfiguration(rd_kafka_topic_conf_t* ptr)
}
TopicConfiguration::TopicConfiguration(const TopicConfiguration& rhs)
: handle_(make_handle(rd_kafka_topic_conf_dup(rhs.handle_.get()))) {
}
TopicConfiguration& TopicConfiguration::operator=(const TopicConfiguration& rhs) {
handle_.reset(rd_kafka_topic_conf_dup(rhs.handle_.get()));
return *this;
}
void TopicConfiguration::set(const string& name, const string& value) {
char error_buffer[512];
rd_kafka_conf_res_t result;
@@ -41,7 +31,7 @@ rd_kafka_topic_conf_t* TopicConfiguration::get_handle() const {
}
TopicConfiguration::HandlePtr TopicConfiguration::make_handle(rd_kafka_topic_conf_t* ptr) {
return HandlePtr(ptr, &rd_kafka_topic_conf_destroy);
return HandlePtr(ptr, &rd_kafka_topic_conf_destroy, &rd_kafka_topic_conf_dup);
}
} // cppkafka