用vector封装resbuf - 精华帖集合
www.dimcax.com
用vector封装resbuf
用std::vector对resbuf结构进行封装,使用完后会释放resbuf所用内存,无需手动释放,所以也不能用于即将保存的resbuf
头文件
//将resbuf指针矢量化表示,使用完后对源resbuf进行类似 acutrelrb 操作
class xresbuf{
public:
std::vector<short> type;
std::vector<ads_u_val> val;
xresbuf();
xresbuf(struct resbuf* prb);
~xresbuf();
//由源 resbuf 设置成员
//返回值: 结果的 xdata 数,失败则返回 -1
long assign(struct resbuf* prb);
//释放内存,清空 vector
void clear();
//返回 xdata 数目
///返回值: 结果的 xdata 数,失败则返回 -1
long size();
};
复制代码
cpp文件
//xresbuf成员函数
xresbuf::xresbuf() {}
xresbuf::xresbuf(struct resbuf* prb) {
assign(prb);
}
xresbuf::~xresbuf() {
clear();
}
//由源 resbuf 设置成员
//返回值: 结果的 xdata 数,失败则返回 -1
long xresbuf::assign(struct resbuf* prb) {
if (prb == null) return -1;
clear();
struct resbuf* ptmp;
for (ptmp = prb; ptmp != null; ) {
type.push_back(ptmp->restype);
val.push_back(ptmp->resval);
prb = ptmp;
ptmp = ptmp->rbnext;
delete prb;
}
return size();
}
//释放内存,清空 vector
void xresbuf::clear() {
long i, n;
n = size();
for (i = 0; i < n; i++) {
if ((type[i] > 999) && (type[i] < 1010)) delete val[i].rstring;
}
type.clear();
val.clear();
}
//返回 xdata 数目
///返回值: 结果的 xdata 数,失败则返回 -1
long xresbuf::size() {
long m, n;
m = (long)(type.size());
n = (long)(val.size());
if (m == n) return m;
else return -1;
}
//xresbuf成员函数结束
复制代码
评分次数
好帖 威望 + 2
好帖
c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。
顶
顶