C12Adapter Opensource C++ Interface
MVersion Class Reference

Version that has multiple fraction (subversion) numbers, up to a certain limit. More...

Inheritance diagram for MVersion:

Public Types

enum  { VersionMaximumNumberOfEntries = 5 }
 

Public Member Functions

 MVersion ()
 Construct an empty version object. More...
 
 MVersion (const MStdString &s, bool readonly=false)
 Construct Version object from a string representation of version. More...
 
 MVersion (const MStdString &s, const MStdString &format)
 Construct Version object from a string. More...
 
 MVersion (const MVersion &other)
 Construct a new version object from a given version object. More...
 
virtual ~MVersion ()
 Destroy the Version object. More...
 
MVersionoperator= (const MVersion &other)
 Assignment operator that takes variable of type MVersion. More...
 
MVersionoperator= (const MStdString &s)
 Assignment operator that takes variable of type MStdString. More...
 
bool operator== (const MVersion &other) const
 Equality boolean operator. More...
 
bool operator!= (const MVersion &other) const
 Inequality boolean operator. More...
 
bool operator< (const MVersion &other) const
 Less-than boolean operator. More...
 
bool operator> (const MVersion &other) const
 Greater-than boolean operator. More...
 
bool operator<= (const MVersion &other) const
 Less-than or equal-to boolean operator. More...
 
bool operator>= (const MVersion &other) const
 Greater-than or equal-to boolean operator. More...
 
bool IsEmpty () const
 Whether the version number is empty, has no subversions. More...
 
void SetEmpty ()
 Discard the value of the version, make it empty. More...
 
void Assign (const MVersion &other)
 Assignment method. More...
 
void AssignVariant (const MVariant &versionOrString)
 Most generic reflected version of assignment operator. More...
 
int CompareWhole (const MVariant &other) const
 
unsigned Item (unsigned index) const
 Returns the numeric value of the specified zero indexed fraction. More...
 
void SetItem (unsigned index, unsigned value)
 Sets the fraction with the given index to a value specified. More...
 
virtual unsigned GetEmbeddedSizeof () const
 Version is an embedded object type, therefore return its size in bytes. More...
 
bool IsReadOnly () const
 
void SetIsReadOnly (bool readonly)
 
int GetCount () const
 
void SetCount (int newCount)
 
MStdString AsString () const
 
void SetAsString (const MStdString &)
 
MStdString GetFormat () const
 
void SetFormat (const MStdString &)
 
bool Matches (const MVariant &other) const
 
bool MatchesVersion (const MVersion &other) const
 
int Compare (const MVariant &other, int precision=0) const
 
int CompareVersion (const MVersion &other, int precision=0) const
 
- Public Member Functions inherited from MObject
virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MObject
static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 
- Static Public Attributes inherited from MObject
static const MClass s_class
 Class of MObject.
 
- Protected Member Functions inherited from MObject
 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Version that has multiple fraction (subversion) numbers, up to a certain limit.

This is to represent a version of a software or firmware release. Restrictions apply on what version can be, as the number of fractions cannot exceed five, and each fraction shall be an unsigned number limited to value 65535. Version is a value type object that can be stored within Variant as is.

Version can be read-only (IsReadOnly is true), which means it cannot be modified by software unless it explicitly changes IsReadOnly into false. This attribute is not a security measure but an easy way of catching software errors.

Version can have a format that defines a number of fractions, their range, and whether the version is read-only. The format is a string consisting of the following case insensitive characters:

  • b - (or B) The entries in the version are bytes. If not specified, version entries are two-byte words
  • r - (or R) The version is Read-Only - its entries cannot be changed. This is another way of setting IsReadOnly.
  • [1-5] - Number of entries is constant, as specified by the given digit. If not specified, the number of entries is variable.

By default, the format is an empty string for read-write version, and "r" for IsReadOnly version. In either case such default format will mean the version can have any number of fractions from 0 to 5, and each fraction can be in range 0 to 65535. Other examples of format string are:

  • "b2" - version can only have two fractions, each in range 0 .. 255.
  • "4" - version is exactly four fractions, each in range 0 .. 65535.
  • "RB3" - version is read-only, exactly three fractions each in range 0 .. 255.

Member Enumeration Documentation

anonymous enum
Enumerator
VersionMaximumNumberOfEntries 

Maximum number of version entries.

Constructor & Destructor Documentation

MVersion::MVersion ( )

Construct an empty version object.

Postcondition
The result object will have no fractions, IsEmpty will be true, format empty, IsReadOnly false, and the count of fractions will be zero.
MVersion::MVersion ( const MStdString s,
bool  readonly = false 
)

Construct Version object from a string representation of version.

Parameters
sString representation of a version such as "3.1". The string should comprise of a correct representation of a version, such that it shall have numbers separated by periods.
readonlyWhether the result version object will be read-only, means the object cannot be changed unless read-only flag is cleared.
MVersion::MVersion ( const MStdString s,
const MStdString format 
)

Construct Version object from a string.

Parameters
sString representation of a version such as "3.1". The string should comprise of a correct representation of a version, such that it shall have numbers separated by periods.
formatVersion format.
MVersion::MVersion ( const MVersion other)

Construct a new version object from a given version object.

An exact same object is constructed. That includes both the set of subversions (fractions) and attributes such as format.

Parameters
otherVersion object from which a copy shall be made.
virtual MVersion::~MVersion ( )
inlinevirtual

Destroy the Version object.

Following value type object rules, this destructor does nothing.

Member Function Documentation

void MVersion::Assign ( const MVersion other)

Assignment method.

The value of this object will be exactly like one given. That includes both the set of subversions (fractions) and attributes such as format.

Precondition
This version shall not be read-only for the method to succeed. When the given object is read-only, this one becomes IsReadOnly too.
Parameters
otherVersion object which whole value is to be copied.
void MVersion::AssignVariant ( const MVariant versionOrString)

Most generic reflected version of assignment operator.

The behavior of this method depends on the type of the given parameter.

Precondition
This version shall not be read-only for the method to succeed. When the given object is read-only, this one becomes IsReadOnly too.
Parameters
versionOrStringParameter from which the assignment shall be made. Depending on the type, the behavior is as follows:
  • When an object is given, it shall be of type MVersion, or a conversion exception is thrown. For the case of such MVersion object, the result value of this object will be exactly like one given. That includes both the set of subversions (fractions) and attributes such as format.
  • Otherwise an attempt to convert the given parameter into string is made, and such string version representation gets assigned to this version. In such case the flags and format of this object are not changed, but only the fractions. If format is present, the string shall comprise a correct representation of a version according to format, or an exception is thrown. Such behavior allows easy manipulation of two-fraction versions as double precision numbers as they can be converted into string representation similar to one of MVersion.
MStdString MVersion::AsString ( ) const

String representation of version, accessible as read/write property.

If Count is zero, then AsString returns an empty string, "". Not all versions are writable, use IsReadOnly to determine if AsString is writable. When assigned, the given string should comprise a correct version representation. If the format is specified, the string should correspond to such format.

Returns
String such as "3.1".
int MVersion::Compare ( const MVariant other,
int  precision = 0 
) const

Compare version with the given other version object.

The comparison of two versions is very similar to string comparison, except that each fraction is compared not each character of a string. The result of the comparison is an integer value that will be zero for equal versions, minus one for the case when this version is smaller than the one given, and one if this version is bigger. The second optional parameter allows for comparison to ignore less significant fractions, which is convenient for cases when the comparison has to check major releases.

Parameters
otherVersion with which this version has to be compared.
precisionWhen comparing, whether to take into consideration a limited set of version fractions. The values are:
  • When zero or absent, all version fractions will be compared.
  • When this parameter is 1 to 5 the peer versions will be compared as if prior to comparison their counts are truncated to such number. For example, if the precisions is limited by two, the version "1.2.5" will be equal to "1.2". In other words, version "1.2.5" is the kind of major release "1.2".

Examples:

MVersion("3.2.15.0").Compare("3") > 0
MVersion("3.2.15.0").Compare("3.2.8") > 0
MVersion("3.0.0.0").Compare("3.2.15.0") < 0
MVersion("").Compare("") = 0
MVersion("3.0.0.0").Compare("3.0.123.123", 2) = 0 // compare up to two fractions
Returns
Integer with the following possible values:
  • 0 is returned if the versions are equal
  • -1, less than zero, means the object is smaller than parameter
  • 1, bigger than zero, the object is bigger than parameter
See also
Matches - comparison method that allows one of the versions to have smaller number of fractions.
int MVersion::CompareVersion ( const MVersion other,
int  precision = 0 
) const

Compare version with the given other version object.

The comparison of two versions is very similar to string comparison, except that each fraction is compared not each character of a string. The result of the comparison is an integer value that will be zero for equal versions, minus one for the case when this version is smaller than the one given, and one if this version is bigger. The second optional parameter allows for comparison to ignore less significant fractions, which is convenient for cases when the comparison has to check major releases.

Parameters
otherVersion with which this version has to be compared.
precisionWhen comparing, whether to take into consideration a limited set of version fractions. The values are:
  • When zero or absent, all version fractions will be compared.
  • When this parameter is 1 to 5 the peer versions will be compared as if prior to comparison their counts are truncated to such number. For example, if the precisions is limited by two, the version "1.2.5" will be equal to "1.2". In other words, version "1.2.5" is the kind of major release "1.2".

Examples:

MVersion("3.2.15.0").Compare("3") > 0
MVersion("3.2.15.0").Compare("3.2.8") > 0
MVersion("3.0.0.0").Compare("3.2.15.0") < 0
MVersion("").Compare("") = 0
MVersion("3.0.0.0").Compare("3.0.123.123", 2) = 0 // compare up to two fractions
Returns
Integer with the following possible values:
  • 0 is returned if the versions are equal
  • -1, less than zero, means the object is smaller than parameter
  • 1, bigger than zero, the object is bigger than parameter
See also
Matches - comparison method that allows one of the versions to have smaller number of fractions.
int MVersion::CompareWhole ( const MVariant other) const
See also
Compare
int MVersion::GetCount ( ) const
inline

Count of subversions (fractions) in version.

For example, Count = 3 is for version "10.20.30". If the referenced object IsEmpty then Count returns zero. When setting Count property, the existing version is either truncated or extended with zeros.

Possible values:
  • When format does not specify the exact count, this can be 0 to 5.
  • When an exact count is specified by format, this can only be that number specified.
Returns
int - the number of fractions present in the version.
virtual unsigned MVersion::GetEmbeddedSizeof ( ) const
virtual

Version is an embedded object type, therefore return its size in bytes.

Returns
Size of MVersion in bytes.

Reimplemented from MObject.

MStdString MVersion::GetFormat ( ) const

Version format property.

The format is described in detail in version class description

bool MVersion::IsEmpty ( ) const
inline

Whether the version number is empty, has no subversions.

This is a test that returns true if the version has no fractions (subversions). Flags such as IsReadOnly or Format are not taken into consideration. A string representation of an empty MVersion object is an empty string, "". When the version has a fixed format it can never be empty.

See also
SetEmpty - Resetting the version value.
bool MVersion::IsReadOnly ( ) const
inline

Indicates if the version object is writable.

Read-only objects cannot be modified in any way until IsReadOnly is set to false.

unsigned MVersion::Item ( unsigned  index) const

Returns the numeric value of the specified zero indexed fraction.

The numeric value of each sub version can be retrieved using the Item method. Assuming the version is "10.20.30.40", the following are fractions:

ver.Item(1) = 10
ver.Item(2) = 20
ver.Item(3) = 30
ver.Item(4) = 40
Parameters
indexThe index of the sub version to retrieve. The valid range is 0 to Count - 1.
Returns
unsigned, the value of a fraction
bool MVersion::Matches ( const MVariant other) const

Check whether this version matches the one given.

This is a convenience method that determines whether the given version number is a subset of a more generic major version (5.0.0.123 is a subset of 5.0). This method is similar to Compare except that it behaves differently when the peer versions have a different number of fractions. If this version has a smaller number of fractions, then true is returned when all existing fractions of this version are equal to those in the other version. Here are the examples:

MVersion("5.0").Matches("5.0.0.123") is TRUE // version 5.0.0.123 is of the 5.0 kind
MVersion("4.1").Matches("4.1.1.543") is TRUE // version 4.1.1.543 is of major kind 4.1
MVersion("5.1").Matches("5.1") is TRUE // same result as simple comparison
MVersion("4.1").Matches("4.2.0.0") is FALSE

The operation is not commutative and v1.Matches(v2) is not necessarily the same result as v2.Matches(v1). In fact, they will give different results if and only if v1 and v2 have a different number of fractions. Therefore:

MVersion("5.0.0.123").Matches("5.0") is FALSE
MVersion("4.1.1.543").Matches("4.1") is FALSE
Parameters
otherVersion with which this version has to be matched.
Returns
bool value to tell if the given version matches this version.
See also
Compare method that takes a second precision parameter is similar to this service.
bool MVersion::MatchesVersion ( const MVersion other) const

Check whether this version matches the one given.

This is a convenience method that determines whether the given version number is a subset of a more generic major version (5.0.0.123 is a subset of 5.0). This method is similar to Compare except that it behaves differently when the peer versions have a different number of fractions. If this version has a smaller number of fractions, then true is returned when all existing fractions of this version are equal to those in the other version. Here are the examples:

MVersion("5.0").Matches("5.0.0.123") is TRUE // version 5.0.0.123 is of the 5.0 kind
MVersion("4.1").Matches("4.1.1.543") is TRUE // version 4.1.1.543 is of major kind 4.1
MVersion("5.1").Matches("5.1") is TRUE // same result as simple comparison
MVersion("4.1").Matches("4.2.0.0") is FALSE

The operation is not commutative and v1.Matches(v2) is not necessarily the same result as v2.Matches(v1). In fact, they will give different results if and only if v1 and v2 have a different number of fractions. Therefore:

MVersion("5.0.0.123").Matches("5.0") is FALSE
MVersion("4.1.1.543").Matches("4.1") is FALSE
Parameters
otherVersion with which this version has to be matched.
Returns
bool value to tell if the given version matches this version.
See also
Compare method that takes a second precision parameter is similar to this service.
bool MVersion::operator!= ( const MVersion other) const
inline

Inequality boolean operator.

Versions are considered not equal if their number of fractions are different, or any fraction has a different value as the corresponding fraction in the other version. Read-only and format flags do not participate in comparison.

Parameters
otherOther version object with which to make the comparison.

Examples of true inequality (string representation of version is used):

MVersion("3.2.15.0") != MVersion("3.2.15.1")
MVersion("3.2.15.0") != MVersion("3.2.15")
MVersion("3.2.15.0") != MVersion("3")
MVersion("15") != MVersion("20")
MVersion("") != MVersion("1.2.3")
See also
Compare - Generic comparison method.
Matches - Comparison method that allows one of the versions to have smaller number of fractions.
bool MVersion::operator< ( const MVersion other) const
inline

Less-than boolean operator.

The comparison of two versions is very similar to string comparison, except that each fraction is compared, not each character of a string. The comparison proceeds from left to right, fraction by fraction, until not matching fractions are found, or one of the versions does not have the corresponding fraction because its Count is smaller.

Parameters
otherOther version object with which to make the comparison.

Examples of comparison:

MVersion("3") < MVersion("3.2.15.0")
MVersion("3.2.8") < MVersion("3.2.15.0")
MVersion("3.0.0.0") < MVersion("3.2.15.0")
MVersion("") < MVersion("3.0.0.0")
MVersion("3.2.15.0") < MVersion("3.3")
See also
Compare - Generic comparison method.
Matches - Comparison method that allows one of the versions to have smaller number of fractions.
bool MVersion::operator<= ( const MVersion other) const
inline

Less-than or equal-to boolean operator.

The comparison of two versions is very similar to string comparison, except that each fraction is compared, not each character of a string. The comparison proceeds from left to right, fraction by fraction, until not matching fractions are found, or one of the versions does not have the corresponding fraction because its Count is smaller.

Parameters
otherOther version object with which to make the comparison.

Examples of comparison:

MVersion("3") <= MVersion("3.2.15.0")
MVersion("3.2.8") <= MVersion("3.2.15.0")
MVersion("3.2.15.0") <= MVersion("3.2.15.0") // because they are equal
MVersion("") <= MVersion("3.0.0.0")
MVersion("") <= MVersion("") // because they are equal
See also
Compare - Generic comparison method.
MVersion& MVersion::operator= ( const MVersion other)
inline

Assignment operator that takes variable of type MVersion.

The value of this object will be exactly like one given. That includes both the set of subversions (fractions) and attributes such as format.

Precondition
This version shall not be read-only for the method to succeed. When the given object is read-only, this one becomes IsReadOnly too.
Parameters
otherVersion object which whole value is to be copied.
MVersion& MVersion::operator= ( const MStdString s)
inline

Assignment operator that takes variable of type MStdString.

Only the value of the string is copied while the read-only status and format remain as they were prior to the assignment.

Precondition
The version shall not be read-only for the method to succeed.
Parameters
sString representation of a version such as "3.1". The string should comprise a correct representation of a version, such as it shall have numbers separated by periods.
bool MVersion::operator== ( const MVersion other) const
inline

Equality boolean operator.

Versions are considered equal if their number of fractions are the same, and each fraction has the same value. Read-only and format flags do not participate in comparison.

Parameters
otherOther version object with which to make the comparison.

Examples of true equality (string representation of version is used):

MVersion("3.2.15.0") = MVersion("3.2.15.0")
MVersion("15") = MVersion("15")
MVersion("") = MVersion("")
See also
Compare - generic comparison method.
bool MVersion::operator> ( const MVersion other) const
inline

Greater-than boolean operator.

The comparison of two versions is very similar to string comparison, except that each fraction is compared, not each character of a string. The comparison proceeds from left to right, fraction by fraction, until not matching fractions are found, or one of the versions does not have the corresponding fraction because its Count is smaller.

Parameters
otherOther version object with which to make the comparison.

Examples of comparison:

MVersion("3.2.15.0") > MVersion("3")
MVersion("3.2.15.0") > MVersion("3.2.8")
MVersion("3.2.15.0") > MVersion("3.0.0.0")
MVersion("3.0.0.0") > MVersion("")
MVersion("3.3") > MVersion("3.2.15.0")
See also
Compare - Generic comparison method.
bool MVersion::operator>= ( const MVersion other) const
inline

Greater-than or equal-to boolean operator.

The comparison of two versions is very similar to string comparison, except that each fraction is compared, not each character of a string. The comparison proceeds from left to right, fraction by fraction, until not matching fractions are found, or one of the versions does not have the corresponding fraction because its Count is smaller.

Parameters
otherOther version object with which to make the comparison.

Examples of comparison:

MVersion("3.2.15.0") >= MVersion("3")
MVersion("3.2.15.0") >= MVersion("3.2.8")
MVersion("3.2.15.0") >= MVersion("3.2.15.0") // because they are equal
MVersion("") >= MVersion("") // because they are equal
See also
Compare - Generic comparison method.
void MVersion::SetAsString ( const MStdString )

String representation of version, accessible as read/write property.

If Count is zero, then AsString returns an empty string, "". Not all versions are writable, use IsReadOnly to determine if AsString is writable. When assigned, the given string should comprise a correct version representation. If the format is specified, the string should correspond to such format.

Returns
String such as "3.1".
void MVersion::SetCount ( int  newCount)

Count of subversions (fractions) in version.

For example, Count = 3 is for version "10.20.30". If the referenced object IsEmpty then Count returns zero. When setting Count property, the existing version is either truncated or extended with zeros.

Possible values:
  • When format does not specify the exact count, this can be 0 to 5.
  • When an exact count is specified by format, this can only be that number specified.
Returns
int - the number of fractions present in the version.
void MVersion::SetEmpty ( )

Discard the value of the version, make it empty.

Precondition
This version shall not be read-only and the version format shall not be fixed size for the method to succeed.
Postcondition
MVersion object will be IsEmpty and AsString will return an empty string after this call.
See also
IsEmpty - emptiness checker.
void MVersion::SetFormat ( const MStdString )

Version format property.

The format is described in detail in version class description

void MVersion::SetIsReadOnly ( bool  readonly)
inline

Indicates if the version object is writable.

Read-only objects cannot be modified in any way until IsReadOnly is set to false.

void MVersion::SetItem ( unsigned  index,
unsigned  value 
)

Sets the fraction with the given index to a value specified.

Parameters
indexThe index of the sub version to set. The valid range is 0 to Count - 1.
valueThe value to which the fraction has to be set. For byte size format "b" this is 0 to 255. Otherwise the allowed range is 0 to 65535.
Precondition
This version shall not be read-only for the method to succeed.