Example #1
0
static T	*DupSerializable(const T *in) throw(NLMISC::EStream)
{
	NLMISC::CMemStream ms;
	nlassert(!ms.isReading());
	T *nonConstIn = const_cast<T *>(in);
	TSerializePolicy::serial(nonConstIn, ms);
	std::vector<uint8> datas(ms.length());
	std::copy(ms.buffer(), ms.buffer() + ms.length(), datas.begin());
	ms.resetPtrTable();
	ms.invert();
	ms.fill(&datas[0], (uint)datas.size());
	nlassert(ms.isReading());
	T *newObj = NULL;
	TSerializePolicy::serial(newObj, ms);
	return newObj;
}
Example #2
0
CWriteFile::CWriteFile(const std::string& filename, const TRequester &requester, uint32 requestid, NLMISC::CMemStream& data)
	: IFileAccess(filename, requester, requestid)
{
	BackupFile = false;
	Append = false;
	CreateDir = true;
	FailureMode = MajorFailureMode;
	uint32 startPos = (uint32)data.getPos();
	uint32 actualLen = data.length()-startPos;
	Data.resize(actualLen);
	memcpy(&(Data[0]), data.buffer()+startPos, actualLen);
}
Example #3
0
	// ***************************************************************************
	CInterfaceElement *CInterfaceElement::clone()
	{
		NLMISC::CMemStream dupStream;
		nlassert(!dupStream.isReading());
		CInterfaceGroup *oldParent = _Parent;
		_Parent = NULL;
		CInterfaceElement *oldParentPos = _ParentPos;
		CInterfaceElement *oldParentSize = _ParentSize;
		if (_ParentPos == oldParent) _ParentPos = NULL;
		if (_ParentSize == oldParent) _ParentSize = NULL;
		CInterfaceElement *begunThisCloneWarHas = NULL;
		try
		{
			if (dupStream.isReading())
			{
				dupStream.invert();
			}
			CInterfaceElement *self = this;
			dupStream.serialPolyPtr(self);
			std::vector<uint8> datas(dupStream.length());
			std::copy(dupStream.buffer(), dupStream.buffer() + dupStream.length(), datas.begin());
			dupStream.resetPtrTable();
			dupStream.invert();
			dupStream.fill(&datas[0], (uint32)datas.size());
			dupStream.serialPolyPtr(begunThisCloneWarHas);
		}
		catch(const NLMISC::EStream &)
		{
			// no-op -> caller has to handle the failure because NULL will be returned
		}
		//
		_Parent		  = oldParent;
		_ParentPos	  = oldParentPos;
		_ParentSize	  = oldParentSize;
		//
		return begunThisCloneWarHas;
	}