📄 header_buf.h
字号:
/*! \mainpage 具有头部格式的缓冲区
* \author nodman
* \date 2003-6-11
*/
#ifndef _HEADER_BUF_H
#define _HEADER_BUF_H
/// 处理具有头部格式的缓冲区
template<typename T>
class header_buf
{
T* x; ///< buffer with header and followed by data
DWORD s; ///< data size, excluding the header size
public:
header_buf():x(NULL),s(0){}
// size: pure data size, exlcuding the header size
header_buf(T* t, DWORD size):x(NULL), s(0){attach(t,size);}
void attach(T* t, DWORD size)
{
x = t;
s = size;
}
void detach()
{
x = NULL;
s = 0;
}
DWORD data_size() const {return s;}
DWORD header_size() const {return sizeof(T);}
DWORD whole_size() const {return s+header_size();}
operator T*() {return x;}
byte* data() {return ((byte*)x)+header_size();}
T* tail() {return ((byte*)x)+whole_size();}
T* operator->(){return x;}
};
#endif // _HEADER_BUF_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -