Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
Use an enum class for file type (File/Folder).
  • Loading branch information
skyjake committed Oct 14, 2017
1 parent 4b01543 commit 55934a6
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions doomsday/apps/libdoomsday/src/resource/bundles.cpp
Expand Up @@ -268,8 +268,8 @@ Bundles::MatchResult Bundles::match(DataBundle const &bundle) const
// Match the file type.
String fileType = def->keyValue(QStringLiteral("fileType"));
if (fileType.isEmpty()) fileType = "file"; // prefer files by default
if ((!fileType.compareWithoutCase(QStringLiteral("file")) && source.status().type() == File::Status::FILE) ||
(!fileType.compareWithoutCase(QStringLiteral("folder")) && source.status().type() == File::Status::FOLDER))
if ((!fileType.compareWithoutCase(QStringLiteral("file")) && source.status().type() == File::Type::File) ||
(!fileType.compareWithoutCase(QStringLiteral("folder")) && source.status().type() == File::Type::Folder))
{
++score;
}
Expand Down
16 changes: 8 additions & 8 deletions doomsday/sdk/libcore/include/de/filesys/file.h
Expand Up @@ -91,6 +91,13 @@ class DENG2_PUBLIC File : public filesys::Node, public IIOStream, public IObject
};
Q_DECLARE_FLAGS(Flags, Flag)

/// Type of file.
enum class Type
{
File,
Folder
};

/**
* The file object is about to be deleted. This may be, e.g., due to pruning or
* because the parent is being deleted.
Expand All @@ -104,16 +111,9 @@ class DENG2_PUBLIC File : public filesys::Node, public IIOStream, public IObject
*/
class Status
{
public:
/// Type of file.
enum Type {
FILE = 0,
FOLDER = 1
};

public:
Status(dsize s = 0, Time const &modTime = Time::invalidTime())
: size(s), modifiedAt(modTime), _type(FILE) {}
: size(s), modifiedAt(modTime), _type(Type::File) {}

Status(Type t, dsize s = 0, Time const &modTime = Time::invalidTime())
: size(s), modifiedAt(modTime), _type(t) {}
Expand Down
2 changes: 0 additions & 2 deletions doomsday/sdk/libcore/src/concurrency/taskpool.cpp
Expand Up @@ -42,8 +42,6 @@ namespace internal

DENG2_PIMPL(TaskPool), public Lockable, public Waitable, public TaskPool::IPool
{
LoopCallback mainCall;

/// Private instance will be deleted when pool is empty.
bool deleteWhenDone = false;

Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/data/archive.cpp
Expand Up @@ -164,7 +164,7 @@ File::Status Archive::entryStatus(Path const &path) const
Entry const &found = static_cast<Entry const &>(d->index->find(path, PathTree::MatchFull));

return File::Status(
found.isLeaf()? File::Status::FILE : File::Status::FOLDER,
found.isLeaf()? File::Type::File : File::Type::Folder,
found.size,
found.modifiedAt);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/data/ziparchive.cpp
Expand Up @@ -752,7 +752,7 @@ static bool recognizeZipExtension(String const &ext)

bool ZipArchive::recognize(File const &file)
{
if (file.status().type() == File::Status::FILE)
if (file.status().type() == File::Type::File)
{
// For now, just check the name.
return recognizeZipExtension(file.extension().lower());
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/filesys/directoryfeed.cpp
Expand Up @@ -264,7 +264,7 @@ File::Status DirectoryFeed::fileStatus(NativePath const &nativePath)
}

// Get file status information.
return File::Status(info.isDir()? File::Status::FOLDER : File::Status::FILE,
return File::Status(info.isDir()? File::Type::Folder : File::Type::File,
dsize(info.size()),
info.lastModified());
}
Expand Down Expand Up @@ -300,7 +300,7 @@ File &DirectoryFeed::manuallyPopulateSingleFile(NativePath const &nativePath,
}
}

if (status.type() == File::Status::FILE)
if (status.type() == File::Type::File)
{
auto *source = new NativeFile(nativePath.fileName(), nativePath);
source->setStatus(status);
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/filesys/file.cpp
Expand Up @@ -425,7 +425,7 @@ String File::fileListAsText(QList<File const *> files)

txt += flags + QString("%1 %2 %3")
.arg(f->size(), 9)
.arg(f->status().modifiedAt.asText())
.arg(f->status().modifiedAt.asText(), 23)
.arg(f->name());

// Link target.
Expand Down
5 changes: 3 additions & 2 deletions doomsday/sdk/libcore/src/filesys/folder.cpp
Expand Up @@ -106,7 +106,7 @@ DENG2_PIMPL(Folder)

Folder::Folder(String const &name) : File(name), d(new Impl(this))
{
setStatus(Status::FOLDER);
setStatus(Type::Folder);
objectNamespace().addSuperRecord(ScriptSystem::builtInClass(QStringLiteral("Folder")));
}

Expand Down Expand Up @@ -573,7 +573,8 @@ Folder::Feeds Folder::feeds() const
String Folder::contentsAsText() const
{
QList<File const *> files;
forContents([&files] (String, File &f) {
forContents([&files] (String, File &f)
{
files << &f;
return LoopContinue;
});
Expand Down

0 comments on commit 55934a6

Please sign in to comment.