Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
cbc469bf
Commit
cbc469bf
authored
Jan 26, 2013
by
Davis King
Browse files
Added comparison operators for network_address.
parent
596201e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
dlib/sockets/sockets_extensions.h
dlib/sockets/sockets_extensions.h
+29
-0
dlib/sockets/sockets_extensions_abstract.h
dlib/sockets/sockets_extensions_abstract.h
+43
-0
No files found.
dlib/sockets/sockets_extensions.h
View file @
cbc469bf
...
...
@@ -46,6 +46,35 @@ namespace dlib
unsigned
short
port
;
};
// ----------------------------------------------------------------------------------------
inline
bool
operator
<
(
const
network_address
&
a
,
const
network_address
&
b
)
{
if
(
a
.
host_address
<
b
.
host_address
)
return
true
;
else
if
(
a
.
host_address
>
b
.
host_address
)
return
false
;
else
if
(
a
.
port
<
b
.
port
)
return
true
;
else
return
false
;
}
inline
bool
operator
==
(
const
network_address
&
a
,
const
network_address
&
b
)
{
return
a
.
host_address
==
b
.
host_address
&&
a
.
port
==
b
.
port
;
}
inline
bool
operator
!=
(
const
network_address
&
a
,
const
network_address
&
b
)
{
return
!
(
a
==
b
);
}
// ----------------------------------------------------------------------------------------
void
serialize
(
const
network_address
&
item
,
std
::
ostream
&
out
...
...
dlib/sockets/sockets_extensions_abstract.h
View file @
cbc469bf
...
...
@@ -86,6 +86,49 @@ namespace dlib
unsigned
short
port
;
};
// ----------------------------------------------------------------------------------------
inline
bool
operator
<
(
const
network_address
&
a
,
const
network_address
&
b
);
/*!
ensures
- provides a total ordering over network_address objects so you can use them in
the standard associative containers. The ordering is defined such that if
you sorted network addresses they would sort first on the host_address string
and then, for network_address objects with equal host_address, they would
sort on the port number
!*/
inline
bool
operator
==
(
const
network_address
&
a
,
const
network_address
&
b
);
/*!
ensures
- returns true if a and b contain exactly the same address and false otherwise.
That is, the following must be true for this function to return true:
- a.host_address == b.host_address
- a.port == b.port
Note that this means that two addresses which are logically equivalent but
written differently will not compare equal. For example, suppose example.com
has the IP address 10.1.1.1. Then network_address("10.1.1.1:80") and
network_address("example.com:80") really refer to the same network resource
but will nevertheless not compare equal since.
!*/
inline
bool
operator
!=
(
const
network_address
&
a
,
const
network_address
&
b
);
/*!
ensures
- returns !(a == b)
!*/
// ----------------------------------------------------------------------------------------
void
serialize
(
const
network_address
&
item
,
std
::
ostream
&
out
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment