From 3b4dc10211acf55318ef61ba12d2a6e3b45aa2de Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 1 Jun 2013 12:05:53 -0300 Subject: [PATCH] Added HWAddress<>::operator[]. --- include/hw_address.h | 9 +++++++++ tests/src/hwaddress.cpp | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/include/hw_address.h b/include/hw_address.h index cd99054..12a8d11 100644 --- a/include/hw_address.h +++ b/include/hw_address.h @@ -244,6 +244,15 @@ public: oss << *this; return oss.str(); } + + /** + * \brief Retrieves the i-th storage_type in this address. + * + * \param i The element to retrieve. + */ + storage_type operator[](size_t i) const { + return buffer[i]; + } /** * \brief Writes this HWAddress in hex-notation to a std::ostream. diff --git a/tests/src/hwaddress.cpp b/tests/src/hwaddress.cpp index 5b7b112..3e6f529 100644 --- a/tests/src/hwaddress.cpp +++ b/tests/src/hwaddress.cpp @@ -36,6 +36,12 @@ TEST_F(HWAddressTest, DistinctOperator) { EXPECT_NE(addr1, addr2); } +TEST_F(HWAddressTest, SubscriptOperator) { + HWAddress<6> addr("00:01:02:03:04:05"); + for(size_t i = 0; i < addr.size(); ++i) + EXPECT_EQ(addr[i], i); +} + TEST_F(HWAddressTest, LessThanOperator) { HWAddress<6> addr1(byte_address), addr2(empty_addr); HWAddress<6> bcast = "ff:ff:ff:ff:ff:ff";