Skip to content

Commit

Permalink
libcore|File: Getting a file description with specific verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 13, 2016
1 parent 065a50d commit 8dda59a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
7 changes: 6 additions & 1 deletion doomsday/sdk/libcore/include/de/filesys/file.h
Expand Up @@ -210,9 +210,14 @@ class DENG2_PUBLIC File : public filesys::Node, public IIOStream, public IObject
* This attempts to fully describe the file, taking into consideration
* the file's type and possible source.
*
* @param verbosity Level of verbosity:
* - Level 1: include file path
* - Level 2: include origin feed description
* Use -1 for autodetection (depends on current log entry level).
*
* @return Full human-friendly description of the file.
*/
String description() const;
String description(int verbosity = -1) const;

/**
* Returns a textual description of this file only. Subclasses must
Expand Down
38 changes: 20 additions & 18 deletions doomsday/sdk/libcore/src/filesys/file.cpp
Expand Up @@ -116,35 +116,37 @@ Folder *File::parent() const
return Node::parent()->maybeAs<Folder>();
}

String File::description() const
String File::description(int verbosity) const
{
DENG2_GUARD(this);

// describe() gives the actual description of this file.
String desc = describe();

if(!mode().testFlag(Write))
{
desc = "read-only " + desc;
}

// Check for additional contextual information that may be relevant. First
// determine if this is being called for a log entry.
Log &log = Log::threadLog();
int verbosity = 0;
if(!log.isStaging() || (log.currentEntryMetadata() & LogEntry::Dev))
{
// For dev entries and everything outside log entries, use a full description.
verbosity = 2;
}
else if((log.currentEntryMetadata() & LogEntry::LevelMask) <= LogEntry::Verbose)
if(verbosity < 0)
{
// Verbose entries can contain some additional information.
verbosity = 1;
Log &log = Log::threadLog();
int verbosity = 0;
if(!log.isStaging() || (log.currentEntryMetadata() & LogEntry::Dev))
{
// For dev entries and everything outside log entries, use a full description.
verbosity = 2;
}
else if((log.currentEntryMetadata() & LogEntry::LevelMask) <= LogEntry::Verbose)
{
// Verbose entries can contain some additional information.
verbosity = 1;
}
}

if(verbosity >= 1)
if(verbosity > 0)
{
if(!mode().testFlag(Write))
{
desc = "read-only " + desc;
}
if(parent())
{
desc += " (path \"" + path() + "\")";
Expand All @@ -165,7 +167,7 @@ String File::description() const
// file interpretation is being applied.
if(source() != this)
{
desc += " (data sourced from " + source()->description() + ")";
desc += _E(i) " {data sourced from " + source()->description(verbosity) + "}" _E(.);
}
#endif

Expand Down

0 comments on commit 8dda59a

Please sign in to comment.