示例#1
0
bool DatabaseAdapter_DocMetaData::load( const Index& blockno, MetaDataBlock& blk)
{
	std::string blkstr;
	DatabaseKey dbkey( KeyPrefix, blockno);
	if (!m_database->readValue( dbkey.ptr(), dbkey.size(), blkstr, DatabaseOptions())) return false;
	blk.init( m_descr, blockno, blkstr.c_str(), blkstr.size());
	return true;
}
示例#2
0
bool DatabaseAdapter_DocMetaData::getBlock( const DatabaseCursorInterface::Slice& key, MetaDataBlock& blk)
{
	if (!key.defined()) return false;
	char const* ki = key.ptr()+1;
	char const* ke = ki + key.size()-1;
	Index blockno = unpackIndex( ki, ke);
	DatabaseCursorInterface::Slice blkslice = m_cursor->value();
	blk.init( m_descr, blockno, blkslice.ptr(), blkslice.size());
	return true;
}
示例#3
0
void MetaDataMap::rewriteMetaData(
		const MetaDataDescription::TranslationMap& trmap,
		const MetaDataDescription& newDescr,
		DatabaseTransactionInterface* transaction)
{
	MetaDataBlock blk;
	DatabaseAdapter_DocMetaData dbadapter( m_database, m_descr);

	for (bool more=dbadapter.loadFirst(blk); more; more=dbadapter.loadNext(blk))
	{
		std::size_t newblk_bytesize = MetaDataBlock::BlockSize * newDescr.bytesize();
		char* newblk_data = new char[ MetaDataBlock::BlockSize * newDescr.bytesize()];
		utils::ScopedArray<char> newblk_data_mem( newblk_data);

		MetaDataRecord::translateBlock(
				trmap, newDescr, newblk_data,
				*m_descr, blk.ptr(), MetaDataBlock::BlockSize);
		MetaDataBlock newblk( &newDescr, blk.blockno(), newblk_data, newblk_bytesize);
		dbadapter.store( transaction, newblk);
	}
	// Clear maps:
	clear();
}
示例#4
0
void MetaDataMap::getWriteBatch( DatabaseTransactionInterface* transaction, std::vector<Index>& cacheRefreshList)
{
	Map::const_iterator mi = m_map.begin(), me = m_map.end();
	Index blockno = 0;
	MetaDataBlock blk;
	DatabaseAdapter_DocMetaData dbadapter( m_database, m_descr);
	for (; mi != me; ++mi)
	{
		Index docno = mi->first.first;
		Index elemhandle = mi->first.second;

		Index bn = MetaDataBlock::blockno( docno);
		if (bn != blockno)
		{
			if (!blk.empty())
			{
				dbadapter.store( transaction, blk);
			}
			if (dbadapter.load( bn, blk))
			{
				cacheRefreshList.push_back( bn);
			}
			else
			{
				blk.init( m_descr, bn);
			}
			blockno = bn;
		}
		const MetaDataElement* elem = m_descr->get( elemhandle);
		MetaDataRecord record = blk[ MetaDataBlock::index( docno)];
		record.setValue( elem, mi->second);
	}
	if (!blk.empty())
	{
		dbadapter.store( transaction, blk);
	}
}
示例#5
0
/*!***************************************************************************
@Function		ReadMetaBlock
@Input			pDataCursor
@Return			bool	true if successful.
@Description	Reads a single meta data block from the data file.
*****************************************************************************/
bool CPVRTPrint3D::ReadMetaBlock(const PVRTuint8** pDataCursor)
{
	SPVRTPrint3DHeader* header;

	unsigned int uiDataSize;

	MetaDataBlock block;
	if(!block.ReadFromPtr(pDataCursor))
	{
		return false;		// Must have been an error.
	}

	switch(block.u32Key)
	{
	case PVRFONT_HEADER:
		header = (SPVRTPrint3DHeader*)block.Data;
		if(header->uVersion != PVRTPRINT3D_VERSION)
		{
			return false;
		}
		// Copy options
		m_uiAscent			= header->wAscent;
		m_uiNextLineH		= header->wLineSpace;
		m_uiSpaceWidth		= header->uSpaceWidth;
		m_uiNumCharacters	= header->wNumCharacters & 0xFFFF;
		m_uiNumKerningPairs = header->wNumKerningPairs & 0xFFFF;	
		break;
	case PVRFONT_CHARLIST:
		uiDataSize = sizeof(PVRTuint32) * m_uiNumCharacters;
		_ASSERT(block.u32DataSize == uiDataSize);
		m_pszCharacterList = new PVRTuint32[m_uiNumCharacters];
		memcpy(m_pszCharacterList, block.Data, uiDataSize);
		break;
	case PVRFONT_YOFFSET:
		uiDataSize = sizeof(PVRTint32) * m_uiNumCharacters;
		_ASSERT(block.u32DataSize == uiDataSize);
		m_pYOffsets	= new PVRTint32[m_uiNumCharacters];
		memcpy(m_pYOffsets, block.Data, uiDataSize);
		break;
	case PVRFONT_METRICS:
		uiDataSize = sizeof(CharMetrics) * m_uiNumCharacters;
		_ASSERT(block.u32DataSize == uiDataSize);
		m_pCharMatrics = new CharMetrics[m_uiNumCharacters];
		memcpy(m_pCharMatrics, block.Data, uiDataSize);
		break;
	case PVRFONT_KERNING:
		uiDataSize = sizeof(KerningPair) * m_uiNumKerningPairs;
		_ASSERT(block.u32DataSize == uiDataSize);
		m_pKerningPairs = new KerningPair[m_uiNumKerningPairs];
		memcpy(m_pKerningPairs, block.Data, uiDataSize);
		break;
	case PVRFONT_RECTS:
		uiDataSize = sizeof(Rectanglei) * m_uiNumCharacters;
		_ASSERT(block.u32DataSize == uiDataSize);

		m_pRects = new Rectanglei[m_uiNumCharacters];
		memcpy(m_pRects, block.Data, uiDataSize);
		break;
	default:
		_ASSERT(!"Unhandled key!");
	}

	return true;
}
示例#6
0
void DatabaseAdapter_DocMetaData::store( DatabaseTransactionInterface* transaction, const MetaDataBlock& blk)
{
	DatabaseKey dbkey( KeyPrefix, blk.blockno());
	transaction->write( dbkey.ptr(), dbkey.size(), blk.charptr(), blk.bytesize());
}