NDEVR
API Documentation
StringEnum.h
1#pragma once
2#include <NDEVR/String.h>
3#include <NDEVR/StringView.h>
4#include <NDEVR/StringStream.h>
5namespace NDEVR
6{
11 {};
12
15 #define NDEVR_DECLARE_ENUM_ITEM(name) name ,
19 #define NDEVR_DECLARE_ENUM(EnumName, ITEMS_MACRO) \
20 enum class EnumName \
21 { \
22 ITEMS_MACRO(NDEVR_DECLARE_ENUM_ITEM) \
23 e_size \
24 };
28 #define _FROMSTRINGCASE(name) case String::hash(#name): v = t_enum::name; break;
32 #define _TOSTRINGCASE(name) case t_enum::name: s.referencedAppend(#name); break;
37 #define NDEVR_DEFINE_STRING_STREAM(EnumName, ITEMS_MACRO) \
38 NDEVR_DECLARE_ENUM(EnumName, ITEMS_MACRO) \
39 template<> inline void StringStream<EnumName>::fromString( \
40 const StringView& s, EnumName& v) \
41 { \
42 typedef EnumName t_enum; \
43 switch (s.hash()) { \
44 ITEMS_MACRO(_FROMSTRINGCASE) \
45 default: \
46 lib_assert(false, "Bad enum"); \
47 v = cast<EnumName>(s.getAs<uint04>()); \
48 break; \
49 } \
50 } \
51 template<> inline void StringStream<EnumName>::toString( \
52 const EnumName& v, StringAllocatingView& s) \
53 { \
54 typedef EnumName t_enum; \
55 switch (v) { \
56 ITEMS_MACRO(_TOSTRINGCASE) \
57 default: lib_assert(false, "Unknown enum"); break; \
58 } \
59 }
60
61 /* We can use the above macros like this to automatically stringify enums
62 #define DXFPOINTMODE_ITEMS(X) \
63 X(e_point) \
64 X(e_station) \
65 X(e_90_cross_hair_square) \
66 X(e_45_cross_hair_square) \
67 X(e_90_cross_hair_circle) \
68 X(e_45_cross_hair_circle)
69 NDEVR_DEFINE_STRING_STREAM(DXFPointMode, DXFPOINTMODE_ITEMS)
70 */
71}
Empty tag class used as a base for string-convertible enumerations defined via macros.
Definition StringEnum.h:11
The primary namespace for the NDEVR SDK.