Marine Library  1.0
C++ library for Linux Networking Development
Public Types | Public Member Functions | List of all members
CFdMap< T, Container > Struct Template Reference

A hash table for fd (file descriptor) related data. More...

#include <fd_data_map.hh>

Public Types

typedef Container container_type
 
typedef T value_type
 
typedef T & reference
 
typedef const T & const_reference
 

Public Member Functions

 CFdMap (size_t capacity=100)
 Initialize this object. More...
 
size_t capacity () const
 Get current capacity. More...
 
void capacity (size_t sz)
 Set current capacity. More...
 
reference operator[] (int fd)
 Get value for an fd. More...
 
const_reference operator[] (int fd) const
 Get value for an fd. More...
 
void clear ()
 Clear all key/value pairs.
 

Detailed Description

template<class T, class Container = std::vector<T>>
struct CFdMap< T, Container >

A hash table for fd (file descriptor) related data.

Key MUST be file descriptors, which are non-negative and of type int. In fact the file descriptor acts as an index to an underlying container of values. Because the number of files a process can open is limited, e.g. 1024 (it is modifiable), there's no chance for the underlying container to grow unexpectedly. So do NOT use CFdMap as a generic int to value hash table.
The underlying container is vector by default, but you can specify it as you like.

Template Parameters
TValue type
ContainerContainer type, default to std::vector<T>
Note
CFdMap is NOT thread safe.
See also
CFdDataMap

Constructor & Destructor Documentation

template<class T, class Container = std::vector<T>>
CFdMap< T, Container >::CFdMap ( size_t  capacity = 100)
inlineexplicit

Initialize this object.

capacity is used as a hint to the number of key/value pairs this object wants to hold. But CFdMap is free to expand as needed.

Parameters
capacityInitial reserved room for key/value pairs

Member Function Documentation

template<class T, class Container = std::vector<T>>
size_t CFdMap< T, Container >::capacity ( ) const
inline

Get current capacity.

Returns
Current capacity
template<class T, class Container = std::vector<T>>
void CFdMap< T, Container >::capacity ( size_t  sz)
inline

Set current capacity.

Parameters
szNew capacity
template<class T, class Container = std::vector<T>>
reference CFdMap< T, Container >::operator[] ( int  fd)
inline

Get value for an fd.

Parameters
fdA file descriptor
Returns
Writable reference to the value for fd
template<class T, class Container = std::vector<T>>
const_reference CFdMap< T, Container >::operator[] ( int  fd) const
inline

Get value for an fd.

Parameters
fdA file descriptor
Returns
Readonly reference to the value for fd

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