// Copyright Onix Solutions Limited [OnixS]. All rights reserved. // // This software owned by Onix Solutions Limited [OnixS] and is // protected by copyright law and international copyright treaties. // // Access to and use of the software is governed by the terms of the applicable // OnixS Software Services Agreement (the Agreement) and Customer end user license // agreements granting a non-assignable, non-transferable and non-exclusive license // to use the software for it's own data processing purposes under the terms defined // in the Agreement. // // Except as otherwise granted within the terms of the Agreement, copying or // reproduction of any part of this source code or associated reference material // to any other location for further reproduction or redistribution, and any // amendments to this copyright notice, are expressly prohibited. // // Any reproduction or redistribution for sale or hiring of the Software not in // accordance with the terms of the Agreement is a violation of copyright law. // #pragma once #include #include #include ONIXS_CMEMDH_NAMESPACE_BEGIN /// Identifies version of the product. /// /// Provides access to single components /// which compound whole version, comparing /// and serialization/deserialization facilities. ONIXS_CMEMDH_LTWT_CLASS Version { public: /// Alias for the numeric component of version. typedef UInt16 Component; /// Initializes instances from all the components. Version( Component major, Component minor, Component patch) : major_(major) , minor_(minor) , patch_(patch) { } /// Initializes as clone of other instance. Version( const Version& other) : major_(other.major_) , minor_(other.minor_) , patch_(other.patch_) { } /// 'major' component of version. Component major() const { return major_; } /// 'minor' component of version. Component minor() const { return minor_; } /// 'patch' component of version. Component patch() const { return patch_; } /// Re-initializes instance as copy of other one. Version& operator =( const Version& other) { major_ = other.major_; minor_ = other.minor_; patch_ = other.patch_; return *this; } /// Identifies current version of the product. ONIXS_CMEMDH_LTWT_EXPORTED static Version current(); private: Component major_; Component minor_; Component patch_; }; /// Compares with other instance for equality. inline bool operator ==( const Version& left, const Version& right) { return ( left.major() == right.major() && left.minor() == right.minor() && left.patch() == right.patch() ); } inline bool operator !=( const Version& left, const Version& right) { return !(left == right); } inline bool operator <( const Version& left, const Version& right) { return ( left.major() < right.major() || ( left.major() == right.major() && left.minor() < right.minor()) || ( left.major() == right.major() && left.minor() == right.minor() && left.patch() < right.patch()) ); } inline bool operator >( const Version& left, const Version& right) { return (right < left); } /// Extracts version from point-separated presentation. /// Updates version parameter if buffer is parsed successfully. ONIXS_CMEMDH_EXPORTED bool fromStr( const Char*, size_t, Version&); /// Appends point-separated presentation of version to given string. ONIXS_CMEMDH_EXPORTED void toStr( std::string&, const Version&); /// Serializes Version instance into point-separated presentation. inline std::string toStr( const Version& version) { std::string str; toStr(str, version); return str; } ONIXS_CMEMDH_NAMESPACE_END