2011-05-23 17:18:52 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2011-05-23 17:18:52 +10:00
|
|
|
*
|
2012-04-23 13:06:41 +10:00
|
|
|
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
2011-05-23 17:18:52 +10:00
|
|
|
*/
|
|
|
|
|
2021-04-14 15:35:49 +10:00
|
|
|
#pragma once
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2012-07-30 16:32:32 +10:00
|
|
|
#include <array>
|
2011-05-23 17:18:52 +10:00
|
|
|
#include <string>
|
2018-03-22 16:10:06 +11:00
|
|
|
#include <iosfwd>
|
2016-01-19 18:31:35 +11:00
|
|
|
#include <limits>
|
2011-05-23 17:18:52 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft {
|
2013-08-05 21:46:11 +10:00
|
|
|
struct version {
|
2016-01-19 18:31:35 +11:00
|
|
|
// underlying component value type
|
|
|
|
using value_t = unsigned;
|
|
|
|
|
|
|
|
static_assert (std::numeric_limits<value_t>::max () >= 2100'00'00,
|
|
|
|
"value_t must be sufficient to store a reasonable future year in YYYYMMDD format");
|
|
|
|
|
|
|
|
/// type of release.
|
|
|
|
///
|
|
|
|
/// * must be sorted from earliest to latest
|
|
|
|
/// * specific values aren't currently guaranteed.
|
2013-08-05 21:46:11 +10:00
|
|
|
enum release_t {
|
2016-01-19 18:31:35 +11:00
|
|
|
ALPHA,
|
|
|
|
BETA,
|
|
|
|
GAMMA,
|
|
|
|
PRODUCTION
|
2013-08-05 21:46:11 +10:00
|
|
|
};
|
|
|
|
|
|
|
|
version ();
|
2016-06-20 13:08:24 +10:00
|
|
|
version (unsigned _major);
|
|
|
|
version (unsigned _major, unsigned _minor);
|
|
|
|
version (unsigned _major, unsigned _minor, unsigned _point);
|
|
|
|
version (unsigned _major, unsigned _minor, unsigned _point, unsigned _build);
|
2015-06-04 22:18:43 +10:00
|
|
|
explicit version (const std::string& str);
|
|
|
|
explicit version (const char *str);
|
2013-08-05 21:46:11 +10:00
|
|
|
|
|
|
|
void sanity (void) const;
|
|
|
|
|
2016-01-19 18:31:35 +11:00
|
|
|
// named component indices
|
|
|
|
//
|
|
|
|
// * must start from zero and be monotonically increasing
|
|
|
|
enum offset_t {
|
|
|
|
MAJOR = 0,
|
|
|
|
MINOR = 1,
|
|
|
|
POINT = 2,
|
|
|
|
BUILD = 3
|
2013-08-05 21:46:11 +10:00
|
|
|
};
|
|
|
|
|
2016-05-13 15:23:38 +10:00
|
|
|
// fuck you too freebsd
|
|
|
|
#ifdef major
|
|
|
|
#undef major
|
|
|
|
#endif
|
|
|
|
#ifdef minor
|
|
|
|
#undef minor
|
|
|
|
#endif
|
|
|
|
|
2016-01-19 18:31:35 +11:00
|
|
|
unsigned major (void) const;
|
|
|
|
unsigned minor (void) const;
|
|
|
|
unsigned point (void) const;
|
|
|
|
unsigned build (void) const;
|
|
|
|
|
2016-06-20 13:08:24 +10:00
|
|
|
const unsigned* begin (void) const noexcept;
|
|
|
|
const unsigned* end (void) const noexcept;
|
|
|
|
const unsigned* cbegin (void) const noexcept;
|
|
|
|
const unsigned* cend (void) const noexcept;
|
|
|
|
|
|
|
|
const unsigned& operator[] (size_t) const;
|
|
|
|
unsigned& operator[] (size_t);
|
2013-08-05 21:46:11 +10:00
|
|
|
|
|
|
|
size_t size;
|
2016-01-19 18:31:35 +11:00
|
|
|
std::array<unsigned,4u> components;
|
2016-06-20 13:08:24 +10:00
|
|
|
release_t release = PRODUCTION;
|
2013-08-05 21:46:11 +10:00
|
|
|
|
|
|
|
static version parse (const std::string&);
|
|
|
|
static version parse (const char*);
|
|
|
|
|
2016-06-20 13:08:24 +10:00
|
|
|
bool operator< (const version& rhs) const noexcept;
|
|
|
|
bool operator> (const version& rhs) const noexcept;
|
|
|
|
bool operator>= (const version& rhs) const noexcept;
|
|
|
|
bool operator<= (const version& rhs) const noexcept;
|
|
|
|
bool operator== (const version& rhs) const noexcept;
|
2011-10-07 21:58:16 +11:00
|
|
|
};
|
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
std::ostream& operator<< (std::ostream& os, const cruft::version& rhs);
|
2021-04-14 15:35:49 +10:00
|
|
|
}
|