Add a 'revision' component to wxVersionInfo

Some versions consist of four parts with the last part being called the
revision or build number. wxVersionInfo is now able to save such a
fourth number.
This commit is contained in:
Ronny Krüger 2022-05-25 15:20:51 +02:00 committed by Vadim Zeitlin
parent 3fcf4a5f74
commit 8ef6f9fa27
2 changed files with 55 additions and 10 deletions

View file

@ -23,15 +23,21 @@ public:
int major = 0,
int minor = 0,
int micro = 0,
int revision = 0,
const wxString& description = wxString(),
const wxString& copyright = wxString())
: m_name(name)
, m_description(description)
, m_copyright(copyright)
{
m_major = major;
m_minor = minor;
m_micro = micro;
Init(name, major, minor, micro, revision, description, copyright);
}
// This constructor exists for backward compatibility (before the revision
// part was added).
wxVersionInfo(const wxString& name,
int major, int minor, int micro,
const wxString& description,
const wxString& copyright = wxString())
{
Init(name, major, minor, micro, 0, description, copyright);
}
// Default copy ctor, assignment operator and dtor are ok.
@ -42,6 +48,7 @@ public:
int GetMajor() const { return m_major; }
int GetMinor() const { return m_minor; }
int GetMicro() const { return m_micro; }
int GetRevision() const { return m_revision; }
wxString ToString() const
{
@ -52,8 +59,12 @@ public:
{
wxString str;
str << m_name << ' ' << GetMajor() << '.' << GetMinor();
if ( GetMicro() )
if ( GetMicro() || GetRevision() )
{
str << '.' << GetMicro();
if ( GetRevision() )
str << '.' << GetRevision();
}
return str;
}
@ -65,13 +76,28 @@ public:
const wxString& GetCopyright() const { return m_copyright; }
private:
void Init(const wxString& name,
int major, int minor, int micro, int revision,
const wxString& description,
const wxString& copyright)
{
m_name = name;
m_description = description;
m_copyright = copyright;
m_major = major;
m_minor = minor;
m_micro = micro;
m_revision = revision;
}
wxString m_name,
m_description,
m_copyright;
int m_major,
m_minor,
m_micro;
m_micro,
m_revision;
};
#endif // _WX_VERSIONINFO_H_

View file

@ -35,6 +35,9 @@ public:
@param major The major version component.
@param minor The minor version component.
@param micro The micro version component, 0 by default.
@param revision The revision version component, also known as "build
number". This component is also 0 by default and is only available
since wxWidgets 3.2.0.
@param description Free form description of this version, none by
default.
@param copyright Copyright string, none by default.
@ -43,6 +46,7 @@ public:
int major = 0,
int minor = 0,
int micro = 0,
int revision = 0,
const wxString& description = wxString(),
const wxString& copyright = wxString());
@ -70,10 +74,23 @@ public:
/**
Get the micro version, or release number.
This is the third component of the version.
@return Micro version, or release number.
*/
int GetMicro() const;
/**
Get the revision version, or build number.
This is the fourth component of the version.
@return Revision version, or build number.
@since 3.2.0
*/
int GetRevision() const;
/**
Get the string representation of this version object.
@ -87,9 +104,11 @@ public:
/**
Get the string representation.
The micro component of the version is ignored/not used if it is 0.
The micro and revision components of the version are ignored/not used
if they are both zero. If the revision component is non-zero all four
parts will be used even if the micro component is zero.
@return The version string in the form "name major.minor[.micro]".
@return The version string in the form "name major.minor[.micro[.revision]]".
*/
wxString GetVersionString() const;