// the persistent map is used to manage a handful of key-value string pairs // this implementation replaces a rather heavy-weight berkeleydb integration
// the file backing up a persistent map consists of line pairs with // - a key string (encoded with chars 0x00..0x0F being escaped) // - a value string (encoded with chars 0x00..0x0F being escaped)
// write key value pairs for (autoconst& entry : m_entries)
{ // write line for key const OString aKeyString = encodeString( entry.first); const sal_Int32 nKeyLen = aKeyString.getLength();
m_MapFile.write( aKeyString.getStr(), nKeyLen, nBytesWritten);
OSL_ASSERT( o3tl::make_unsigned(nKeyLen) == nBytesWritten);
m_MapFile.write( "\n", 1, nBytesWritten); // write line for value const OString aValString = encodeString( entry.second); const sal_Int32 nValLen = aValString.getLength();
m_MapFile.write( aValString.getStr(), nValLen, nBytesWritten);
OSL_ASSERT( o3tl::make_unsigned(nValLen) == nBytesWritten);
m_MapFile.write( "\n", 1, nBytesWritten);
}
// write a file delimiter (an empty key-string)
m_MapFile.write( "\n", 1, nBytesWritten); // truncate file here
sal_uInt64 nNewFileSize; if( m_MapFile.getPos( nNewFileSize) == osl::File::E_None)
m_MapFile.setSize( nNewFileSize); // flush to disk
m_MapFile.sync(); // the in-memory map now matches to the file on disk
m_bIsDirty = false;
}
void PersistentMap::add( OString const & key, OString const & value )
{ auto r = m_entries.emplace(key,value);
m_bIsDirty = r.second;
}
void PersistentMap::put( OString const & key, OString const & value )
{
add( key, value); // HACK: flush now as the extension manager does not seem // to properly destruct this object in some situations if(m_bIsDirty)
flush();
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.