From df3642b832dec73cf00e6a353ad134d3b132f4b1 Mon Sep 17 00:00:00 2001 From: isotes Date: Fri, 19 Feb 2016 23:51:00 +0100 Subject: Generate MIN/MAX/ARRAYSIZE for enums This generates #defines mirroring the following values from the generated C++ code of GPB * const Foo Foo_MIN: the smallest valid value of the enum (VALUE_A in the example). * const Foo Foo_MAX: the largest valid value of the enum (VALUE_C in the example). * const Foo Foo_ARRAYSIZE: always defined as Foo_MAX + 1. --- generator/nanopb_generator.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'generator') diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index bc9e9da..0e9b018 100755 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -197,6 +197,10 @@ class Enum: result += ' %s;' % self.names + result += '\n#define _%s_MIN %s' % (self.names, self.values[0][0]) + result += '\n#define _%s_MAX %s' % (self.names, self.values[-1][0]) + result += '\n#define _%s_ARRAYSIZE ((%s)(%s+1))' % (self.names, self.names, self.values[-1][0]) + if not self.options.long_names: # Define the long names always so that enum value references # from other files work properly. -- cgit 1.2.3-korg