mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-06 16:56:42 +08:00
enum.h tries to automatically detect whether it is running with C++11 support. If not, it emits alternative code that is supposed to work on compilers supporting C++98 and variadic macros. This code is largely interface-compatible with the C++11 code, with the following semantic differences: - No compile-time stringization. This is done upon first use of a function other than to_integral. - Implicit conversion to integral types. This is due to the lack of enum class support. - The values _name, _names, _values are replaced with functions _name_, _names_, _values_.
227 lines
11 KiB
C++
227 lines
11 KiB
C++
#include <enum.h>
|
|
|
|
ENUM(Channel, int,
|
|
Red, Green, Blue, Cyan, Magenta, Yellow, Black, Hue, Saturation, Value);
|
|
|
|
ENUM(Direction, int,
|
|
North, East, South, West, NorthEast, SouthEast, SouthWest, NorthWest,
|
|
NorthNorthEast, EastNorthEast, EastSouthEast, SouthSouthEast,
|
|
SouthSouthWest, WestSouthWest, WestNorthWest, NorthNorthWest);
|
|
|
|
ENUM(ASTNode, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(State, int,
|
|
Attacking, Defending, Searching, Pursuing, Hungry, Fleeing, Confused,
|
|
Healing, Stunned);
|
|
|
|
ENUM(APIMethod, int,
|
|
ReadPost, WritePost, PollPost, ReadImage, WriteImage, PollImage, ReadKey,
|
|
WriteKey, PollKey, ReadUser, WriteUser, PollUser, ReadOrganization,
|
|
WriteOrganization, PollOrganization, ReadGroup, WriteGroup, PollGroup,
|
|
ReadProject, WriteProject, PollProject, ReadComment, WriteComment,
|
|
PollComment, ReadPermission, WritePermission, PollPermission, ReadOwner,
|
|
WriteOwner, PollOwner, ReadProposal, WriteProposal, PollProposal,
|
|
ReadHistory, WriteHistory, PollHistory);
|
|
|
|
ENUM(Region, int,
|
|
EasterEurope, CentralEurope, WesternEurope, Mediterranean, NorthAfrica,
|
|
MiddleEast, MiddleEastNorthAfrica, GreaterPersia, Balkans, Scandinavia,
|
|
NorhernEurope, BritishIsles, LatinEurope, Iberia, LowCountries, Baltics,
|
|
Yugoslavia, Caucasus, VolgaBasin, Urals, CentralAsia, Siberia,
|
|
RussianFarEast, EastAsia, SoutheastAsia, Indochina, SouthAsia,
|
|
IndianSubcontinent, Desi = IndianSubcontinent, Asia, Australasia, Oceania,
|
|
Micronesia, Polynesia, JapaneseIslands, Tibet, ArabianPeninsula,
|
|
HornOfAfrica, NearEast, AlSham, EastAfrica, NileBasin, Palestine, Levant,
|
|
Anatolia, AegeanSea, GreatSteppe, CongoBasin, SouthAfrica, WestAfrica,
|
|
Sahara, WestSahara, NorthwestTerritory, YukonAlaska, Quebec, NewEngland,
|
|
DeepSouth);
|
|
|
|
int main()
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
ENUM(ASTNode0, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode1, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode2, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode3, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode4, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode5, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode6, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode7, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode8, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode9, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode10, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode11, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode12, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode13, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode14, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode15, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode16, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode17, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode18, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode19, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode20, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode21, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode22, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode23, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode24, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode25, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode26, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode27, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode28, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|
|
|
|
ENUM(ASTNode29, int,
|
|
IntegerLiteral, StringLiteral, CharacterLiteral, Variable, UnaryOperation,
|
|
BinaryOperation, ApplicationExpression, Abstraction, LetBinding,
|
|
CaseExpression, Pattern, Signature, Module, Functor, TypeVariable,
|
|
BasicType, ArrowType, VariantTypeConstant);
|