This template class provides an associative container keyed by IPv4 addresses, with longest-match searching. More...
#include <DwmRDAPIpv4Routes.hh>
Inherits Readable, Writable, GZReadable, GZWritable, BZ2Readable, and BZ2Writable.
Public Types | |
| typedef std::map< Ipv4Address, _valueT > | _RepSubType |
| typedef _RepSubType::const_iterator | const_iterator |
Public Member Functions | |
| Ipv4Routes () | |
| Constructor. | |
| void | Clear () |
| Clears all entries. | |
| bool | Empty () const |
| Returns true if there are no entries. | |
| bool | Add (const Ipv4Prefix &prefix, const _valueT &value) |
| Adds an entry. More... | |
| _valueT & | operator[] (const Ipv4Prefix &prefix) |
| operator [] works like you would expect from an STL map. | |
| bool | Delete (const Ipv4Prefix &prefix) |
Deletes the entry for prefix. More... | |
| bool | Find (const Ipv4Prefix &prefix, _valueT &match) const |
Find the entry for the given prefix. More... | |
| bool | FindLongest (const Ipv4Address &ipAddr, std::pair< Ipv4Prefix, _valueT > &match) const |
Finds the longest match for ipAddr. More... | |
| bool | FindLongest (const Ipv4Address &ipAddr, std::pair< Ipv4Prefix, const _valueT *> &match) const |
Finds the longest match for ipAddr. More... | |
| bool | Find (const Ipv4Address &ipAddr, std::vector< std::pair< Ipv4Prefix, _valueT > > &matches) const |
Finds all matches for ipAddr. More... | |
| bool | operator== (const Ipv4Routes< _valueT > &r) const |
| operator == It's unlikely you'd ever need to use this, and it's expensive. More... | |
| bool | operator!= (const Ipv4Routes< _valueT > &r) const |
| operator != It's unlikely you'd ever need to use this, and it's expensive. More... | |
| uint32_t | Size () const |
| Returns the number of routes. | |
| void | HashSizes (std::vector< std::pair< uint8_t, uint32_t > > &sizes) const |
| uint32_t | StreamedLength () const |
| std::istream & | Read (std::istream &is) |
| Reads the routes from an istream. Returns the istream. | |
| std::ostream & | Write (std::ostream &os) const |
| Writes the routes to an ostream. Returns the ostream. | |
| size_t | Read (FILE *f) |
| Reades the routes from a FILE pointer. More... | |
| size_t | Write (FILE *f) const |
| Writes the routes to a FILE pointer. More... | |
| ssize_t | Read (int fd) |
| Reads the routes from a file descriptor. More... | |
| ssize_t | Write (int fd) const |
| Writes the routes to a file descriptor. More... | |
| int | Read (gzFile gzf) |
| Reads the routes from a gzFile. More... | |
| int | Write (gzFile gzf) const |
| Writes the routes to a gzFile. More... | |
| int | BZRead (BZFILE *bzf) |
| Reads the routes from a BZFILE pointer. More... | |
| int | BZWrite (BZFILE *bzf) const |
| Writes the routes to a BZFILE pointer. More... | |
| void | SortByKey (std::vector< std::pair< Ipv4Prefix, _valueT >> &target, bool ascending=true) const |
| void | SortByValue (std::vector< std::pair< Ipv4Prefix, _valueT > > &target) |
| Sorts the contained pair<Ipv4Prefix,_valueT> values into a vector, in descending order by the value stored for each prefix. More... | |
| uint32_t | AddressesCovered () const |
| Returns the number of addresses covered by the contained prefixes, not including 0/0. More... | |
Protected Attributes | |
| std::vector< _RepSubType > | _maps |
| std::shared_mutex | _mtx |
This template class provides an associative container keyed by IPv4 addresses, with longest-match searching.
While this isn't as speedy to search as Patricia or radix, it is based on STL containers and is hence easy to understand and maintain (note how few lines of actual code are here).
I/O functionality is provided, but the real work there is done in the Dwm::IO class.
|
inline |
Adds an entry.
Returns false (and does nothing) if there was already an entry present for prefix.
|
inline |
Returns the number of addresses covered by the contained prefixes, not including 0/0.
|
inline |
Reads the routes from a BZFILE pointer.
Returns the number of bytes read on success, -1 on failure.
|
inline |
Writes the routes to a BZFILE pointer.
Returns the number of bytes written on success, -1 on failure.
|
inline |
Deletes the entry for prefix.
Returns true on success, false if an entry wasn't found for prefix.
|
inline |
Find the entry for the given prefix.
If an entry is found, the value is stored in match and true is returned. Else false is returned.
|
inline |
Finds all matches for ipAddr.
Places the results in matches (in longest-match-first order) and returns true if any matches were found. Returns false if no matches were found.
|
inline |
Finds the longest match for ipAddr.
Places the result in match and returns true on success. Returns false if no match was found for ipAddr.
|
inline |
Finds the longest match for ipAddr.
Places the result in match and returns true on success. Returns false if no match was found for ipAddr. Note that match.second is a pointer to const for the value stored under the prefix. That means you need to be careful using this member; don't call free() or delete() on match.second.
|
inline |
operator != It's unlikely you'd ever need to use this, and it's expensive.
It's mainly here for unit testing.
|
inline |
operator == It's unlikely you'd ever need to use this, and it's expensive.
It's mainly here for unit testing.
|
inline |
Reades the routes from a FILE pointer.
Returns 1 on success, 0 on failure.
|
inline |
Reads the routes from a file descriptor.
Returns the number of bytes read on success, -1 on failure.
|
inline |
Reads the routes from a gzFile.
Returns the number of bytes read on success, -1 on failure.
|
inline |
Sorts the contained pair<Ipv4Prefix,_valueT> values into a vector, in descending order by the value stored for each prefix.
For example, if you had an Ipv4Routes<uint32_t> object, target would contain the pair<Ipv4Prefix,_valueT> objects sorted in descending order by the uint32_t values.
|
inline |
Writes the routes to a FILE pointer.
Returns 1 on success, 0 on failure.
|
inline |
Writes the routes to a file descriptor.
Returns the number of bytes written on success, -1 on failure.
|
inline |
Writes the routes to a gzFile.
Returns the number of bytes written on success, -1 on failure.