Stefan Schuermans commited on 2011-12-21 22:46:46
Showing 2 changed files, with 53 additions and 11 deletions.
| ... | ... |
@@ -28,24 +28,58 @@ Udp4Addr::~Udp4Addr() |
| 28 | 28 |
{
|
| 29 | 29 |
} |
| 30 | 30 |
|
| 31 |
-/// less-than operator (to allow usage as map key) |
|
| 32 |
-bool Udp4Addr::operator<(const Udp4Addr &that) const |
|
| 31 |
+/// comparison |
|
| 32 |
+//@{
|
|
| 33 |
+ |
|
| 34 |
+int Udp4Addr::compare(const Udp4Addr &that) const |
|
| 33 | 35 |
{
|
| 34 | 36 |
if (m_addr.sin_family < that.m_addr.sin_family) |
| 35 |
- return true; |
|
| 37 |
+ return -1; |
|
| 36 | 38 |
if (m_addr.sin_family > that.m_addr.sin_family) |
| 37 |
- return false; |
|
| 39 |
+ return 1; |
|
| 38 | 40 |
if (ntohl(m_addr.sin_addr.s_addr) < ntohl(that.m_addr.sin_addr.s_addr)) |
| 39 |
- return true; |
|
| 41 |
+ return -1; |
|
| 40 | 42 |
if (ntohl(m_addr.sin_addr.s_addr) > ntohl(that.m_addr.sin_addr.s_addr)) |
| 41 |
- return false; |
|
| 43 |
+ return 1; |
|
| 42 | 44 |
if (ntohs(m_addr.sin_port) < ntohs(that.m_addr.sin_port)) |
| 43 |
- return true; |
|
| 45 |
+ return -1; |
|
| 44 | 46 |
if (ntohs(m_addr.sin_port) > ntohs(that.m_addr.sin_port)) |
| 45 |
- return false; |
|
| 46 |
- return false; |
|
| 47 |
+ return 1; |
|
| 48 |
+ return 0; |
|
| 49 |
+} |
|
| 50 |
+ |
|
| 51 |
+bool Udp4Addr::operator==(const Udp4Addr &that) const |
|
| 52 |
+{
|
|
| 53 |
+ return compare(that) == 0; |
|
| 54 |
+} |
|
| 55 |
+ |
|
| 56 |
+bool Udp4Addr::operator!=(const Udp4Addr &that) const |
|
| 57 |
+{
|
|
| 58 |
+ return compare(that) != 0; |
|
| 47 | 59 |
} |
| 48 | 60 |
|
| 61 |
+bool Udp4Addr::operator<(const Udp4Addr &that) const |
|
| 62 |
+{
|
|
| 63 |
+ return compare(that) < 0; |
|
| 64 |
+} |
|
| 65 |
+ |
|
| 66 |
+bool Udp4Addr::operator>(const Udp4Addr &that) const |
|
| 67 |
+{
|
|
| 68 |
+ return compare(that) > 0; |
|
| 69 |
+} |
|
| 70 |
+ |
|
| 71 |
+bool Udp4Addr::operator<=(const Udp4Addr &that) const |
|
| 72 |
+{
|
|
| 73 |
+ return compare(that) <= 0; |
|
| 74 |
+} |
|
| 75 |
+ |
|
| 76 |
+bool Udp4Addr::operator>=(const Udp4Addr &that) const |
|
| 77 |
+{
|
|
| 78 |
+ return compare(that) >= 0; |
|
| 79 |
+} |
|
| 80 |
+ |
|
| 81 |
+//@} |
|
| 82 |
+ |
|
| 49 | 83 |
/// return address family |
| 50 | 84 |
int Udp4Addr::getFamily() const |
| 51 | 85 |
{
|
| ... | ... |
@@ -26,8 +26,16 @@ public: |
| 26 | 26 |
virtual ~Udp4Addr(); |
| 27 | 27 |
|
| 28 | 28 |
public: |
| 29 |
- /// less-than operator (to allow usage as map key) |
|
| 30 |
- virtual bool operator<(const Udp4Addr &that) const; |
|
| 29 |
+ /// comparison |
|
| 30 |
+ //@{
|
|
| 31 |
+ int compare(const Udp4Addr &that) const; |
|
| 32 |
+ bool operator==(const Udp4Addr &that) const; |
|
| 33 |
+ bool operator!=(const Udp4Addr &that) const; |
|
| 34 |
+ bool operator<(const Udp4Addr &that) const; |
|
| 35 |
+ bool operator>(const Udp4Addr &that) const; |
|
| 36 |
+ bool operator<=(const Udp4Addr &that) const; |
|
| 37 |
+ bool operator>=(const Udp4Addr &that) const; |
|
| 38 |
+ //@} |
|
| 31 | 39 |
|
| 32 | 40 |
/// return address family |
| 33 | 41 |
virtual int getFamily() const; |
| 34 | 42 |