Skip to content

Commit

Permalink
Cleanup|libdoomsday|FS1: Minor formatting/style cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Jun 18, 2014
1 parent 350da97 commit 3af44a9
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 98 deletions.
30 changes: 0 additions & 30 deletions doomsday/libdoomsday/include/doomsday/filesys/sys_direc.h
Expand Up @@ -67,23 +67,11 @@ LIBDOOMSDAY_PUBLIC directory_t* Dir_FromText(const char* path);

LIBDOOMSDAY_PUBLIC void Dir_Delete(directory_t* dir);

/**
* @return @c true if the directories @a a and @a b are considered equal
* (i.e., their paths match exactly).
*/
LIBDOOMSDAY_PUBLIC dd_bool Dir_IsEqual(directory_t* dir, directory_t* other);

/**
* @return "Raw" version of the present path.
*/
LIBDOOMSDAY_PUBLIC const char* Dir_Path(directory_t* dir);

/**
* Change the path to that specified in @a path.
* \note Path directives (such as '}' and '~' on Unix) are automatically expanded.
*/
LIBDOOMSDAY_PUBLIC void Dir_SetPath(directory_t* dir, const char* path);

/// Class-Static Members:

/**
Expand All @@ -100,24 +88,6 @@ LIBDOOMSDAY_PUBLIC void Dir_CleanPathStr(ddstring_t* str);
*/
LIBDOOMSDAY_PUBLIC char* Dir_CurrentPath(void);

/**
* Extract just the file name including any extension from @a path.
*/
LIBDOOMSDAY_PUBLIC void Dir_FileName(char* name, const char* path, size_t len);

/**
* Convert directory separators in @a path to their system-specifc form.
*/
LIBDOOMSDAY_PUBLIC void Dir_ToNativeSeparators(char* path, size_t len);

/**
* Convert directory separators in @a path to our internal '/' form.
*/
LIBDOOMSDAY_PUBLIC void Dir_FixSeparators(char* path, size_t len);

/// @return @c true if @a path is absolute.
LIBDOOMSDAY_PUBLIC int Dir_IsAbsolutePath(const char* path);

/**
* Convert a path into an absolute path. If @a path is relative it is considered
* relative to the current working directory. On Unix '~' expansion is applied.
Expand Down
40 changes: 22 additions & 18 deletions doomsday/libdoomsday/src/filesys/file.cpp
Expand Up @@ -28,9 +28,13 @@

namespace de {

File1::File1(FileHandle& hndl, String _path, FileInfo const& _info, File1* _container)
: handle_(&hndl), info_(_info), container_(_container),
flags(DefaultFlags), path_(_path), name_(_path.fileName())
File1::File1(FileHandle &hndl, String _path, FileInfo const &_info, File1 *_container)
: handle_(&hndl)
, info_(_info)
, container_(_container)
, flags(DefaultFlags)
, path_(_path)
, name_(_path.fileName())
{
// Used to favor newer files when duplicates are pruned.
/// @todo Does not belong at this level. Load order should be determined
Expand All @@ -45,7 +49,7 @@ File1::~File1()
if(handle_) delete handle_;
}

FileInfo const& File1::info() const
FileInfo const &File1::info() const
{
return info_;
}
Expand All @@ -55,20 +59,20 @@ bool File1::isContained() const
return !!container_;
}

File1& File1::container() const
File1 &File1::container() const
{
if(!container_) throw NotContainedError("File1::container", "File \"" + NativePath(composePath()).pretty() + " is not contained");
return *container_;
}

FileHandle& File1::handle()
FileHandle &File1::handle()
{
return *handle_;
}

de::Uri File1::composeUri(QChar delimiter) const
Uri File1::composeUri(QChar delimiter) const
{
return de::Uri(path_, RC_NULL, delimiter);
return Uri(path_, RC_NULL, delimiter);
}

uint File1::loadOrderIndex() const
Expand All @@ -81,7 +85,7 @@ bool File1::hasStartup() const
return flags.testFlag(Startup);
}

File1& File1::setStartup(bool yes)
File1 &File1::setStartup(bool yes)
{
if(yes) flags |= Startup;
else flags &= ~Startup;
Expand All @@ -93,47 +97,47 @@ bool File1::hasCustom() const
return flags.testFlag(Custom);
}

File1& File1::setCustom(bool yes)
File1 &File1::setCustom(bool yes)
{
if(yes) flags |= Custom;
else flags &= ~Custom;
return *this;
}

String const& File1::name() const
String const &File1::name() const
{
return name_;
}

size_t File1::read(uint8_t* /*buffer*/, bool /*tryCache*/)
{
/// @todo writeme
throw de::Error("File1::read", "Not yet implemented");
throw Error("File1::read", "Not yet implemented");
}

size_t File1::read(uint8_t* /*buffer*/, size_t /*startOffset*/, size_t /*length*/,
bool /*tryCache*/)
{
/// @todo writeme
throw de::Error("File1::read", "Not yet implemented");
throw Error("File1::read", "Not yet implemented");
}

uint8_t const* File1::cache()
uint8_t const *File1::cache()
{
/// @todo writeme
throw de::Error("File1::cache", "Not yet implemented");
throw Error("File1::cache", "Not yet implemented");
}

File1& File1::unlock()
{
/// @todo writeme
throw de::Error("File1::unlock", "Not yet implemented");
throw Error("File1::unlock", "Not yet implemented");
}

File1& File1::clearCache(bool* /*retCleared*/)
File1 &File1::clearCache(bool* /*retCleared*/)
{
/// @todo writeme
throw de::Error("File1::clearCache", "Not yet implemented");
throw Error("File1::clearCache", "Not yet implemented");
}

} // namespace de
10 changes: 6 additions & 4 deletions doomsday/libdoomsday/src/filesys/filehandle.cpp
Expand Up @@ -44,9 +44,9 @@ struct FileHandle::Instance
void *list;

struct dfile_flags_s {
uint open:1; /// Presently open.
uint eof:1; /// Reader has reached the end of the stream.
uint reference:1; /// This handle is a reference to another dfile instance.
uint open:1; ///< Presently open.
uint eof:1; ///< Reader has reached the end of the stream.
uint reference:1; ///< This handle is a reference to another dfile instance.
} flags;

/// Offset from start of owning package.
Expand Down Expand Up @@ -82,7 +82,7 @@ FileHandle *FileHandleBuilder::fromLump(File1 &lump, bool dontBuffer)
if(!dontBuffer)
{
hndl->d->size = lump.size();
hndl->d->pos = hndl->d->data = (uint8_t*) M_Malloc(hndl->d->size);
hndl->d->pos = hndl->d->data = (uint8_t *) M_Malloc(hndl->d->size);

LOGDEV_RES_XVERBOSE_DEBUGONLY("[%p] Buffering \"%s:%s\"...", dintptr(hndl)
<< NativePath(lump.container().composePath()).pretty()
Expand Down Expand Up @@ -280,7 +280,9 @@ size_t FileHandle::tell()
else
{
if(d->hndl)
{
return (size_t) ftell(d->hndl);
}
return d->pos - d->data;
}
}
Expand Down
19 changes: 11 additions & 8 deletions doomsday/libdoomsday/src/filesys/fileid.cpp
Expand Up @@ -33,35 +33,38 @@

using namespace de;

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

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

FileId& FileId::operator = (FileId other)
FileId &FileId::operator = (FileId other)
{
swap(*this, other);
return *this;
}

bool FileId::operator < (FileId const& other) const
bool FileId::operator < (FileId const &other) const
{
return md5_ < other.md5_;
}

bool FileId::operator == (FileId const& other) const
bool FileId::operator == (FileId const &other) const
{
return md5_ == other.md5_;
}

bool FileId::operator != (FileId const& other) const
bool FileId::operator != (FileId const &other) const
{
return md5_ != other.md5_;
}
Expand Down
30 changes: 15 additions & 15 deletions doomsday/libdoomsday/src/filesys/fs_main.cpp
Expand Up @@ -52,7 +52,7 @@ D_CMD(DumpLump);
D_CMD(ListFiles);
D_CMD(ListLumps);

static FS1* fileSystem;
static FS1 *fileSystem;

typedef QList<FileId> FileIds;

Expand All @@ -77,7 +77,7 @@ typedef QList<LumpMapping> LumpMappings;
typedef QPair<QString, QString> PathMapping;
typedef QList<PathMapping> PathMappings;

static bool applyPathMapping(ddstring_t* path, PathMapping const& vdm);
static bool applyPathMapping(ddstring_t *path, PathMapping const &vdm);

/**
* Performs a case-insensitive pattern match. The pattern can contain
Expand Down Expand Up @@ -190,7 +190,7 @@ DENG2_PIMPL(FS1)
return false;
}

void clearLoadedFiles(de::LumpIndex *index = 0)
void clearLoadedFiles(LumpIndex *index = 0)
{
loadedFilesCRC = 0;

Expand Down Expand Up @@ -223,7 +223,7 @@ DENG2_PIMPL(FS1)
// Within a subspace scheme?
try
{
FS1::Scheme &scheme = self.scheme(search.scheme());
Scheme &scheme = self.scheme(search.scheme());
LOG_RES_XVERBOSE("Using scheme '%s'...") << scheme.name();

// Ensure the scheme's index is up to date.
Expand All @@ -233,11 +233,11 @@ DENG2_PIMPL(FS1)
String name = search.path().lastSegment().toString().fileNameWithoutExtension();

// Perform the search.
FS1::Scheme::FoundNodes foundNodes;
Scheme::FoundNodes foundNodes;
if(scheme.findAll(name, foundNodes))
{
// At least one node name was matched (perhaps partially).
DENG2_FOR_EACH_CONST(FS1::Scheme::FoundNodes, i, foundNodes)
DENG2_FOR_EACH_CONST(Scheme::FoundNodes, i, foundNodes)
{
PathTree::Node &node = **i;
if(!node.comparePath(search.path(), PathTree::NoBranch))
Expand All @@ -251,7 +251,7 @@ DENG2_PIMPL(FS1)
/// @todo Should return not-found here but some searches are still dependent
/// on falling back to a wider search. -ds
}
catch(FS1::UnknownSchemeError const &)
catch(UnknownSchemeError const &)
{} // Ignore this error.

// Try a wider search of the whole virtual file system.
Expand Down Expand Up @@ -1136,7 +1136,7 @@ bool FS1::knownScheme(String name)
return false;
}

FS1::Scheme& FS1::scheme(String name)
FS1::Scheme &FS1::scheme(String name)
{
if(!name.isEmpty())
{
Expand All @@ -1147,15 +1147,15 @@ FS1::Scheme& FS1::scheme(String name)
throw UnknownSchemeError("FS1::scheme", "No scheme found matching '" + name + "'");
}

FS1::Schemes const& FS1::allSchemes()
FS1::Schemes const &FS1::allSchemes()
{
return d->schemes;
}

/// Print contents of directories as Doomsday sees them.
D_CMD(Dir)
{
DENG_UNUSED(src);
DENG2_UNUSED(src);
if(argc > 1)
{
for(int i = 1; i < argc; ++i)
Expand Down Expand Up @@ -1250,7 +1250,7 @@ D_CMD(ListFiles)
}

LOG_RES_MSG(" %s " _E(2)_E(>) "(%i %s%s)%s")
<< de::NativePath(file.composePath()).pretty()
<< NativePath(file.composePath()).pretty()
<< fileCount << (fileCount != 1 ? "files" : "file")
<< (file.hasStartup()? ", startup" : "")
<< (crc? QString(" [%1]").arg(crc, 0, 16) : "");
Expand Down Expand Up @@ -1278,13 +1278,13 @@ String App_BasePath()
return App::app().nativeBasePath().withSeparators('/'); // + '/';
}

void F_Init(void)
void F_Init()
{
DENG_ASSERT(!fileSystem);
fileSystem = new de::FS1();
DENG2_ASSERT(!fileSystem);
fileSystem = new FS1();
}

void F_Shutdown(void)
void F_Shutdown()
{
if(!fileSystem) return;
delete fileSystem; fileSystem = 0;
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libdoomsday/src/filesys/fs_scheme.cpp
Expand Up @@ -526,7 +526,7 @@ bool FS1::Scheme::mapPath(String &path) const
return true;
}

#if _DEBUG
#ifdef DENG_DEBUG
void FS1::Scheme::debugPrint() const
{
LOG_AS("Scheme::debugPrint");
Expand Down
8 changes: 4 additions & 4 deletions doomsday/libdoomsday/src/filesys/lumpindex.cpp
Expand Up @@ -40,8 +40,8 @@ namespace internal

static int lumpSorter(void const *a, void const *b)
{
LumpSortInfo const *infoA = (LumpSortInfo const*)a;
LumpSortInfo const *infoB = (LumpSortInfo const*)b;
LumpSortInfo const *infoA = (LumpSortInfo const *)a;
LumpSortInfo const *infoB = (LumpSortInfo const *)b;

if(int delta = infoA->path.compare(infoB->path, Qt::CaseInsensitive))
return delta;
Expand Down Expand Up @@ -100,7 +100,7 @@ DENG2_PIMPL(LumpIndex)
// the last lump with a given name appears first in the chain.
for(int i = 0; i < numElements; ++i)
{
File1 const &lump = *(lumps[i]);
File1 const &lump = *(lumps[i]);
PathTree::Node const &node = lump.directoryNode();
ushort k = node.hash() % (unsigned)numElements;

Expand All @@ -126,7 +126,7 @@ DENG2_PIMPL(LumpIndex)
for(int i = 0; i < numRecords; ++i)
{
if(pruneFlags.testBit(i)) continue;
if(reinterpret_cast<File1 *>(&lumps[i]->container()) != &file) continue;
if(&lumps[i]->container() != &file) continue;
pruneFlags.setBit(i, true);
numFlagged += 1;
}
Expand Down

0 comments on commit 3af44a9

Please sign in to comment.