Skip to content

Commit

Permalink
libcore: Minor API additions in several classes
Browse files Browse the repository at this point in the history
Added some useful but hitherto missing member functions.
  • Loading branch information
skyjake committed Jan 12, 2016
1 parent f8ab020 commit 86c5bf2
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 17 deletions.
2 changes: 2 additions & 0 deletions doomsday/sdk/libcore/include/de/core/loop.h
Expand Up @@ -102,6 +102,8 @@ class DENG2_PUBLIC LoopCallback : public Lockable, DENG2_OBSERVES(Loop, Iteratio
LoopCallback();
~LoopCallback();

bool isEmpty() const;

void enqueue(Callback func);
void loopIteration();

Expand Down
8 changes: 7 additions & 1 deletion doomsday/sdk/libcore/include/de/core/version.h
Expand Up @@ -16,7 +16,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_VERSION_H
Expand Down Expand Up @@ -63,6 +63,12 @@ class DENG2_PUBLIC Version
*/
Version(String const &version, int buildNumber = 0);

/**
* Determines if the version is valid, i.e., it contains something other
* than all zeroes and empty strings.
*/
bool isValid() const;

/**
* Forms a version string in the form "x.y.z". If a release label is
* defined, it will be included, too: "x.y.z (label)".
Expand Down
5 changes: 3 additions & 2 deletions doomsday/sdk/libcore/include/de/data/block.h
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#ifndef LIBDENG2_BLOCK_H
Expand Down Expand Up @@ -89,6 +89,7 @@ class DENG2_PUBLIC Block : public QByteArray, public IByteArray, public IBlock
Byte const *data() const;

Byte *data();
Byte const *dataConst() const;

/// Appends a block after this one.
Block &operator += (Block const &other);
Expand All @@ -103,5 +104,5 @@ class DENG2_PUBLIC Block : public QByteArray, public IByteArray, public IBlock
};

} // namespace de

#endif // LIBDENG2_BLOCK_H
24 changes: 14 additions & 10 deletions doomsday/sdk/libcore/include/de/data/info.h
Expand Up @@ -182,6 +182,8 @@ class DENG2_PUBLIC Info
*/
bool isRootBlock() const { return _blockType.isEmpty(); }

bool isEmpty() const { return _contents.empty(); }

Info &info() const { return _info; }

String const &blockType() const { return _blockType; }
Expand Down Expand Up @@ -280,16 +282,6 @@ class DENG2_PUBLIC Info
public:
Info();

/**
* Sets the finder for included documents. By default, attempts to locate Info files
* by treating the name of the included file as an absolute path.
*
* @param finder Include finder object. Info does not take ownership.
*/
void setFinder(IIncludeFinder const &finder);

void useDefaultFinder();

/**
* Parses a string of text as Info source.
*
Expand All @@ -306,6 +298,16 @@ class DENG2_PUBLIC Info

Info(String const &source, IIncludeFinder const &finder);

/**
* Sets the finder for included documents. By default, attempts to locate Info files
* by treating the name of the included file as an absolute path.
*
* @param finder Include finder object. Info does not take ownership.
*/
void setFinder(IIncludeFinder const &finder);

void useDefaultFinder();

/**
* Sets all the block types whose content is parsed using a script parser.
* The blocks will contain a single KeyElement named "script".
Expand Down Expand Up @@ -390,6 +392,8 @@ class DENG2_PUBLIC Info
*/
bool findValueForKey(String const &key, String &value) const;

bool isEmpty() const;

static String sourceLocation(duint32 lineId);
static SourceLineTable const &sourceLineTable();

Expand Down
11 changes: 11 additions & 0 deletions doomsday/sdk/libcore/include/de/filesys/package.h
Expand Up @@ -22,6 +22,7 @@
#include "../String"
#include "../File"
#include "../FileIndex"
#include "../Version"
#include "../IObject"

#include <QSet>
Expand Down Expand Up @@ -159,6 +160,16 @@ class DENG2_PUBLIC Package : public IObject

static QStringList tags(File const &packageFile);

/**
* Splits a string containing a package identifier and version. The
* expected format of the string is `{packageId}_{version}`.
*
* @param identifier_version Identifier and version.
*
* @return The split components.
*/
static std::pair<String, Version> split(String const &identifier_version);

static String identifierForFile(File const &file);

/**
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libcore/src/core/loop.cpp
Expand Up @@ -127,6 +127,11 @@ LoopCallback::~LoopCallback()
Loop::get().audienceForIteration() -= this;
}

bool LoopCallback::isEmpty() const
{
return _funcs.isEmpty();
}

void LoopCallback::enqueue(Callback func)
{
DENG2_GUARD(this);
Expand Down
7 changes: 6 additions & 1 deletion doomsday/sdk/libcore/src/data/block.cpp
Expand Up @@ -14,7 +14,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/Block"
Expand Down Expand Up @@ -107,6 +107,11 @@ void Block::resize(Size size)
QByteArray::resize(size);
}

IByteArray::Byte const *Block::dataConst() const
{
return reinterpret_cast<Byte const *>(QByteArray::constData());
}

Block::Byte *Block::data()
{
return reinterpret_cast<Byte *>(QByteArray::data());
Expand Down
5 changes: 5 additions & 0 deletions doomsday/sdk/libcore/src/data/info.cpp
Expand Up @@ -892,6 +892,11 @@ bool Info::findValueForKey(String const &key, String &value) const
return false;
}

bool Info::isEmpty() const
{
return d->rootBlock.isEmpty();
}

String Info::sourceLocation(duint32 lineId) // static
{
return de::sourceLineTable.sourceLocation(lineId);
Expand Down
16 changes: 16 additions & 0 deletions doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -326,6 +326,22 @@ static String extractIdentifier(String str)
return stripAfterFirstUnderscore(str.fileNameWithoutExtension());
}

std::pair<String, Version> Package::split(String const &identifier_version)
{
std::pair<String, Version> idVer;
if(identifier_version.contains(QChar('_')))
{
idVer.first = stripAfterFirstUnderscore(identifier_version);
idVer.second = Version(identifier_version.substr(idVer.first.size() + 1));
}
else
{
idVer.first = identifier_version;
idVer.second = Version("");
}
return idVer;
}

String Package::identifierForFile(File const &file)
{
// Form the prefix if there are enclosing packs as parents.
Expand Down
12 changes: 9 additions & 3 deletions doomsday/sdk/libcore/src/version.cpp
Expand Up @@ -16,7 +16,7 @@
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
* General Public License for more details. You should have received a copy of
* the GNU Lesser General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
* http://www.gnu.org/licenses</small>
*/

#include "de/Version"
Expand All @@ -35,9 +35,9 @@ Version::Version() : build(Time().asBuildNumber())
#endif

label = LIBDENG2_RELEASE_LABEL;

#ifdef LIBDENG2_GIT_DESCRIPTION
gitDescription = LIBDENG2_GIT_DESCRIPTION;
gitDescription = LIBDENG2_GIT_DESCRIPTION;
#endif
}

Expand All @@ -46,6 +46,12 @@ Version::Version(String const &version, int buildNumber) : build(buildNumber)
parseVersionString(version);
}

bool Version::isValid() const
{
return major || minor || patch || build ||
!label.isEmpty() || !gitDescription.isEmpty();
}

String Version::base() const
{
String v = String("%1.%2.%3").arg(major).arg(minor).arg(patch);
Expand Down

0 comments on commit 86c5bf2

Please sign in to comment.