Browse Source

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

Jelte Jansen 12 years ago
parent
commit
a3e0f04e9f

+ 11 - 1
src/lib/dns/rdata/generic/hinfo_13.cc

@@ -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

+ 7 - 1
src/lib/dns/rdata/generic/hinfo_13.h

@@ -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_;
 };
 
 

+ 7 - 1
src/lib/dns/rdata/generic/naptr_35.cc

@@ -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

+ 5 - 1
src/lib/dns/rdata/generic/naptr_35.h

@@ -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

+ 13 - 0
src/lib/dns/tests/rdata_hinfo_unittest.cc

@@ -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));
+}
+
 }

+ 11 - 0
src/lib/dns/tests/rdata_naptr_unittest.cc

@@ -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));
 }
 
 }