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,13 +22,15 @@
#include "debug.hpp"
class nocopy {
namespace util {
class nocopy {
public:
nocopy () { ; }
private:
nocopy (const nocopy &) = delete;
nocopy& operator =(const nocopy &) = delete;
};
};
}
#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.
template class pool<std::string>;
template class util::pool<std::string>;

View File

@ -22,9 +22,9 @@
#include "nocopy.hpp"
namespace util {
template <typename T>
class pool : public nocopy {
class pool : public nocopy {
protected:
union node {
char _data[sizeof (T)];
@ -94,7 +94,7 @@ class pool : public nocopy {
newnode->_chain = m_next;
m_next = newnode;
}
};
};
}
#endif // __UTIL_POOL_HPP

View File

@ -20,12 +20,14 @@
#include "version.hpp"
#include <cstring>
#include <stdexcept>
#include "debug.hpp"
using namespace std;
using namespace util;
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
check_release (version::release_t 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
release_string (const version::release_t r) {
switch (r) {
@ -140,8 +164,9 @@ version::operator > (const version &rhs) const {
}
ostream&
operator <<(ostream& os, const version& rhs) {
namespace util {
ostream&
operator <<(ostream& os, const util::version& rhs) {
auto i = rhs.m_values.begin();
os << *i; ++i;
@ -150,5 +175,6 @@ operator <<(ostream& os, const version& rhs) {
os << release_string (rhs.m_release);
return os;
}
}

View File

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