libcruft-util/version.hpp

74 lines
2.1 KiB
C++
Raw Normal View History

2011-05-23 17:18:52 +10:00
/*
2015-04-13 18:05:28 +10:00
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
2011-05-23 17:18:52 +10:00
*
2015-04-13 18:05:28 +10:00
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
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
*/
#ifndef __UTIL_VERSION_HPP
#define __UTIL_VERSION_HPP
2011-05-23 17:18:52 +10:00
#include <array>
2011-05-23 17:18:52 +10:00
#include <string>
#include <iostream>
namespace util {
2013-08-05 21:46:11 +10:00
struct version {
enum release_t {
RELEASE_ALPHA,
RELEASE_BETA,
RELEASE_GAMMA,
RELEASE_PRODUCTION
};
version ();
version (unsigned int _major, unsigned int _minor);
version (const std::string& str);
version (const char *str);
void sanity (void) const;
enum {
OFFSET_MAJOR = 0,
OFFSET_MINOR = 1,
OFFSET_POINT = 2,
OFFSET_BUILD = 3,
NUM_OFFSETS
};
unsigned major (void) const { return values[OFFSET_MAJOR]; }
unsigned minor (void) const { return values[OFFSET_MINOR]; }
unsigned point (void) const { return values[OFFSET_POINT]; }
unsigned build (void) const { return values[OFFSET_BUILD]; }
std::array<unsigned int, NUM_OFFSETS> values;
size_t size;
release_t release;
static version parse (const std::string&);
static version parse (const char*);
bool operator < (const version& rhs) const;
bool operator > (const version& rhs) const;
bool operator >= (const version& rhs) const;
bool operator <= (const version& rhs) const;
bool operator == (const version& rhs) const;
};
}
2013-08-05 21:46:11 +10:00
std::ostream& operator<< (std::ostream& os, const util::version& rhs);
2011-05-23 17:18:52 +10:00
#endif // __VERSION_HPP