Loading...   

  • Created By Uleat On: 07:40 PM August 08, 2015
  • Link

/*
EQEMu:  Everquest Server Emulator

Copyright (C) 2001-2015 EQEMu Development Team (http://eqemulator.net)

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

#pragma once

#include <forward_list>
#include <string>

#include "typedefs.h"

template<typename V, typename B> class IEnumBase
{
public:
	virtual ~IEnumBase() = 0;

protected:
	typedef V _v; // value integral type
	typedef B _b; // bitmask integral type (void if not implemented)

public:
	static bool IsValid(_v enumValue) = 0;
	static _v Validate(_v enumValue) = 0;

	static _b ValueToBitmask(_v enumValue) {
		return 0;
	}

	static _v BitmaskToValue(_b enumBitmask) {
		return 0;
	}

	static std::string ValueToString(_v enumValue) {
		return "<no string data>";
	}

	static std::string BitmaskToString(_b enumBitmask) {
		return "<no string data>";
	}
};

template<typename D, typename V, typename B> class IEnumIterable : public virtual IEnumBase<V, B>
{
public:
	virtual ~IEnumIterable() = 0;

protected:
	//typedef D _d; // derived enum class type (throw away template parameter - enforces unique static forward list)

	typedef std::forward_list<_v> _fl;
	typedef _fl::const_iterator _flci;

	static void populate_fl() = 0;

	static _fl m_fl;

	static _flci const _cb() {
		populate_fl();
		return m_fl.cbegin();
	}

	static _flci const _ce() {
		populate_fl();
		return m_fl.cend();
	}

public:
	static _flci const cbegin() = 0;
	static _flci const cend() = 0;
};

template<typename V, typename B> class IEnumInstantiable : public virtual IEnumBase<V, B>
{
public:
	virtual ~IEnumInstantiable() = 0;

protected:
	void set(_v enumValue) {
		m_v = Validate(enumValue);
		m_b = ValueToBitmask(m_v);
	}

	_v get_v() {
		return m_v;
	}

	_b get_b() {
		return m_b;
	}

private:
	_v m_v;
	_b m_b;

public:
	void value(_v enumValue) = 0;
	_v value() = 0;

	_b bitmask() {
		return 0;
	}
};

template<typename D, typename V, typename B> class IEnumBaseII : public IEnumInstantiable<V, B>, public IEnumIterable<D, V, B>
{
public:
	virtual ~IEnumBaseII() = 0;
};

Raw Paste Data