Minor refactoring. (nw)

This commit is contained in:
couriersud 2017-01-27 18:36:45 +01:00
parent 5b0d4772a3
commit cb16de91c6
5 changed files with 37 additions and 45 deletions

View File

@ -17,6 +17,7 @@
#include "nl_config.h"
#include "plib/plists.h"
#include "plib/pchrono.h"
#include "plib/ptypes.h"
// ----------------------------------------------------------------------------------------
// timed queue

View File

@ -51,30 +51,6 @@ typedef __int128_t INT128;
// Standard defines
//============================================================
// prevent implicit copying
#if 0
#define P_PREVENT_COPYING(name) \
private: \
name(const name &); \
name(const name &&); \
name &operator=(const name &);
#else
namespace plib
{
struct nocopyassignmove
{
protected:
nocopyassignmove() = default;
~nocopyassignmove() = default;
private:
nocopyassignmove(const nocopyassignmove &) = delete;
nocopyassignmove(nocopyassignmove &&) = delete;
nocopyassignmove &operator=(const nocopyassignmove &) = delete;
};
}
#endif
//============================================================
// Pointer to Member Function
//============================================================

View File

@ -14,6 +14,14 @@
namespace plib {
P_ENUM(plog_level,
DEBUG,
INFO,
VERBOSE,
WARNING,
ERROR,
FATAL)
template <typename T>
struct ptype_traits_base
{
@ -175,14 +183,6 @@ private:
unsigned m_arg;
};
P_ENUM(plog_level,
DEBUG,
INFO,
VERBOSE,
WARNING,
ERROR,
FATAL)
class plog_dispatch_intf;
template <bool build_enabled = true>
@ -242,7 +242,7 @@ private:
};
template <plog_level::e L, bool build_enabled = true>
template <plog_level::E L, bool build_enabled = true>
class plog_channel : public pfmt_writer_t<build_enabled>
{
public:
@ -258,7 +258,7 @@ private:
class plog_dispatch_intf
{
template<plog_level::e, bool> friend class plog_channel;
template<plog_level::E, bool> friend class plog_channel;
public:
virtual ~plog_dispatch_intf();
@ -290,7 +290,7 @@ public:
};
template <plog_level::e L, bool build_enabled>
template <plog_level::E L, bool build_enabled>
void plog_channel<L, build_enabled>::vdowrite(const pstring &ls) const
{
m_base->vlog(L, ls);

View File

@ -39,11 +39,26 @@ namespace plib
};
#endif
//============================================================
// prevent implicit copying
//============================================================
struct nocopyassignmove
{
protected:
nocopyassignmove() = default;
~nocopyassignmove() = default;
private:
nocopyassignmove(const nocopyassignmove &) = delete;
nocopyassignmove(nocopyassignmove &&) = delete;
nocopyassignmove &operator=(const nocopyassignmove &) = delete;
};
//============================================================
// penum - strongly typed enumeration
//============================================================
struct enum_base
struct penum_base
{
protected:
static int from_string_int(const char *str, const char *x);
@ -53,22 +68,22 @@ namespace plib
}
#define P_ENUM(ename, ...) \
struct ename : public plib::enum_base { \
enum e { __VA_ARGS__ }; \
ename (e v) : m_v(v) { } \
struct ename : public plib::penum_base { \
enum E { __VA_ARGS__ }; \
ename (E v) : m_v(v) { } \
bool set_from_string (const pstring &s) { \
static const char *strings = # __VA_ARGS__; \
int f = from_string_int(strings, s.c_str()); \
if (f>=0) { m_v = static_cast<e>(f); return true; } else { return false; } \
if (f>=0) { m_v = static_cast<E>(f); return true; } else { return false; } \
} \
operator e() const {return m_v;} \
operator E() const {return m_v;} \
bool operator==(const ename &rhs) const {return m_v == rhs.m_v;} \
bool operator==(const e &rhs) const {return m_v == rhs;} \
bool operator==(const E &rhs) const {return m_v == rhs;} \
const pstring name() const { \
static const char *strings = # __VA_ARGS__; \
return nthstr(static_cast<int>(m_v), strings); \
} \
private: e m_v; };
private: E m_v; };
#endif /* PTYPES_H_ */

View File

@ -104,7 +104,7 @@ namespace plib
}
int enum_base::from_string_int(const char *str, const char *x)
int penum_base::from_string_int(const char *str, const char *x)
{
int cnt = 0;
const char *cur = str;
@ -131,7 +131,7 @@ namespace plib
return cnt;
return -1;
}
pstring enum_base::nthstr(int n, const char *str)
pstring penum_base::nthstr(int n, const char *str)
{
char buf[64];
char *bufp = buf;