ResbufPointer类
我想其他人可能会发现这很有用。这是我今天拼凑的一个快速的小智能指针类,以帮助我避免忘记释放resbuf指针:class ResbufPointer {
resbuf* pHead; // Maintain a pointer to the head of the resource chain for de-allocation
resbuf* pBuffer;
public:
ResbufPointer(resbuf* ptr) : pHead(ptr), pBuffer(ptr) {}
~ResbufPointer() {
acutRelRb(pHead); // release the buffer
pHead = pBuffer = 0;
}
resbuf* operator->() { return pBuffer; }// so you can do things like buf->resval.rstring
operator resbuf*() { return pBuffer; } // so you can pass the smart pointer to functions that expect a resbuf*
bool isNull() { return pBuffer == 0; } // null pointer check
void start() { pBuffer = pHead; } // in case you need to return to the head of the resource chain
void next() { pBuffer = pBuffer->rbnext; } // try to move the pointer to the next item in the resource chain
};
在如此琐碎的事情上将实现与接口分开似乎很傻,所以我只是把它们都放在一起。
添加了一些注释。更改了愚蠢的变量名称。
**** Hidden Message ***** 我喜欢,我想知道resbuf是否有智能指针,我想是的
谢谢Chuck
结构resbuf的类包装器的另一个示例是ArxDbgRbList(来自ObjectARX SDK中的ArxDbg示例) 谢谢亚历山大。我从没在样本中注意到这一点。
页:
[1]