Use the util namespace for more classes

This commit is contained in:
Danny Robson 2011-10-07 21:58:16 +11:00
parent 6e2ba427f9
commit 641a15f0ec
6 changed files with 154 additions and 147 deletions

View File

@ -22,6 +22,7 @@
#include "debug.hpp" #include "debug.hpp"
namespace util {
class nocopy { class nocopy {
public: public:
nocopy () { ; } nocopy () { ; }
@ -30,5 +31,6 @@ class nocopy {
nocopy (const nocopy &) = delete; nocopy (const nocopy &) = delete;
nocopy& operator =(const nocopy &) = delete; nocopy& operator =(const nocopy &) = delete;
}; };
}
#endif #endif

View File

@ -1,23 +0,0 @@
// Derived from boost::noncopyable
//
// (C) Copyright Beman Dawes 1999-2003. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Contributed by Dave Abrahams
#ifndef __UTIL_NONCOPYABLE_HPP
#define __UTIL_NONCOPYABLE_HPP
class noncopyable
{
protected:
noncopyable() {}
~noncopyable() {}
private: // emphasize the following members are private
noncopyable( const noncopyable& );
const noncopyable& operator=( const noncopyable& );
};
#endif

View File

@ -22,4 +22,4 @@
// Explicitly instance a possibly useful specialisation so that we can more easily catch linker errors. // Explicitly instance a possibly useful specialisation so that we can more easily catch linker errors.
template class pool<std::string>; template class util::pool<std::string>;

View File

@ -22,7 +22,7 @@
#include "nocopy.hpp" #include "nocopy.hpp"
namespace util {
template <typename T> template <typename T>
class pool : public nocopy { class pool : public nocopy {
protected: protected:
@ -95,6 +95,6 @@ class pool : public nocopy {
m_next = newnode; m_next = newnode;
} }
}; };
}
#endif // __UTIL_POOL_HPP #endif // __UTIL_POOL_HPP

View File

@ -20,12 +20,14 @@
#include "version.hpp" #include "version.hpp"
#include <cstring>
#include <stdexcept> #include <stdexcept>
#include "debug.hpp" #include "debug.hpp"
using namespace std; using namespace std;
using namespace util;
version::version (unsigned int _major, version::version (unsigned int _major,
@ -45,6 +47,14 @@ version::version (const string& str):
} }
version::version (const char *str):
m_values (NUM_OFFSETS, 0),
m_release (RELEASE_PRODUCTION) {
m_values.clear ();
parse (str);
}
static void static void
check_release (version::release_t r) { check_release (version::release_t r) {
switch (r) { switch (r) {
@ -109,6 +119,20 @@ version::parse (const string& str) {
} }
void
version::parse (const char *str) {
unsigned int current;
size_t cs;
const char *p = str,
*pe = str + strlen (str),
*eof = pe;
%%write init;
%%write exec;
}
static string static string
release_string (const version::release_t r) { release_string (const version::release_t r) {
switch (r) { switch (r) {
@ -140,8 +164,9 @@ version::operator > (const version &rhs) const {
} }
namespace util {
ostream& ostream&
operator <<(ostream& os, const version& rhs) { operator <<(ostream& os, const util::version& rhs) {
auto i = rhs.m_values.begin(); auto i = rhs.m_values.begin();
os << *i; ++i; os << *i; ++i;
@ -151,4 +176,5 @@ operator <<(ostream& os, const version& rhs) {
os << release_string (rhs.m_release); os << release_string (rhs.m_release);
return os; return os;
} }
}

View File

@ -25,6 +25,7 @@
#include <iostream> #include <iostream>
namespace util {
class version { class version {
public: public:
enum release_t { enum release_t {
@ -37,6 +38,8 @@ class version {
version (unsigned int _major, version (unsigned int _major,
unsigned int _minor); unsigned int _minor);
version (const std::string& str); version (const std::string& str);
version (const char *str);
virtual ~version () { ; } virtual ~version () { ; }
virtual void sanity (void) const; virtual void sanity (void) const;
@ -55,6 +58,7 @@ class version {
release_t m_release; release_t m_release;
void parse (const std::string&); void parse (const std::string&);
void parse (const char*);
public: public:
@ -78,9 +82,7 @@ class version {
friend std::ostream& friend std::ostream&
operator <<(std::ostream& os, const version& rhs); operator <<(std::ostream& os, const version& rhs);
}; };
}
std::ostream&
operator <<(std::ostream& os, const version& rhs);
#endif // __VERSION_HPP #endif // __VERSION_HPP