}
bool
-OpaqueDataTuple::operator==(const std::string& other) {
+OpaqueDataTuple::operator==(const std::string& other) const {
return (equals(other));
}
///
/// @param other String to compare the tuple against.
/// @return true if data carried in the tuple is equal to the string.
- bool operator==(const std::string& other);
+ bool operator==(const std::string& other) const;
/// @brief Inequality operator.
///
return (tuples_[at]);
}
+bool
+OptionVendorClass::hasTuple(const std::string& tuple_str) const {
+ // Iterate over existing tuples (there shouldn't be many of them),
+ // and try to match the searched one.
+ for (TuplesCollection::const_iterator it = tuples_.begin();
+ it != tuples_.end(); ++it) {
+ if (*it == tuple_str) {
+ return (true);
+ }
+ }
+ return (false);
+}
+
+
uint16_t
OptionVendorClass::len() {
// The option starts with the header and enterprise id.
return (tuples_);
}
+ /// @brief Checks if the Vendor Class holds the opaque data tuple with the
+ /// specified string.
+ ///
+ /// @param tuple_str String representation of the tuple being searched.
+ /// @return true if the specified tuple exists for this option.
+ bool hasTuple(const std::string& tuple_str) const;
+
/// @brief Returns the full length of the option, including option header.
virtual uint16_t len();
EXPECT_EQ("xyz", vendor_class.getTuple(0).getText());
EXPECT_EQ("abc", vendor_class.getTuple(1).getText());
+ // Check that hasTuple correctly identifies existing tuples.
+ EXPECT_TRUE(vendor_class.hasTuple("xyz"));
+ EXPECT_TRUE(vendor_class.hasTuple("abc"));
+ EXPECT_FALSE(vendor_class.hasTuple("other"));
+
// Attempt to add the tuple with 1 byte long length field should fail
// for DHCPv6 option.
OpaqueDataTuple tuple2(OpaqueDataTuple::LENGTH_1_BYTE);