diff options
author | Matthijs Kooijman <matthijs@stdin.nl> | 2014-01-09 19:39:07 +0100 |
---|---|---|
committer | Matthijs Kooijman <matthijs@stdin.nl> | 2014-01-15 16:20:48 +0100 |
commit | 46b0ada9a941607de0a2df80bf7f58d3a959ff57 (patch) | |
tree | 84a8d742591996b777d495966c462885f509c82f | |
parent | fbedfc4fbe05cdc01e654cc8d94accab96befeaa (diff) |
Make some operators in IPAddress const
These functions do not modify the IPAddress object, but were not marked
as const. This meant that you could not do:
void set_ip(const IPAddress& ip) {
uint32_t copy = ip;
}
Since calling operator uint32_t() on ip would discard the constness of
the reference.
-rw-r--r-- | cores/arduino/IPAddress.cpp | 2 | ||||
-rw-r--r-- | cores/arduino/IPAddress.h | 6 |
2 files changed, 4 insertions, 4 deletions
diff --git a/cores/arduino/IPAddress.cpp b/cores/arduino/IPAddress.cpp index fe3deb7..f698f2a 100644 --- a/cores/arduino/IPAddress.cpp +++ b/cores/arduino/IPAddress.cpp @@ -37,7 +37,7 @@ IPAddress& IPAddress::operator=(uint32_t address) return *this; } -bool IPAddress::operator==(const uint8_t* addr) +bool IPAddress::operator==(const uint8_t* addr) const { return memcmp(addr, _address, sizeof(_address)) == 0; } diff --git a/cores/arduino/IPAddress.h b/cores/arduino/IPAddress.h index 078ac97..ce396f1 100644 --- a/cores/arduino/IPAddress.h +++ b/cores/arduino/IPAddress.h @@ -49,9 +49,9 @@ public: // Overloaded cast operator to allow IPAddress objects to be used where a pointer // to a four-byte uint8_t array is expected - operator uint32_t() { return *((uint32_t*)_address); }; - bool operator==(const IPAddress& addr) { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; - bool operator==(const uint8_t* addr); + operator uint32_t() const { return *((uint32_t*)_address); }; + bool operator==(const IPAddress& addr) const { return (*((uint32_t*)_address)) == (*((uint32_t*)addr._address)); }; + bool operator==(const uint8_t* addr) const; // Overloaded index operator to allow getting and setting individual octets of the address uint8_t operator[](int index) const { return _address[index]; }; |