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,
|
version::version (unsigned int _major,
|
||||||
unsigned int _minor):
|
unsigned int _minor):
|
||||||
m_values (2),
|
m_size (2),
|
||||||
m_release (RELEASE_PRODUCTION) {
|
m_release (RELEASE_PRODUCTION)
|
||||||
|
{
|
||||||
m_values[OFFSET_MAJOR] = _major;
|
m_values[OFFSET_MAJOR] = _major;
|
||||||
m_values[OFFSET_MINOR] = _minor;
|
m_values[OFFSET_MINOR] = _minor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
version::version (const string& str):
|
version::version (const string& str):
|
||||||
m_values (NUM_OFFSETS, 0),
|
m_size (0),
|
||||||
m_release (RELEASE_PRODUCTION) {
|
m_release (RELEASE_PRODUCTION)
|
||||||
m_values.clear ();
|
{
|
||||||
parse (str);
|
parse (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
version::version (const char *str):
|
version::version (const char *str):
|
||||||
m_values (NUM_OFFSETS, 0),
|
m_size (0),
|
||||||
m_release (RELEASE_PRODUCTION) {
|
m_release (RELEASE_PRODUCTION)
|
||||||
m_values.clear ();
|
{
|
||||||
parse (str);
|
parse (str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ check_release (version::release_t r) {
|
|||||||
void
|
void
|
||||||
version::sanity (void) const {
|
version::sanity (void) const {
|
||||||
check_release (m_release);
|
check_release (m_release);
|
||||||
CHECK (!m_values.empty ());
|
CHECK (m_size > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ version::sanity (void) const {
|
|||||||
{ current *= 10;
|
{ current *= 10;
|
||||||
current += (uintptr_t)(fc - (unsigned char)'0'); }
|
current += (uintptr_t)(fc - (unsigned char)'0'); }
|
||||||
action finish
|
action finish
|
||||||
{ m_values.push_back (current); }
|
{ m_values[m_size++] = current; }
|
||||||
|
|
||||||
number = (digit+)
|
number = (digit+)
|
||||||
>clear
|
>clear
|
||||||
@ -101,7 +102,7 @@ version::sanity (void) const {
|
|||||||
version := (dots type?)
|
version := (dots type?)
|
||||||
$!{ throw invalid_argument (str); };
|
$!{ throw invalid_argument (str); };
|
||||||
|
|
||||||
write data;
|
write data;
|
||||||
}%%
|
}%%
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +148,7 @@ release_string (const version::release_t r) {
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
version::operator > (const version &rhs) const {
|
version::operator> (const version &rhs) const {
|
||||||
unsigned int count = min (m_values.size (), rhs.m_values.size ());
|
unsigned int count = min (m_values.size (), rhs.m_values.size ());
|
||||||
|
|
||||||
for (unsigned int i = 0; i < count; ++i)
|
for (unsigned int i = 0; i < count; ++i)
|
||||||
|
24
version.hpp
24
version.hpp
@ -17,11 +17,11 @@
|
|||||||
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2010 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __VERSION_HPP
|
#ifndef __UTIL_VERSION_HPP
|
||||||
#define __VERSION_HPP
|
#define __UTIL_VERSION_HPP
|
||||||
|
|
||||||
|
#include <array>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
@ -54,22 +54,20 @@ namespace util {
|
|||||||
NUM_OFFSETS
|
NUM_OFFSETS
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector <unsigned int> m_values;
|
std::array<unsigned int, NUM_OFFSETS> m_values;
|
||||||
release_t m_release;
|
size_t m_size;
|
||||||
|
release_t m_release;
|
||||||
|
|
||||||
void parse (const std::string&);
|
void parse (const std::string&);
|
||||||
void parse (const char*);
|
void parse (const char*);
|
||||||
|
|
||||||
public:
|
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
|
size_t size (void) const { return m_size; }
|
||||||
{ 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]; }
|
|
||||||
|
|
||||||
bool operator < (const version& rhs) const;
|
bool operator < (const version& rhs) const;
|
||||||
bool operator > (const version& rhs) const;
|
bool operator > (const version& rhs) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user