mirror of
https://github.com/aantron/better-enums.git
synced 2025-12-07 17:26:45 +08:00
Eliminated underscored internal macro names.
Also made a few documentation changes.
This commit is contained in:
parent
b24d155b7b
commit
41508fb114
15
README.md
15
README.md
@ -68,6 +68,21 @@ enums that are missing from standard C++.
|
|||||||
|
|
||||||
[performance]: http://aantron.github.io/better-enums/Performance.html
|
[performance]: http://aantron.github.io/better-enums/Performance.html
|
||||||
|
|
||||||
|
## Limitations
|
||||||
|
|
||||||
|
The biggest current limitation is that the `ENUM` macro can't be used inside a
|
||||||
|
class or namespace. This seems difficult to remove, but I am looking into it. In
|
||||||
|
the meantime, there is a workaround with a `typedef` (or `using`):
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
ENUM(UniquePrefix_Color, uint8_t, Red, Green, Blue)
|
||||||
|
|
||||||
|
struct triplet {
|
||||||
|
typedef UniquePrefix_Color Color;
|
||||||
|
Color r, g, b;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
## Contact
|
## Contact
|
||||||
|
|
||||||
Don't hesitate to contact me about features or bugs:
|
Don't hesitate to contact me about features or bugs:
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
||||||
<url>
|
|
||||||
<loc>http://aantron.github.io/better-enums</loc>
|
|
||||||
<priority>1.0</priority>
|
|
||||||
</url>
|
|
||||||
<url>
|
|
||||||
<loc>http://aantron.github.io/better-enums/api.html</loc>
|
|
||||||
</url>
|
|
||||||
</urlset>
|
|
||||||
@ -3,18 +3,20 @@
|
|||||||
# This file is part of Better Enums, released under the BSD 2-clause license.
|
# This file is part of Better Enums, released under the BSD 2-clause license.
|
||||||
# See LICENSE for details, or visit http://github.com/aantron/better-enums.
|
# See LICENSE for details, or visit http://github.com/aantron/better-enums.
|
||||||
|
|
||||||
# This script generates the macros _ENUM_PP_MAP and _ENUM_ITERATE, used
|
# You only need this script if you are developing enum.h, or run into a limit.
|
||||||
# internally by enum.h. These are already inlined into enum.h. You only need
|
|
||||||
# this script if you are developing enum.h, or run into a limit.
|
|
||||||
#
|
#
|
||||||
# _ENUM_PP_MAP has a limit, which determines the maximum number of constants an
|
# This script generates the macros BETTER_ENUMS__PP_MAP and
|
||||||
# enum can have. By default, this limit is 64 constants.
|
# BETTER_ENUMS__ITERATE, used internally by enum.h. These are already inlined
|
||||||
|
# into enum.h.
|
||||||
#
|
#
|
||||||
# _ENUM_ITERATE also has a limit. This one determines the maximum length of the
|
# BETTER_ENUMS__PP_MAP has a limit, which determines the maximum number of
|
||||||
# name of a constant that is followed by an initializer (" = 2") when compiling
|
# constants an enum can have. By default, this limit is 64 constants.
|
||||||
# an enum with constexpr to_string function (i.e. usually, this limit does not
|
#
|
||||||
# apply). By default, the limit is 23 characters (24 with the obligatory null
|
# BETTER_ENUMS__ITERATE also has a limit. This one determines the maximum length
|
||||||
# terminator).
|
# of the name of a constant that is followed by an initializer (" = 2") when
|
||||||
|
# compiling an enum with constexpr _to_string function (i.e. usually, this limit
|
||||||
|
# does not apply). By default, the limit is 23 characters (24 with the
|
||||||
|
# obligatory null terminator).
|
||||||
#
|
#
|
||||||
# If either of these limits is inadequate, you can still compile your code
|
# If either of these limits is inadequate, you can still compile your code
|
||||||
# without changing enum.h. You need to generate an external macro file with
|
# without changing enum.h. You need to generate an external macro file with
|
||||||
@ -28,7 +30,7 @@
|
|||||||
# 2. Build your code with an additional compiler flag:
|
# 2. Build your code with an additional compiler flag:
|
||||||
# - for gcc and clang, -DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>'
|
# - for gcc and clang, -DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>'
|
||||||
# - for VC++, /DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>'
|
# - for VC++, /DBETTER_ENUMS_MACRO_FILE='<MACRO_FILE>'
|
||||||
# or use any other method of getting these macros declared.
|
# or use any other method of getting these macros defined.
|
||||||
# 3. Compile your code. Your macro file should be included, and enum.h should
|
# 3. Compile your code. Your macro file should be included, and enum.h should
|
||||||
# happily work with whatever limits you chose.
|
# happily work with whatever limits you chose.
|
||||||
|
|
||||||
@ -66,35 +68,38 @@ def generate(stream, constants, length, script):
|
|||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#pragma once'
|
print >> stream, '#pragma once'
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#ifndef _BETTER_ENUM_MACRO_FILE_H_'
|
print >> stream, '#ifndef BETTER_ENUMS__MACRO_FILE_H'
|
||||||
print >> stream, '#define _BETTER_ENUM_MACRO_FILE_H_'
|
print >> stream, '#define BETTER_ENUMS__MACRO_FILE_H'
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#define _ENUM_PP_MAP(macro, data, ...) \\'
|
print >> stream, '#define BETTER_ENUMS__PP_MAP(macro, data, ...) \\'
|
||||||
print >> stream, ' _ENUM_ID(_ENUM_A(_ENUM_PP_MAP_VAR_COUNT, ' + \
|
print >> stream, ' BETTER_ENUMS__ID( \\'
|
||||||
'_ENUM_PP_COUNT(__VA_ARGS__)) \\'
|
print >> stream, ' BETTER_ENUMS__APPLY( \\'
|
||||||
|
print >> stream, ' BETTER_ENUMS__PP_MAP_VAR_COUNT, \\'
|
||||||
|
print >> stream, ' BETTER_ENUMS__PP_COUNT(__VA_ARGS__)) \\'
|
||||||
print >> stream, ' (macro, data, __VA_ARGS__))'
|
print >> stream, ' (macro, data, __VA_ARGS__))'
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#define _ENUM_PP_MAP_VAR_COUNT(count) ' + \
|
print >> stream, '#define BETTER_ENUMS__PP_MAP_VAR_COUNT(count) ' + \
|
||||||
'_ENUM_M ## count'
|
'BETTER_ENUMS__M ## count'
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#define _ENUM_A(macro, ...) _ENUM_ID(macro(__VA_ARGS__))'
|
print >> stream, '#define BETTER_ENUMS__APPLY(macro, ...) ' + \
|
||||||
|
'BETTER_ENUMS__ID(macro(__VA_ARGS__))'
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#define _ENUM_ID(x) x'
|
print >> stream, '#define BETTER_ENUMS__ID(x) x'
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#define _ENUM_M1(m, d, x) m(d,0,x)'
|
print >> stream, '#define BETTER_ENUMS__M1(m, d, x) m(d,0,x)'
|
||||||
for index in range(2, constants + 1):
|
for index in range(2, constants + 1):
|
||||||
print >> stream, '#define _ENUM_M' + str(index) + \
|
print >> stream, '#define BETTER_ENUMS__M' + str(index) + \
|
||||||
'(m,d,x,...) m(d,' + str(index - 1) + \
|
'(m,d,x,...) m(d,' + str(index - 1) + ',x) \\'
|
||||||
',x) _ENUM_ID(_ENUM_M' + str(index - 1) + \
|
print >> stream, ' BETTER_ENUMS__ID(BETTER_ENUMS__M' + \
|
||||||
'(m,d,__VA_ARGS__))'
|
str(index - 1) + '(m,d,__VA_ARGS__))'
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
pp_count_impl_prefix = '#define _ENUM_PP_COUNT_IMPL(_1,'
|
pp_count_impl_prefix = '#define BETTER_ENUMS__PP_COUNT_IMPL(_1,'
|
||||||
stream.write(pp_count_impl_prefix)
|
stream.write(pp_count_impl_prefix)
|
||||||
pp_count_impl = MultiLine(stream = stream, indent = 4,
|
pp_count_impl = MultiLine(stream = stream, indent = 4,
|
||||||
initial_column = len(pp_count_impl_prefix))
|
initial_column = len(pp_count_impl_prefix))
|
||||||
@ -106,10 +111,11 @@ def generate(stream, constants, length, script):
|
|||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
|
print >> stream, '#define BETTER_ENUMS__PP_COUNT(...) \\'
|
||||||
pp_count_prefix = \
|
pp_count_prefix = \
|
||||||
'#define _ENUM_PP_COUNT(...) _ENUM_ID(_ENUM_PP_COUNT_IMPL(__VA_ARGS__,'
|
' BETTER_ENUMS__ID(BETTER_ENUMS__PP_COUNT_IMPL(__VA_ARGS__,'
|
||||||
stream.write(pp_count_prefix)
|
stream.write(pp_count_prefix)
|
||||||
pp_count = MultiLine(stream = stream, indent = 4,
|
pp_count = MultiLine(stream = stream, indent = 8,
|
||||||
initial_column = len(pp_count_prefix))
|
initial_column = len(pp_count_prefix))
|
||||||
for index in range(0, constants - 1):
|
for index in range(0, constants - 1):
|
||||||
pp_count.write(' ' + str(constants - index) + ',')
|
pp_count.write(' ' + str(constants - index) + ',')
|
||||||
@ -117,7 +123,7 @@ def generate(stream, constants, length, script):
|
|||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
iterate_prefix = '#define _ENUM_ITERATE(X, f, l)'
|
iterate_prefix = '#define BETTER_ENUMS__ITERATE(X, f, l)'
|
||||||
stream.write(iterate_prefix)
|
stream.write(iterate_prefix)
|
||||||
iterate = MultiLine(stream = stream, indent = 4,
|
iterate = MultiLine(stream = stream, indent = 4,
|
||||||
initial_column = len(iterate_prefix))
|
initial_column = len(iterate_prefix))
|
||||||
@ -126,7 +132,7 @@ def generate(stream, constants, length, script):
|
|||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
|
|
||||||
print >> stream, ''
|
print >> stream, ''
|
||||||
print >> stream, '#endif // #ifndef _BETTER_ENUM_MACRO_FILE_H_'
|
print >> stream, '#endif // #ifndef BETTER_ENUMS__MACRO_FILE_H'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user