Use an array not a vector for components
This commit is contained in:
parent
20e8297768
commit
1c251699c3
@ -32,25 +32,26 @@ using namespace util;
|
||||
|
||||
version::version (unsigned int _major,
|
||||
unsigned int _minor):
|
||||
m_values (2),
|
||||
m_release (RELEASE_PRODUCTION) {
|
||||
m_size (2),
|
||||
m_release (RELEASE_PRODUCTION)
|
||||
{
|
||||
m_values[OFFSET_MAJOR] = _major;
|
||||
m_values[OFFSET_MINOR] = _minor;
|
||||
}
|
||||
|
||||
|
||||
version::version (const string& str):
|
||||
m_values (NUM_OFFSETS, 0),
|
||||
m_release (RELEASE_PRODUCTION) {
|
||||
m_values.clear ();
|
||||
m_size (0),
|
||||
m_release (RELEASE_PRODUCTION)
|
||||
{
|
||||
parse (str);
|
||||
}
|
||||
|
||||
|
||||
version::version (const char *str):
|
||||
m_values (NUM_OFFSETS, 0),
|
||||
m_release (RELEASE_PRODUCTION) {
|
||||
m_values.clear ();
|
||||
m_size (0),
|
||||
m_release (RELEASE_PRODUCTION)
|
||||
{
|
||||
parse (str);
|
||||
}
|
||||
|
||||
@ -72,7 +73,7 @@ check_release (version::release_t r) {
|
||||
void
|
||||
version::sanity (void) const {
|
||||
check_release (m_release);
|
||||
CHECK (!m_values.empty ());
|
||||
CHECK (m_size > 0);
|
||||
}
|
||||
|
||||
|
||||
@ -85,7 +86,7 @@ version::sanity (void) const {
|
||||
{ current *= 10;
|
||||
current += (uintptr_t)(fc - (unsigned char)'0'); }
|
||||
action finish
|
||||
{ m_values.push_back (current); }
|
||||
{ m_values[m_size++] = current; }
|
||||
|
||||
number = (digit+)
|
||||
>clear
|
||||
|
22
version.hpp
22
version.hpp
@ -17,11 +17,11 @@
|
||||
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef __VERSION_HPP
|
||||
#define __VERSION_HPP
|
||||
#ifndef __UTIL_VERSION_HPP
|
||||
#define __UTIL_VERSION_HPP
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
@ -54,22 +54,20 @@ namespace util {
|
||||
NUM_OFFSETS
|
||||
};
|
||||
|
||||
std::vector <unsigned int> m_values;
|
||||
std::array<unsigned int, NUM_OFFSETS> m_values;
|
||||
size_t m_size;
|
||||
release_t m_release;
|
||||
|
||||
void parse (const std::string&);
|
||||
void parse (const char*);
|
||||
|
||||
public:
|
||||
unsigned int major (void) const { return m_values[OFFSET_MAJOR]; }
|
||||
unsigned int minor (void) const { return m_values[OFFSET_MINOR]; }
|
||||
unsigned int point (void) const { return m_values[OFFSET_POINT]; }
|
||||
unsigned int build (void) const { return m_values[OFFSET_BUILD]; }
|
||||
|
||||
unsigned int major (void) const
|
||||
{ return m_values[OFFSET_MAJOR]; }
|
||||
unsigned int minor (void) const
|
||||
{ return m_values[OFFSET_MINOR]; }
|
||||
unsigned int point (void) const
|
||||
{ return m_values[OFFSET_POINT]; }
|
||||
unsigned int build (void) const
|
||||
{ return m_values[OFFSET_BUILD]; }
|
||||
size_t size (void) const { return m_size; }
|
||||
|
||||
bool operator < (const version& rhs) const;
|
||||
bool operator > (const version& rhs) const;
|
||||
|
Loading…
Reference in New Issue
Block a user