Skip to content

Commit

Permalink
Debug|FileId: In debug builds store a copy of the path in FileId
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Oct 16, 2012
1 parent adecfec commit 1ce0581
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
22 changes: 22 additions & 0 deletions doomsday/engine/portable/include/fileid.h
Expand Up @@ -60,8 +60,14 @@ class FileId : public LogEntry::Arg::Base
{
#ifdef DENG2_QT_4_8_OR_NEWER
first.md5_.swap(second.md5_);
# ifdef DENG_DEBUG
first.path_.swap(second.path_);
# endif
#else
std::swap(first.md5_, second.md5_);
# ifdef DENG_DEBUG
std::swap(first.path_, second.path_);
# endif
#endif
}

Expand All @@ -77,6 +83,18 @@ class FileId : public LogEntry::Arg::Base
/// @return Md5hash for this FileId.
Md5Hash const& md5() const { return md5_; }

#ifdef DENG_DEBUG
/// @return Path attributed to this FileId.
String const& path() const { return path_; }

/// Set the path attributed to this FileId.
FileId& FileId::setPath(String path)
{
path_ = path;
return *this;
}
#endif

/**
* Constructs a new FileId instance by hashing the absolute @a path.
* @param path Path to be hashed.
Expand All @@ -92,6 +110,10 @@ class FileId : public LogEntry::Arg::Base

private:
Md5Hash md5_;

#ifdef DENG_DEBUG
String path_;
#endif
};

} // namespace de
Expand Down
12 changes: 11 additions & 1 deletion doomsday/engine/portable/src/fileid.cpp
Expand Up @@ -34,9 +34,15 @@
using namespace de;

FileId::FileId(Md5Hash _md5) : md5_(_md5.left(16))
#ifdef DENG_DEBUG
, path_("unknown-path")
#endif
{}

FileId::FileId(FileId const& other) : LogEntry::Arg::Base(), md5_(other.md5())
#ifdef DENG_DEBUG
, path_(other.path())
#endif
{}

FileId& FileId::operator = (FileId other)
Expand Down Expand Up @@ -73,7 +79,11 @@ String FileId::asText() const

FileId FileId::fromPath(char const* path)
{
return FileId(hash(path));
FileId fileId = FileId(hash(path));
#ifdef DENG_DEBUG
fileId.setPath(path);
#endif
return fileId;
}

FileId::Md5Hash FileId::hash(char const* path)
Expand Down
14 changes: 7 additions & 7 deletions doomsday/engine/portable/src/fs_main.cpp
Expand Up @@ -171,7 +171,7 @@ struct FS1::Instance
if(place != fileIds.end() && *place == fileId)
{
#if _DEBUG
LOG_VERBOSE("Released FileId %s - \"%s\"") << *place << F_PrettyPath(path);
LOG_VERBOSE("Released FileId %s - \"%s\"") << *place << fileId.path();
#endif
fileIds.erase(place);
return true;
Expand Down Expand Up @@ -378,7 +378,7 @@ bool FS1::checkFileId(char const* path)
if(place != d->fileIds.end() && *place == fileId) return false;

#if _DEBUG
LOG_VERBOSE("Added FileId %s - \"%s\"") << fileId << F_PrettyPath(path);
LOG_VERBOSE("Added FileId %s - \"%s\"") << fileId << fileId.path();
#endif

d->fileIds.insert(place, fileId);
Expand All @@ -402,7 +402,7 @@ static void printFileIds(FileIds const& fileIds)
uint idx = 0;
DENG2_FOR_EACH(i, fileIds, FileIds::const_iterator)
{
LOG_MSG(" %u - %s") << idx << *i;
LOG_MSG(" %u - %s : \"%s\"") << idx << *i << i->path();
++idx;
}
}
Expand All @@ -416,9 +416,9 @@ static void printFileList(FS1::FileList& list)
de::DFile* hndl = list[i];
de::AbstractFile& file = hndl->file();
FileId fileId = FileId::fromPath(Str_Text(file.path()));
LOG_MSG(" %c%d: %s - \"%s\" [handle: %p]")
LOG_MSG(" %c%d: %s - \"%s\" (handle: %p)")
<< (file.hasStartup()? '*' : ' ') << i
<< fileId << F_PrettyPath(Str_Text(file.path())) << (void*)&hndl;
<< fileId << fileId.path() << (void*)&hndl;
}
}
#endif
Expand Down Expand Up @@ -1031,7 +1031,7 @@ de::DFile* FS1::tryOpenNativeFile(char const* path, char const* mymode, size_t b
if(strchr(mymode, 'b')) strcat(mode, "b");
else if(strchr(mymode, 't')) strcat(mode, "t");

AutoStr* nativePath = Str_Set(AutoStr_NewStd(), path);
AutoStr* nativePath = AutoStr_FromTextStd(path);
F_ExpandBasePath(nativePath, nativePath);
// We must have an absolute path - prepend the CWD if necessary.
F_PrependWorkPath(nativePath, nativePath);
Expand Down Expand Up @@ -1093,7 +1093,7 @@ de::AbstractFile* FS1::tryOpenFile(char const* path, char const* mode, size_t ba
bool const reqNativeFile = !!strchr(mode, 'f');

// Make it a full path.
AutoStr* searchPath = Str_Set(AutoStr_NewStd(), path);
AutoStr* searchPath = AutoStr_FromTextStd(path);
F_FixSlashes(searchPath, searchPath);
F_ExpandBasePath(searchPath, searchPath);

Expand Down

0 comments on commit 1ce0581

Please sign in to comment.