本文整理汇总了C++中Parts::toBinary方法的典型用法代码示例。如果您正苦于以下问题:C++ Parts::toBinary方法的具体用法?C++ Parts::toBinary怎么用?C++ Parts::toBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parts
的用法示例。
在下文中一共展示了Parts::toBinary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sizeof
/**
* @brief Binalize of the entity
* @param Size of binalized data
* @return Binalized data
*/
char *SimObjBase::toBinary(int &n)
{
const int RESIZE = 1000;
static int bufsize = RESIZE;
static char *buf = new char[bufsize];
char *p = buf;
p += sizeof(DataLengthType); // skip datalen
BINARY_SET_DATA_L_INCR(p, Id, id());
BINARY_SET_STRING_INCR(p, name());
BINARY_SET_STRING_INCR(p, classname());
short attached = isAttached();
BINARY_SET_DATA_S_INCR(p, short, attached);
BINARY_SET_DATA_L_INCR(p, Operation, m_ops);
DataOffsetType ao_offset = p - buf;
BINARY_SET_DATA_S_INCR(p, DataOffsetType, 0); // skip attr offset
DataOffsetType bo_offset = p - buf;
BINARY_SET_DATA_S_INCR(p, DataOffsetType, 0); // skip body offset
// attrs
{
DataOffsetType attrs_offset = p - buf;
BINARY_SET_DATA_S(buf + ao_offset, DataOffsetType, attrs_offset);
BINARY_SET_DATA_S_INCR(p, DataLengthType, 0); // skip attrs size
DataLengthType attrssize = sizeof(DataLengthType);
for (AttrM::iterator i=m_attrs.begin(); i!=m_attrs.end(); i++) {
int head = p - buf;
Attribute *attr = i->second;
int nn;
char *pp = attr->toBinary(nn);
if (head + nn >= bufsize) {
int newsize = bufsize + RESIZE;
char *newbuf = new char[newsize];
memcpy(newbuf, buf, head);
delete buf;
buf = newbuf;
bufsize = newsize;
p = buf + head;
}
memcpy(p, pp, nn);
p += nn;
attrssize += nn;
}
BINARY_SET_DATA_S(buf + attrs_offset, DataLengthType, attrssize);
}
// set body offset value
{
DataOffsetType body_offset = p - buf;
BINARY_SET_DATA_S(buf + bo_offset, DataOffsetType, body_offset);
// body
BINARY_SET_DATA_S_INCR(p, DataLengthType, 0); // skip body size
DataLengthType bodysize = sizeof(DataLengthType);
//for (PartsM::iterator i=m_parts.begin(); i!=m_parts.end(); i++) {
PartsIterator *itr = getPartsIterator();
Parts *parts = NULL;
while (itr && (parts = itr->next()) != NULL) {
if (parts->isBlind()) { continue; }
int head = p - buf;
//Parts *parts = i->second;
// added by sekikawa (2007/12/4)
#ifdef TAKU_TEST
parts->calcAbsPos(this);
#endif
int nn;
char *pp = parts->toBinary(nn);
if (head + nn >= bufsize) {
int newsize = bufsize + RESIZE;
char *newbuf = new char[newsize];
memcpy(newbuf, buf, head);
delete buf;
buf = newbuf;
bufsize = newsize;
p = buf + head;
}
memcpy(p, pp, nn);
p += nn;
bodysize += nn;
}
BINARY_SET_DATA_S(buf + body_offset, DataLengthType, bodysize);
delete itr;
}
//.........这里部分代码省略.........