Commit a3e0f04e authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[2498] Add operator= and use scoped_ptr in HINFO and NAPTR

parent 360a5bb6
......@@ -96,8 +96,14 @@ HINFO::HINFO(MasterLexer& lexer, const Name*,
impl_(new HINFOImpl(lexer))
{}
HINFO&
HINFO::operator=(const HINFO& source)
{
impl_.reset(new HINFOImpl(*source.impl_));
return (*this);
}
HINFO::~HINFO() {
delete impl_;
}
std::string
......@@ -149,5 +155,9 @@ HINFO::toWireHelper(T& outputer) const {
outputer.writeData(&impl_->os[0], impl_->os.size());
}
void HINFO::ptr() const {
std::cout << "[XX] PTR: " << impl_.get() << std::endl;
}
// END_RDATA_NAMESPACE
// END_ISC_NAMESPACE
......@@ -17,6 +17,9 @@
#include <string>
#include <boost/scoped_ptr.hpp>
#include <boost/noncopyable.hpp>
#include <dns/name.h>
#include <dns/rdata.h>
#include <util/buffer.h>
......@@ -44,9 +47,12 @@ public:
// HINFO specific methods
~HINFO();
HINFO& operator=(const HINFO&);
const std::string getCPU() const;
const std::string getOS() const;
void ptr() const;
private:
/// Helper template function for toWire()
///
......@@ -54,7 +60,7 @@ private:
template <typename T>
void toWireHelper(T& outputer) const;
HINFOImpl* impl_;
boost::scoped_ptr<HINFOImpl> impl_;
};
......
......@@ -141,8 +141,14 @@ NAPTR::NAPTR(const NAPTR& naptr) : Rdata(),
impl_(new NAPTRImpl(*naptr.impl_))
{}
NAPTR&
NAPTR::operator=(const NAPTR& source)
{
impl_.reset(new NAPTRImpl(*source.impl_));
return (*this);
}
NAPTR::~NAPTR() {
delete impl_;
}
void
......
......@@ -16,6 +16,8 @@
#include <string>
#include <boost/scoped_ptr.hpp>
#include <dns/name.h>
#include <dns/rdata.h>
#include <util/buffer.h>
......@@ -43,6 +45,8 @@ public:
// NAPTR specific methods
~NAPTR();
NAPTR& operator=(const NAPTR& source);
uint16_t getOrder() const;
uint16_t getPreference() const;
const std::string getFlags() const;
......@@ -56,7 +60,7 @@ private:
template <typename T>
void toWireHelper(T& outputer) const;
NAPTRImpl* impl_;
boost::scoped_ptr<NAPTRImpl> impl_;
};
// END_RDATA_NAMESPACE
......
......@@ -136,4 +136,17 @@ TEST_F(Rdata_HINFO_Test, compare) {
EXPECT_EQ(-1, hinfo.compare(HINFO(hinfo_str_large2)));
}
// Copy/assign test
TEST_F(Rdata_HINFO_Test, copy) {
HINFO hinfo(hinfo_str);
HINFO hinfo2(hinfo);
HINFO hinfo3 = hinfo;
EXPECT_EQ(0, hinfo.compare(hinfo2));
EXPECT_EQ(0, hinfo.compare(hinfo3));
hinfo3 = hinfo;
EXPECT_EQ(0, hinfo.compare(hinfo3));
}
}
......@@ -219,7 +219,18 @@ TEST_F(Rdata_NAPTR_Test, compare) {
EXPECT_EQ(1, naptr_large3.compare(naptr));
EXPECT_EQ(1, naptr_large4.compare(naptr));
EXPECT_EQ(1, naptr_large5.compare(naptr));
}
TEST_F(Rdata_NAPTR_Test, copy) {
NAPTR naptr(naptr_str);
NAPTR naptr2(naptr);
NAPTR naptr3 = naptr;
EXPECT_EQ(0, naptr.compare(naptr2));
EXPECT_EQ(0, naptr.compare(naptr3));
naptr3 = naptr;
EXPECT_EQ(0, naptr.compare(naptr3));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment