25 #ifndef DOZERG_FD_DATA_MAP_H_20130228 26 #define DOZERG_FD_DATA_MAP_H_20130228 31 #include "shared_ptr.hh" 47 template<
class T,
class Container = std::vector<T> >
50 typedef Container container_type;
52 typedef T & reference;
53 typedef const T & const_reference;
65 size_t capacity()
const{
return map_.capacity();}
78 if(
size_t(fd) >= map_.size())
89 static const value_type kDef = value_type();
90 if(fd >= 0 &&
size_t(fd) < map_.size())
120 template<
class T,
class LockT = CSpinLock>
124 typedef T value_type;
128 typedef LockT lock_type;
145 size_t size()
const{
return sz_;}
152 return map_.capacity();
168 void setData(
int fd,
const pointer & data, pointer * old = NULL){
172 setAux(fd, data, old);
191 if(NULL == data || fd < 0)
214 template<
class ForwardIter,
class OutputIter>
215 void getData(ForwardIter first, ForwardIter last, OutputIter dstFirst)
const{
217 for(
int fd = -1;first != last;++first, ++dstFirst){
220 *dstFirst = map_[fd];
233 setAux(fd, pointer(), old);
240 template<
class ForwardIter>
243 for(
int fd = -1;first != last;++first){
246 setAux(fd, pointer(), NULL);
256 template<
class ForwardIter,
class OutputIter>
257 void clearData(ForwardIter first, ForwardIter last, OutputIter dstFirst){
259 for(
int fd = -1;first != last;++first, ++dstFirst){
262 setAux(fd, pointer(), &*dstFirst);
276 void setAux(
int fd,
const pointer & data, pointer * old){
278 if(fd <
int(map_.capacity())){
279 pointer & cur = map_[fd];
280 sz_ += (data ? 1 : 0) - (cur ? 1 : 0);
void getData(ForwardIter first, ForwardIter last, OutputIter dstFirst) const
Get values for some file descriptors.
Definition: fd_data_map.hh:215
void capacity(size_t sz)
Set current capacity.
Definition: fd_data_map.hh:70
size_t capacity() const
Get current capacity.
Definition: fd_data_map.hh:150
CFdMap(size_t capacity=100)
Initialize this object.
Definition: fd_data_map.hh:60
void clear()
Clear all key/value pairs.
Definition: fd_data_map.hh:97
void clearData(int fd, pointer *old=NULL)
Remove value for an fd.
Definition: fd_data_map.hh:229
pointer getData(int fd) const
Get value for an fd.
Definition: fd_data_map.hh:179
void clearData(ForwardIter first, ForwardIter last, OutputIter dstFirst)
Remove values for some file descriptors.
Definition: fd_data_map.hh:257
Thread-safe hash table for fd (file descriptor) related data.
Definition: fd_data_map.hh:121
void setData(int fd, const pointer &data, pointer *old=NULL)
Set value for an fd.
Definition: fd_data_map.hh:168
CFdDataMap(size_t capacity=100)
Initialize this object.
Definition: fd_data_map.hh:137
void clearData(ForwardIter first, ForwardIter last)
Remove values for some file descriptors.
Definition: fd_data_map.hh:241
Definition: shared_ptr.hh:24
void getData(int fd, pointer *data) const
Get value for an fd.
Definition: fd_data_map.hh:190
size_t size() const
Get number of key/value pairs.
Definition: fd_data_map.hh:145
A hash table for fd (file descriptor) related data.
Definition: fd_data_map.hh:48
void clear()
Clear all key/value pairs.
Definition: fd_data_map.hh:268
void capacity(size_t c)
Set current capacity.
Definition: fd_data_map.hh:158
reference operator[](int fd)
Get value for an fd.
Definition: fd_data_map.hh:76
size_t capacity() const
Get current capacity.
Definition: fd_data_map.hh:65