libDwmRDAP-0.1.4
Dwm::RDAP::Ipv4Routes< _valueT > Class Template Reference

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
 

Detailed Description

template<typename _valueT>
class Dwm::RDAP::Ipv4Routes< _valueT >

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.

Member Function Documentation

◆ Add()

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::Add ( const Ipv4Prefix &  prefix,
const _valueT &  value 
)
inline

Adds an entry.

Returns false (and does nothing) if there was already an entry present for prefix.

◆ AddressesCovered()

template<typename _valueT>
uint32_t Dwm::RDAP::Ipv4Routes< _valueT >::AddressesCovered ( ) const
inline

Returns the number of addresses covered by the contained prefixes, not including 0/0.

◆ BZRead()

template<typename _valueT>
int Dwm::RDAP::Ipv4Routes< _valueT >::BZRead ( BZFILE *  bzf)
inline

Reads the routes from a BZFILE pointer.

Returns the number of bytes read on success, -1 on failure.

◆ BZWrite()

template<typename _valueT>
int Dwm::RDAP::Ipv4Routes< _valueT >::BZWrite ( BZFILE *  bzf) const
inline

Writes the routes to a BZFILE pointer.

Returns the number of bytes written on success, -1 on failure.

◆ Delete()

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::Delete ( const Ipv4Prefix &  prefix)
inline

Deletes the entry for prefix.

Returns true on success, false if an entry wasn't found for prefix.

◆ Find() [1/2]

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::Find ( const Ipv4Prefix &  prefix,
_valueT &  match 
) const
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.

◆ Find() [2/2]

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::Find ( const Ipv4Address &  ipAddr,
std::vector< std::pair< Ipv4Prefix, _valueT > > &  matches 
) const
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.

◆ FindLongest() [1/2]

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::FindLongest ( const Ipv4Address &  ipAddr,
std::pair< Ipv4Prefix, _valueT > &  match 
) const
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.

◆ FindLongest() [2/2]

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::FindLongest ( const Ipv4Address &  ipAddr,
std::pair< Ipv4Prefix, const _valueT *> &  match 
) const
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.

◆ operator!=()

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::operator!= ( const Ipv4Routes< _valueT > &  r) const
inline

operator != It's unlikely you'd ever need to use this, and it's expensive.

It's mainly here for unit testing.

◆ operator==()

template<typename _valueT>
bool Dwm::RDAP::Ipv4Routes< _valueT >::operator== ( const Ipv4Routes< _valueT > &  r) const
inline

operator == It's unlikely you'd ever need to use this, and it's expensive.

It's mainly here for unit testing.

◆ Read() [1/3]

template<typename _valueT>
size_t Dwm::RDAP::Ipv4Routes< _valueT >::Read ( FILE *  f)
inline

Reades the routes from a FILE pointer.

Returns 1 on success, 0 on failure.

◆ Read() [2/3]

template<typename _valueT>
ssize_t Dwm::RDAP::Ipv4Routes< _valueT >::Read ( int  fd)
inline

Reads the routes from a file descriptor.

Returns the number of bytes read on success, -1 on failure.

◆ Read() [3/3]

template<typename _valueT>
int Dwm::RDAP::Ipv4Routes< _valueT >::Read ( gzFile  gzf)
inline

Reads the routes from a gzFile.

Returns the number of bytes read on success, -1 on failure.

◆ SortByValue()

template<typename _valueT>
void Dwm::RDAP::Ipv4Routes< _valueT >::SortByValue ( std::vector< std::pair< Ipv4Prefix, _valueT > > &  target)
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.

◆ Write() [1/3]

template<typename _valueT>
size_t Dwm::RDAP::Ipv4Routes< _valueT >::Write ( FILE *  f) const
inline

Writes the routes to a FILE pointer.

Returns 1 on success, 0 on failure.

◆ Write() [2/3]

template<typename _valueT>
ssize_t Dwm::RDAP::Ipv4Routes< _valueT >::Write ( int  fd) const
inline

Writes the routes to a file descriptor.

Returns the number of bytes written on success, -1 on failure.

◆ Write() [3/3]

template<typename _valueT>
int Dwm::RDAP::Ipv4Routes< _valueT >::Write ( gzFile  gzf) const
inline

Writes the routes to a gzFile.

Returns the number of bytes written on success, -1 on failure.


The documentation for this class was generated from the following file: