xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2008 Google Inc. All rights reserved. |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 3 | // |
Joshua Haberman | ccb1173 | 2023-09-11 13:45:07 -0700 | [diff] [blame] | 4 | // Use of this source code is governed by a BSD-style |
| 5 | // license that can be found in the LICENSE file or at |
| 6 | // https://developers.google.com/open-source/licenses/bsd |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 7 | |
| 8 | // Author: jasonh@google.com (Jason Hsueh) |
| 9 | // |
| 10 | // This header is logically internal, but is made public because it is used |
| 11 | // from protocol-compiler-generated code, which may reside in other components. |
| 12 | // It provides reflection support for generated enums, and is included in |
| 13 | // generated .pb.h files and should have minimal dependencies. The methods are |
| 14 | // implemented in generated_message_reflection.cc. |
| 15 | |
| 16 | #ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ |
| 17 | #define GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ |
| 18 | |
| 19 | #include <string> |
| 20 | |
Mike Kruskal | a3c8e2d | 2022-08-24 10:46:33 -0700 | [diff] [blame] | 21 | #include "absl/strings/string_view.h" |
Mike Kruskal | 1595417 | 2022-09-09 10:42:19 -0700 | [diff] [blame] | 22 | #include "google/protobuf/generated_enum_util.h" |
Protobuf Team Bot | 68f9d84 | 2023-08-22 08:03:51 -0700 | [diff] [blame] | 23 | #include "google/protobuf/port.h" |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 24 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 25 | #ifdef SWIG |
| 26 | #error "You cannot SWIG proto headers" |
| 27 | #endif |
| 28 | |
Deanna Garcia | ab4585a | 2022-02-01 18:24:53 +0000 | [diff] [blame] | 29 | // Must be included last. |
Mike Kruskal | 1595417 | 2022-09-09 10:42:19 -0700 | [diff] [blame] | 30 | #include "google/protobuf/port_def.inc" |
Josh Haberman | d61aede | 2018-09-04 10:58:54 -0700 | [diff] [blame] | 31 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 32 | namespace google { |
| 33 | namespace protobuf { |
Hao Nguyen | 176f7db | 2019-04-09 06:23:32 -0700 | [diff] [blame] | 34 | class EnumDescriptor; |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 35 | } // namespace protobuf |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 36 | } // namespace google |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 37 | |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 38 | namespace google { |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 39 | namespace protobuf { |
| 40 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 41 | // Returns the EnumDescriptor for enum type E, which must be a |
| 42 | // proto-declared enum type. Code generated by the protocol compiler |
| 43 | // will include specializations of this template for each enum type declared. |
| 44 | template <typename E> |
| 45 | const EnumDescriptor* GetEnumDescriptor(); |
| 46 | |
| 47 | namespace internal { |
| 48 | |
Hao Nguyen | d0f91c8 | 2019-03-06 12:39:12 -0800 | [diff] [blame] | 49 | // Helper for EnumType_Parse functions: try to parse the string 'name' as |
| 50 | // an enum name of the given type, returning true and filling in value on |
| 51 | // success, or returning false and leaving value unchanged on failure. |
Josh Haberman | d61aede | 2018-09-04 10:58:54 -0700 | [diff] [blame] | 52 | PROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor, |
Mike Kruskal | a3c8e2d | 2022-08-24 10:46:33 -0700 | [diff] [blame] | 53 | absl::string_view name, int* value); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 54 | |
Hao Nguyen | d0f91c8 | 2019-03-06 12:39:12 -0800 | [diff] [blame] | 55 | template <typename EnumType> |
Mike Kruskal | a3c8e2d | 2022-08-24 10:46:33 -0700 | [diff] [blame] | 56 | bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 57 | EnumType* value) { |
| 58 | int tmp; |
| 59 | if (!ParseNamedEnum(descriptor, name, &tmp)) return false; |
| 60 | *value = static_cast<EnumType>(tmp); |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | // Just a wrapper around printing the name of a value. The main point of this |
| 65 | // function is not to be inlined, so that you can do this without including |
| 66 | // descriptor.h. |
Josh Haberman | d61aede | 2018-09-04 10:58:54 -0700 | [diff] [blame] | 67 | PROTOBUF_EXPORT const std::string& NameOfEnum(const EnumDescriptor* descriptor, |
Hao Nguyen | d0f91c8 | 2019-03-06 12:39:12 -0800 | [diff] [blame] | 68 | int value); |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 69 | |
| 70 | } // namespace internal |
| 71 | } // namespace protobuf |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 72 | } // namespace google |
Feng Xiao | 6bbe197 | 2018-08-08 17:00:41 -0700 | [diff] [blame] | 73 | |
Mike Kruskal | 1595417 | 2022-09-09 10:42:19 -0700 | [diff] [blame] | 74 | #include "google/protobuf/port_undef.inc" |
Josh Haberman | d61aede | 2018-09-04 10:58:54 -0700 | [diff] [blame] | 75 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 76 | #endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ |