当前位置: 首页>>代码示例>>C++>>正文


C++ Parts::toBinary方法代码示例

本文整理汇总了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;
	}
//.........这里部分代码省略.........
开发者ID:Aharobot,项目名称:SIGServer,代码行数:101,代码来源:SimObjBase.cpp


注:本文中的Parts::toBinary方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。