Skip to content

Commit

Permalink
libdeng2|InfoBank: Keep track of source file location
Browse files Browse the repository at this point in the history
Most derived banks have use for this information.
  • Loading branch information
skyjake committed Apr 2, 2014
1 parent 7dc1a75 commit 44dae93
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions doomsday/libdeng2/include/de/data/info.h
Expand Up @@ -282,6 +282,8 @@ class DENG2_PUBLIC Info
*/
void setFinder(IIncludeFinder const &finder);

void useDefaultFinder();

/**
* Parses a string of text as Info source.
*
Expand Down
1 change: 1 addition & 0 deletions doomsday/libdeng2/include/de/data/infobank.h
Expand Up @@ -57,6 +57,7 @@ class DENG2_PUBLIC InfoBank : public Bank
void addFromInfoBlocks(String const &blockType);

Time sourceModifiedAt() const;
String relativeToPath() const;

protected:
virtual ISource *newSourceFromInfo(String const &id) = 0;
Expand Down
35 changes: 20 additions & 15 deletions doomsday/libdeng2/src/data/info.cpp
Expand Up @@ -40,17 +40,7 @@ DENG2_PIMPL(Info)
{
String findIncludedInfoSource(String const &includeName, Info const &) const
{
try
{
return String::fromUtf8(Block(App::rootFolder().locate<File const>(includeName)));
}
catch(Error const &er)
{
throw NotFoundError("Info::DefaultIncludeFinder",
QString("Cannot include '%1': %2")
.arg(includeName)
.arg(er.asText()));
}
return String::fromUtf8(Block(App::rootFolder().locate<File const>(includeName)));
}
};

Expand Down Expand Up @@ -573,12 +563,22 @@ success:;

void includeFrom(String const &includeName)
{
DENG2_ASSERT(finder != 0);
try
{
DENG2_ASSERT(finder != 0);

Info included(finder->findIncludedInfoSource(includeName, self), *finder);
Info included(finder->findIncludedInfoSource(includeName, self), *finder);

// Move the contents of the resulting root block to our root block.
included.d->rootBlock.moveContents(rootBlock);
// Move the contents of the resulting root block to our root block.
included.d->rootBlock.moveContents(rootBlock);
}
catch(Error const &er)
{
throw IIncludeFinder::NotFoundError("Info::includeFrom",
QString("Cannot include '%1': %2")
.arg(includeName)
.arg(er.asText()));
}
}

void parse(String const &source)
Expand Down Expand Up @@ -708,6 +708,11 @@ void Info::setFinder(IIncludeFinder const &finder)
d->finder = &finder;
}

void Info::useDefaultFinder()
{
d->finder = &d->defaultFinder;
}

void Info::setScriptBlocks(QStringList const &blocksToParseAsScript)
{
d->scriptBlockTypes = blocksToParseAsScript;
Expand Down
9 changes: 9 additions & 0 deletions doomsday/libdeng2/src/data/infobank.cpp
Expand Up @@ -19,13 +19,15 @@
#include "de/InfoBank"
#include "de/ScriptedInfo"
#include "de/File"
#include "de/App"

namespace de {

DENG2_PIMPL_NOREF(InfoBank)
{
ScriptedInfo info;
Time modTime;
String relativeToPath;
};

InfoBank::InfoBank(Bank::Flags const &flags, String const &hotStorageLocation)
Expand All @@ -36,6 +38,7 @@ void InfoBank::parse(String const &source)
{
try
{
d->relativeToPath = "";
d->modTime = Time();
d->info.parse(source);
}
Expand All @@ -49,6 +52,7 @@ void InfoBank::parse(File const &file)
{
try
{
d->relativeToPath = file.path().fileNamePath();
d->modTime = file.status().modifiedAt;
d->info.parse(file);
}
Expand Down Expand Up @@ -91,6 +95,11 @@ Time InfoBank::sourceModifiedAt() const
return d->modTime;
}

String InfoBank::relativeToPath() const
{
return d->relativeToPath;
}

Variable const &InfoBank::operator [] (String const &name) const
{
return d->info[name];
Expand Down

0 comments on commit 44dae93

Please sign in to comment.