Skip to content

Commit

Permalink
libdeng2: Improved Archive
Browse files Browse the repository at this point in the history
Renamed a few methods for consistency.
  • Loading branch information
skyjake committed Nov 30, 2012
1 parent 9d58314 commit a09aee7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
12 changes: 8 additions & 4 deletions doomsday/libdeng2/include/de/data/archive.h
Expand Up @@ -64,7 +64,7 @@ namespace de
* by calling @c cache(DetachFromSource). This forces all entries to be
* copied to Archive-owned memory (in original serialized form).
*
* @see ArchiveFeed, ArchiveFile
* @see ArchiveFeed, ArchiveEntryFile
*
* @ingroup data
*/
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace de
*
* @return Type, size, and other metadata about the entry.
*/
File::Status status(Path const &path) const;
File::Status entryStatus(Path const &path) const;

/**
* Returns the deserialized data of an entry for read-only access. The
Expand All @@ -176,12 +176,16 @@ namespace de
* existing serialized data of the entry can be used as-is when the
* archive is written.
*
* @param path Entry path.
* @param path Entry path. The entry must already exist in the archive.
*
* @return Immutable contents of the entry.
*/
Block const &entryBlock(Path const &path) const;

inline Block const &constEntryBlock(Path const &path) const {
return entryBlock(path);
}

/**
* Returns the deserialized data of an entry for read and write access.
* The data is deserialized and cached if a cached copy doesn't already
Expand All @@ -191,7 +195,7 @@ namespace de
* entry's data is automatically marked for re-serialization in case
* the archive is written.
*
* @param path Entry path. The entry must already exist in the archive.
* @param path Entry path. If doesn't exist, a new entry will be added.
*
* @return Modifiable contents of the entry.
*/
Expand Down
36 changes: 26 additions & 10 deletions doomsday/libdeng2/src/data/archive.cpp
Expand Up @@ -147,7 +147,7 @@ dint Archive::listFolders(Archive::Names &names, Path const &folder) const
return names.size();
}

File::Status Archive::status(Path const &path) const
File::Status Archive::entryStatus(Path const &path) const
{
DENG2_ASSERT(d->index != 0);

Expand All @@ -163,25 +163,41 @@ Block const &Archive::entryBlock(Path const &path) const
{
DENG2_ASSERT(d->index != 0);

// We'll need to modify the entry.
Entry &entry = static_cast<Entry &>(d->index->find(path, PathTree::MatchFull | PathTree::NoBranch));
if(entry.data)
try
{
// Got it.
// We'll need to modify the entry.
Entry &entry = static_cast<Entry &>(d->index->find(path, PathTree::MatchFull | PathTree::NoBranch));
if(entry.data)
{
// Got it.
return *entry.data;
}
std::auto_ptr<Block> cached(new Block);
d->readEntry(path, *cached.get());
entry.data = cached.release();
return *entry.data;
}
std::auto_ptr<Block> cached(new Block);
d->readEntry(path, *cached.get());
entry.data = cached.release();
return *entry.data;
catch(PathTree::NotFoundError const &)
{
/// @throw NotFoundError Entry with @a path was not found.
throw NotFoundError("Archive::entryBlock", String("'%1' not found").arg(path));
}
}

Block &Archive::entryBlock(Path const &path)
{
if(!hasEntry(path))
{
add(path, Block());
}

Block const &block = const_cast<Archive const *>(this)->entryBlock(path);

// Mark for recompression.
static_cast<Entry &>(d->index->find(path, PathTree::MatchFull | PathTree::NoBranch)).maybeChanged = true;
Entry &entry = static_cast<Entry &>(d->index->find(path, PathTree::MatchFull | PathTree::NoBranch));
entry.maybeChanged = true;
entry.modifiedAt = Time();

d->modified = true;

return const_cast<Block &>(block);
Expand Down

0 comments on commit a09aee7

Please sign in to comment.