blob: 998944406ae9f042d940cde7f93ca3f78e05a124 [file] [log] [blame]
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +00001// Protocol Buffers - Google's data interchange format
2// Copyright 2008 Google Inc. All rights reserved.
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +00003//
Joshua Habermanccb11732023-09-11 13:45:07 -07004// 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.comb55a20f2012-09-22 02:40:50 +00007
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 Kruskala3c8e2d2022-08-24 10:46:33 -070021#include "absl/strings/string_view.h"
Mike Kruskal15954172022-09-09 10:42:19 -070022#include "google/protobuf/generated_enum_util.h"
Protobuf Team Bot68f9d842023-08-22 08:03:51 -070023#include "google/protobuf/port.h"
jieluo@google.com4de8f552014-07-18 00:47:59 +000024
Feng Xiao6bbe1972018-08-08 17:00:41 -070025#ifdef SWIG
26#error "You cannot SWIG proto headers"
27#endif
28
Deanna Garciaab4585a2022-02-01 18:24:53 +000029// Must be included last.
Mike Kruskal15954172022-09-09 10:42:19 -070030#include "google/protobuf/port_def.inc"
Josh Habermand61aede2018-09-04 10:58:54 -070031
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000032namespace google {
33namespace protobuf {
Hao Nguyen176f7db2019-04-09 06:23:32 -070034class EnumDescriptor;
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000035} // namespace protobuf
Feng Xiao6bbe1972018-08-08 17:00:41 -070036} // namespace google
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000037
Feng Xiao6bbe1972018-08-08 17:00:41 -070038namespace google {
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000039namespace protobuf {
40
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000041// 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.
44template <typename E>
45const EnumDescriptor* GetEnumDescriptor();
46
47namespace internal {
48
Hao Nguyend0f91c82019-03-06 12:39:12 -080049// 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 Habermand61aede2018-09-04 10:58:54 -070052PROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor,
Mike Kruskala3c8e2d2022-08-24 10:46:33 -070053 absl::string_view name, int* value);
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000054
Hao Nguyend0f91c82019-03-06 12:39:12 -080055template <typename EnumType>
Mike Kruskala3c8e2d2022-08-24 10:46:33 -070056bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name,
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000057 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 Habermand61aede2018-09-04 10:58:54 -070067PROTOBUF_EXPORT const std::string& NameOfEnum(const EnumDescriptor* descriptor,
Hao Nguyend0f91c82019-03-06 12:39:12 -080068 int value);
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000069
70} // namespace internal
71} // namespace protobuf
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000072} // namespace google
Feng Xiao6bbe1972018-08-08 17:00:41 -070073
Mike Kruskal15954172022-09-09 10:42:19 -070074#include "google/protobuf/port_undef.inc"
Josh Habermand61aede2018-09-04 10:58:54 -070075
xiaofeng@google.comb55a20f2012-09-22 02:40:50 +000076#endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__