1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-24 19:21:35 +01:00

Added HWAddress<>::operator[].

This commit is contained in:
Matias Fontanini
2013-06-01 12:05:53 -03:00
parent 8c1d71c7b7
commit 3b4dc10211
2 changed files with 15 additions and 0 deletions

View File

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

View File

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