A super-easy macro to define 'enum' value and its 'string' representation in C++
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
LICENSE
README.md
enum.cpp
enum.h

README.md

An ultimate 'enum' for C++

Usage

  • Include the 'enum.h' header file.
  • Define an 'enum' value like this:
struct CpuType
{
	enum Type
	{
		INTEL,
		AMD,
		ARM,
		UNDEFINED,
	};
};
  • Map the enum value and string:
ENUM_BEGIN(CpuType, UNDEFINED)
	ENUM_ITEM(CpuType, INTEL)
	ENUM_ITEM(CpuType, AMD)
	ENUM_ITEM(CpuType, ARM)
ENUM_END
  • Convert from an enum value to a string:
EnumConverter< CpuType::Type >::FromString("INTEL")
  • Convert from a string to an enum value:
EnumConverter< CpuType::Type >::ToString(intelCpuType)