Parcourir la source

[2786] Changes as a result of the second review.

Marcin Siodelski il y a 12 ans
Parent
commit
e0d3a70def
3 fichiers modifiés avec 16 ajouts et 16 suppressions
  1. 2 9
      src/lib/dhcp/option.cc
  2. 7 2
      src/lib/dhcp/option.h
  3. 7 5
      src/lib/dhcp/option_string.cc

+ 2 - 9
src/lib/dhcp/option.cc

@@ -55,7 +55,7 @@ Option::Option(Universe u, uint16_t type, const OptionBuffer& data)
 
 Option::Option(Universe u, uint16_t type, OptionBufferConstIter first,
                OptionBufferConstIter last)
-    :universe_(u), type_(type), data_(OptionBuffer(first,last)) {
+    :universe_(u), type_(type), data_(first, last) {
     check();
 }
 
@@ -121,7 +121,7 @@ Option::packOptions(isc::util::OutputBuffer& buf) {
 
 void Option::unpack(OptionBufferConstIter begin,
                     OptionBufferConstIter end) {
-    data_ = OptionBuffer(begin, end);
+    setData(begin, end);
 }
 
 void
@@ -274,13 +274,6 @@ void Option::setUint32(uint32_t value) {
   writeUint32(value, &data_[0]);
 }
 
-void Option::setData(const OptionBufferConstIter first,
-                     const OptionBufferConstIter last) {
-    // We will copy entire option buffer, so we have to resize data_.
-    data_.resize(std::distance(first, last));
-    std::copy(first, last, data_.begin());
-}
-
 bool Option::equal(const OptionPtr& other) const {
     return ( (getType() == other->getType()) &&
              (getData() == other->getData()) );

+ 7 - 2
src/lib/dhcp/option.h

@@ -282,8 +282,13 @@ public:
     ///
     /// @param first iterator pointing to beginning of buffer to copy.
     /// @param last iterator pointing to end of buffer to copy.
-    void setData(const OptionBufferConstIter first,
-                 const OptionBufferConstIter last);
+    ///
+    /// @tparam InputIterator type of the iterator representing the
+    /// limits of the buffer to be assigned to a data_ buffer.
+    template<typename InputIterator>
+    void setData(InputIterator first, InputIterator last) {
+        data_.assign(first, last);
+    }
 
     /// just to force that every option has virtual dtor
     virtual ~Option();

+ 7 - 5
src/lib/dhcp/option_string.cc

@@ -36,7 +36,8 @@ OptionString::OptionString(const Option::Universe u, const uint16_t type,
 
 std::string
 OptionString::getValue() const {
-    return (std::string(data_.begin(), data_.end()));
+    const OptionBuffer& data = getData();
+    return (std::string(data.begin(), data.end()));
 }
 
 void
@@ -49,13 +50,13 @@ OptionString::setValue(const std::string& value) {
                   << getType() << "' must not be empty");
     }
 
-    data_.assign(value.begin(), value.end());
+    setData(value.begin(), value.end());
 }
 
 
 uint16_t
 OptionString::len() {
-    return (getHeaderLen() + data_.size());
+    return (getHeaderLen() + getData().size());
 }
 
 void
@@ -63,7 +64,8 @@ OptionString::pack(isc::util::OutputBuffer& buf) {
     // Pack option header.
     packHeader(buf);
     // Pack data.
-    buf.writeData(&data_[0], data_.size());
+    const OptionBuffer& data = getData();
+    buf.writeData(&data[0], data.size());
 
     // That's it. We don't pack any sub-options here, because this option
     // must not contain sub-options.
@@ -77,7 +79,7 @@ OptionString::unpack(OptionBufferConstIter begin,
                   << getType() << "' holding string value"
                   << " - empty value is not accepted");
     }
-    data_.assign(begin, end);
+    setData(begin, end);
 }
 
 } // end of isc::dhcp namespace