|
||||
File indexing completed on 2025-01-31 10:12:20
0001 // Protocol Buffers - Google's data interchange format 0002 // Copyright 2008 Google Inc. All rights reserved. 0003 // 0004 // Use of this source code is governed by a BSD-style 0005 // license that can be found in the LICENSE file or at 0006 // https://developers.google.com/open-source/licenses/bsd 0007 0008 // Author: jasonh@google.com (Jason Hsueh) 0009 // 0010 // This header is logically internal, but is made public because it is used 0011 // from protocol-compiler-generated code, which may reside in other components. 0012 // It provides reflection support for generated enums, and is included in 0013 // generated .pb.h files and should have minimal dependencies. The methods are 0014 // implemented in generated_message_reflection.cc. 0015 0016 #ifndef GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ 0017 #define GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__ 0018 0019 #include <string> 0020 0021 #include "absl/strings/string_view.h" 0022 #include "google/protobuf/generated_enum_util.h" 0023 #include "google/protobuf/port.h" 0024 0025 #ifdef SWIG 0026 #error "You cannot SWIG proto headers" 0027 #endif 0028 0029 // Must be included last. 0030 #include "google/protobuf/port_def.inc" 0031 0032 namespace google { 0033 namespace protobuf { 0034 class EnumDescriptor; 0035 } // namespace protobuf 0036 } // namespace google 0037 0038 namespace google { 0039 namespace protobuf { 0040 0041 // Returns the EnumDescriptor for enum type E, which must be a 0042 // proto-declared enum type. Code generated by the protocol compiler 0043 // will include specializations of this template for each enum type declared. 0044 template <typename E> 0045 const EnumDescriptor* GetEnumDescriptor(); 0046 0047 namespace internal { 0048 0049 // Helper for EnumType_Parse functions: try to parse the string 'name' as 0050 // an enum name of the given type, returning true and filling in value on 0051 // success, or returning false and leaving value unchanged on failure. 0052 PROTOBUF_EXPORT bool ParseNamedEnum(const EnumDescriptor* descriptor, 0053 absl::string_view name, int* value); 0054 0055 template <typename EnumType> 0056 bool ParseNamedEnum(const EnumDescriptor* descriptor, absl::string_view name, 0057 EnumType* value) { 0058 int tmp; 0059 if (!ParseNamedEnum(descriptor, name, &tmp)) return false; 0060 *value = static_cast<EnumType>(tmp); 0061 return true; 0062 } 0063 0064 // Just a wrapper around printing the name of a value. The main point of this 0065 // function is not to be inlined, so that you can do this without including 0066 // descriptor.h. 0067 PROTOBUF_EXPORT const std::string& NameOfEnum(const EnumDescriptor* descriptor, 0068 int value); 0069 0070 } // namespace internal 0071 } // namespace protobuf 0072 } // namespace google 0073 0074 #include "google/protobuf/port_undef.inc" 0075 0076 #endif // GOOGLE_PROTOBUF_GENERATED_ENUM_REFLECTION_H__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |