Skip to content

Commit

Permalink
Refactor|libcore|Client: Improved Version class API
Browse files Browse the repository at this point in the history
The default constructor now creates a null version and there is a
static method for getting info about the current build. This is
more readable than the previous implicit behavior of Version().

This makes it also less of a performance hit in situations where
Version instances get constructed often. (No calls to Time().)
  • Loading branch information
skyjake committed Jun 5, 2016
1 parent b7792c6 commit 4fea419
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 19 deletions.
5 changes: 4 additions & 1 deletion doomsday/apps/client/include/versioninfo.h
Expand Up @@ -6,6 +6,9 @@
#include <de/Time>
#include "dd_version.h"

/**
* @deprecated Use de::Version instead.
*/
struct VersionInfo
{
int major;
Expand Down Expand Up @@ -47,7 +50,7 @@ struct VersionInfo
void parseVersionString(de::String const &version)
{
major = minor = revision = patch = 0;

QStringList const parts = version.split('.');
if(parts.size() > 0)
{
Expand Down
3 changes: 2 additions & 1 deletion doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -499,7 +499,8 @@ ClientApp::ClientApp(int &argc, char **argv)
QPixmap const pixmap(doomsdaySplashXpm);
QSplashScreen *splash = new QSplashScreen(pixmap);
splash->show();
splash->showMessage(Version().asText(), Qt::AlignHCenter | Qt::AlignBottom,
splash->showMessage(Version::currentBuild().asText(),
Qt::AlignHCenter | Qt::AlignBottom,
QColor(90, 110, 95));
processEvents();
splash->deleteLater();
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/network/net_main.cpp
Expand Up @@ -897,7 +897,7 @@ dd_bool ServerInfo_FromString(serverinfo_t *info, char const *valuePair)
String Net_UserAgent()
{
return String(DOOMSDAY_NICENAME " " DOOMSDAY_VERSION_TEXT)
+ " (" + de::Version().operatingSystem() + ")";
+ " (" + de::Version::operatingSystem() + ")";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion doomsday/apps/client/src/ui/dialogs/aboutdialog.cpp
Expand Up @@ -64,7 +64,7 @@ AboutDialog::AboutDialog() : DialogWidget("about"), d(new Instance(this))
logo->setSizePolicy(ui::Fixed, ui::Expand);

VersionInfo version;
de::Version ver2;
de::Version ver2 = de::Version::currentBuild();

// Set up the contents of the widget.
LabelWidget *title = LabelWidget::newWithText(String("%1 %2.%3")
Expand Down
8 changes: 7 additions & 1 deletion doomsday/sdk/libcore/include/de/core/version.h
Expand Up @@ -52,7 +52,7 @@ class DENG2_PUBLIC Version
String gitDescription; ///< Output from "git describe".

/**
* Version information about this build.
* Initializes an invalid all-zero version.
*/
Version();

Expand All @@ -67,6 +67,12 @@ class DENG2_PUBLIC Version
*/
Version(String const &version, int buildNumber = 0);

/**
* Version information about this build. The version information is hardcoded in the
* build configuration.
*/
static Version currentBuild();

/**
* Determines if the version is valid, i.e., it contains something other
* than all zeroes and empty strings.
Expand Down
4 changes: 2 additions & 2 deletions doomsday/sdk/libcore/src/core/app.cpp
Expand Up @@ -610,7 +610,7 @@ void App::initSubsystems(SubsystemInitFlags flags)

// Immediately after upgrading, OLD_VERSION is also present in the Version module.
Version oldVer = d->config->upgradedFromVersion();
if (oldVer != Version())
if (oldVer != Version::currentBuild())
{
ArrayValue *old = new ArrayValue;
*old << NumberValue(oldVer.major) << NumberValue(oldVer.minor)
Expand Down Expand Up @@ -677,7 +677,7 @@ void App::initSubsystems(SubsystemInitFlags flags)
#endif
}

LOG_VERBOSE("libcore::App %s subsystems initialized") << Version().asText();
LOG_VERBOSE("libcore::App %s subsystems initialized") << Version::currentBuild().asText();
}

void App::addSystem(System &system)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/core/config.cpp
Expand Up @@ -86,7 +86,7 @@ void Config::read()
LOG_AS("Config::read");

// Current version.
Version verInfo;
Version verInfo = Version::currentBuild();
QScopedPointer<ArrayValue> version(new ArrayValue);
*version << NumberValue(verInfo.major)
<< NumberValue(verInfo.minor)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/filesys/package.cpp
Expand Up @@ -380,6 +380,7 @@ static String extractIdentifier(String str)
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);
Expand All @@ -388,7 +389,6 @@ std::pair<String, Version> Package::split(String const &identifier_version)
else
{
idVer.first = identifier_version;
idVer.second = Version("");
}
return idVer;
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libcore/src/scriptsys/scriptsystem.cpp
Expand Up @@ -67,7 +67,7 @@ DENG2_PIMPL(ScriptSystem)

// Setup the Version module.
{
Version ver;
Version const ver = Version::currentBuild();
Record &mod = versionModule;
ArrayValue *num = new ArrayValue;
*num << NumberValue(ver.major) << NumberValue(ver.minor)
Expand Down
29 changes: 20 additions & 9 deletions doomsday/sdk/libcore/src/version.cpp
Expand Up @@ -24,21 +24,32 @@

namespace de {

Version::Version() : build(Time().asBuildNumber())
Version::Version()
: major(0)
, minor(0)
, patch(0)
, build(0)
{}

Version Version::currentBuild()
{
major = LIBDENG2_MAJOR_VERSION;
minor = LIBDENG2_MINOR_VERSION;
patch = LIBDENG2_PATCHLEVEL;
Version v;
v.major = LIBDENG2_MAJOR_VERSION;
v.minor = LIBDENG2_MINOR_VERSION;
v.patch = LIBDENG2_PATCHLEVEL;

#ifdef LIBDENG2_BUILD_TEXT
build = String(LIBDENG2_BUILD_TEXT).toInt();
v.build = String(LIBDENG2_BUILD_TEXT).toInt();
#else
v.build = Time().asBuildNumber(); // only used in development builds
#endif

label = LIBDENG2_RELEASE_LABEL;
v.label = LIBDENG2_RELEASE_LABEL;

#ifdef LIBDENG2_GIT_DESCRIPTION
gitDescription = LIBDENG2_GIT_DESCRIPTION;
v.gitDescription = LIBDENG2_GIT_DESCRIPTION;
#endif
return v;
}

Version::Version(String const &version, int buildNumber) : build(buildNumber)
Expand Down Expand Up @@ -114,9 +125,9 @@ bool Version::operator > (Version const &other) const

String Version::operatingSystem()
{
#ifdef WIN32
#if defined(WIN32)
return "windows";
#elif MACOSX
#elif defined(MACOSX)
return "macx";
#else
return "unix";
Expand Down

0 comments on commit 4fea419

Please sign in to comment.