-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbufpool.h
More file actions
46 lines (38 loc) · 1.3 KB
/
bufpool.h
File metadata and controls
46 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#if !defined(BUF_POOL_H)
#define BUF_POOL_H
#include <QMap>
#include "SysUtils.h"
#include "netaddr.h"
#include "msg.h"
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
class TBufPool
{
public:
template <typename T> void insertPool(T* pool) { mBufPool.insert(poolId<T>(), pool); /*qDebug() << "pool Id:" << poolId<T>() << "pool handle:" << pool; */ }
template <typename T> T* getPool()
{
TBufPoolMap::iterator pool = mBufPool.find(SysUtils::TTypeEnumerator<T>::classId());
if(pool != mBufPool.end()) {
return static_cast<T*>(pool.value());
} else {
return 0;
}
}
template <typename T> bool getBuf(TBaseMsgWrapperPtr& buf)
{
/*typename*/ T* pool = getPool<T>();
if(pool) {
return pool->get(buf);
} else {
return false;
}
}
~TBufPool();
void bufPoolInfo(); // for test information
private:
typedef QMap<int,TMsgWrapperPoolQueue*> TBufPoolMap;
TBufPoolMap mBufPool;
template<typename T> static int poolId() { return SysUtils::TTypeEnumerator<T>::classId(); }
};
#endif // BUF_POOL_H