neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
version.hpp
Go to the documentation of this file.
1// version.hpp
2/*
3 * Copyright (c) 2007 Leigh Johnston.
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * * Neither the name of Leigh Johnston nor the names of any
19 * other contributors to this software may be used to endorse or
20 * promote products derived from this software without specific prior
21 * written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#pragma once
37
38#include <neolib/neolib.hpp>
39#include <string>
40#include <ostream>
45
46namespace neolib
47{
48 class version : public i_version
49 {
50 // construction
51 public:
52 version(uint32_t aMajor, uint32_t aMinor, uint32_t aMaintenance, uint32_t aBuild = 0, const std::string& aName = "") :
53 iMajor(aMajor), iMinor(aMinor), iMaintenance(aMaintenance), iBuild(aBuild), iName(aName)
54 {
55 }
56 version(const std::string& aVersionString = "") :
57 iMajor(0), iMinor(0), iMaintenance(0), iBuild(0), iName("")
58 {
60 neolib::tokens(aVersionString, std::string(". "), bits, 4);
61 if (bits.size() > 0)
62 iMajor = neolib::string_to_uint32(bits[0]);
63 if (bits.size() > 1)
64 iMinor = neolib::string_to_uint32(bits[1]);
65 if (bits.size() > 2)
66 iMaintenance = neolib::string_to_uint32(bits[2]);
67 if (bits.size() > 3)
68 iBuild = neolib::string_to_uint32(bits[3]);
69 if (bits.size() > 4)
70 iName = bits[3];
71 }
72 version(const i_version& aOther) :
73 iMajor(aOther.version_major()), iMinor(aOther.version_minor()), iMaintenance(aOther.version_maintenance()), iBuild(aOther.version_build()), iName(aOther.version_name())
74 {
75 }
76
77 // operations
78 public:
79 bool operator<(const version& aOther) const
80 {
81 return std::make_tuple(iMajor, iMinor, iMaintenance, iBuild) < std::make_tuple(aOther.iMajor, aOther.iMinor, iMaintenance, aOther.iBuild);
82 }
83 bool operator>(const version& aOther) const
84 {
85 return aOther < *this;
86 }
87 bool operator==(const version& aOther) const
88 {
89 return iMajor == aOther.iMajor && iMinor == aOther.iMinor && iMaintenance == aOther.iMaintenance && iBuild == aOther.iBuild;
90 }
91 // implementation
92 public:
93 // from i_version
94 uint32_t version_major() const
95 {
96 return iMajor;
97 }
98 uint32_t version_minor() const
99 {
100 return iMinor;
101 }
102 uint32_t version_maintenance() const
103 {
104 return iMaintenance;
105 }
106 uint32_t version_build() const
107 {
108 return iBuild;
109 }
110 const i_string& version_name() const
111 {
112 return iName;
113 }
114 private:
115 uint32_t iMajor;
116 uint32_t iMinor;
117 uint32_t iMaintenance;
118 uint32_t iBuild;
119 string iName;
120 };
121
122 template <typename Elem, typename Traits>
123 inline std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& aStream, const version& aVersion)
124 {
125 aStream << aVersion.version_major() << "." << aVersion.version_minor() << "." << aVersion.version_maintenance() << "." << aVersion.version_build();
126 if (!aVersion.version_name().empty())
127 aStream << " " << aVersion.version_name();
128 return aStream;
129 }
130
131}
size_type size() const
Definition vecarray.hpp:441
uint32_t version_build() const
Definition version.hpp:106
uint32_t version_major() const
Definition version.hpp:94
const i_string & version_name() const
Definition version.hpp:110
version(const std::string &aVersionString="")
Definition version.hpp:56
version(const i_version &aOther)
Definition version.hpp:72
bool operator<(const version &aOther) const
Definition version.hpp:79
bool operator==(const version &aOther) const
Definition version.hpp:87
uint32_t version_maintenance() const
Definition version.hpp:102
version(uint32_t aMajor, uint32_t aMinor, uint32_t aMaintenance, uint32_t aBuild=0, const std::string &aName="")
Definition version.hpp:52
uint32_t version_minor() const
Definition version.hpp:98
bool operator>(const version &aOther) const
Definition version.hpp:83
FwdIter1 tokens(FwdIter1 aFirst, FwdIter1 aLast, FwdIter2 aDelimeterFirst, FwdIter2 aDelimiterLast, ResultContainer &aTokens, std::size_t aMaxTokens=0, bool aSkipEmptyTokens=true, bool aDelimeterIsSubsequence=false)
uint32_t string_to_uint32(const std::basic_string_view< CharT, Traits > &aStringView)