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


C++ CDatabase::Serialize方法代码示例

本文整理汇总了C++中CDatabase::Serialize方法的典型用法代码示例。如果您正苦于以下问题:C++ CDatabase::Serialize方法的具体用法?C++ CDatabase::Serialize怎么用?C++ CDatabase::Serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CDatabase的用法示例。


在下文中一共展示了CDatabase::Serialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: OnCreateGlobalDBObject

DWORD CDatabaseManager::OnCreateGlobalDBObject(DWORD size, void *params)
{
	DBCREATEPARAMS *db;
	CHashString memType(_T("Memory"));
	IArchive *MemArchive;
	StdString str;
	TCHAR strNum[50];
	int memsize;
	VERIFY_MESSAGE_SIZE(size, sizeof(DBCREATEPARAMS));

	db = (DBCREATEPARAMS*)params;

	// begin name
	str = _T("GlobalDatabase");

	// append number to each name
	_ltot(m_iGlobalCount, strNum, 10);
	str = str + strNum;
	
	// increment global count
	++m_iGlobalCount;

	// get name, parent and type
	CHashString name(str.c_str());
	static CHashString typeName(_T("CDatabase"));
	
	// create object
	CDatabase *pDatabase = dynamic_cast<CDatabase *>(
		m_ToolBox->CreateComponent(&typeName, 3, &name, NULL, false));

	// add object to object factory by hand since we need a pointer to the database object
	OFACTORYADDPARAMS aotf;
	aotf.component = pDatabase;
	aotf.name = &name;
	static DWORD msgHash_AddObjectToFactory = CHashString(_T("AddObjectToFactory")).GetUniqueID();
	m_ToolBox->SendMessage(msgHash_AddObjectToFactory, sizeof(aotf), &aotf );

	// get size of name
	memsize = _tcslen(db->fileName)+1;

	// create memory chunk
	char* memBuffer = new char[memsize];

	// create archive
	CREATEARCHIVE ca;
	ca.mode =  STREAM_MODE_READ | STREAM_MODE_WRITE;
	ca.streamData = memBuffer;
	ca.streamSize = memsize;
	ca.streamType = &memType;
	static DWORD msgHash_CreateArchive = CHashString(_T("CreateArchive")).GetUniqueID();
	if (m_ToolBox->SendMessage(msgHash_CreateArchive, sizeof(CREATEARCHIVE), &ca) != MSG_HANDLED)
	{
		StdString error;
		error = _T(__FILE__ " OnCreateGlobalDBObject(): cannot create archive\n");
		EngineGetToolBox()->Log( LOGWARNING, error );
		if( memBuffer != NULL )
		{
			delete [] memBuffer;
		}
		memBuffer = NULL;
		return MSG_ERROR;
	}

	// write name to archive 
	MemArchive = ca.archive;
	MemArchive->Write(db->fileName);

	// serialize database object
	pDatabase->Serialize(*MemArchive);
	// init database object
	pDatabase->Init();

	// close the archive
	MemArchive->Close();
	// clean up
	if( memBuffer != NULL )
	{
		delete [] memBuffer;
	}
	memBuffer = NULL;
	
	*static_cast<IDatabase**>(db->dbObj) = pDatabase;

	return MSG_HANDLED_STOP;
}
开发者ID:klhurley,项目名称:ElementalEngine2,代码行数:85,代码来源:DatabaseManager.cpp


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