Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:11:55

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: kenton@google.com (Kenton Varda)
0009 //  Based on original Protocol Buffers design by
0010 //  Sanjay Ghemawat, Jeff Dean, and others.
0011 
0012 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__
0013 #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__
0014 
0015 #include <string>
0016 
0017 #include "google/protobuf/compiler/cpp/options.h"
0018 #include "google/protobuf/descriptor.h"
0019 #include "google/protobuf/io/printer.h"
0020 
0021 namespace google {
0022 namespace protobuf {
0023 namespace compiler {
0024 namespace cpp {
0025 class EnumGenerator {
0026  public:
0027   EnumGenerator(const EnumDescriptor* descriptor, const Options& options);
0028 
0029   EnumGenerator(const EnumGenerator&) = delete;
0030   EnumGenerator& operator=(const EnumGenerator&) = delete;
0031 
0032   ~EnumGenerator() = default;
0033 
0034   // Generate header code defining the enum.  This code should be placed
0035   // within the enum's package namespace, but NOT within any class, even for
0036   // nested enums.
0037   void GenerateDefinition(io::Printer* p);
0038 
0039   // Generate specialization of GetEnumDescriptor<MyEnum>().
0040   // Precondition: in ::google::protobuf namespace.
0041   void GenerateGetEnumDescriptorSpecializations(io::Printer* p);
0042 
0043 
0044   // For enums nested within a message, generate code to import all the enum's
0045   // symbols (e.g. the enum type name, all its values, etc.) into the class's
0046   // namespace.  This should be placed inside the class definition in the
0047   // header.
0048   void GenerateSymbolImports(io::Printer* p) const;
0049 
0050   // Source file stuff.
0051 
0052   // Generate non-inline methods related to the enum, such as IsValidValue().
0053   // Goes in the .cc file. EnumDescriptors are stored in an array, idx is
0054   // the index in this array that corresponds with this enum.
0055   void GenerateMethods(int idx, io::Printer* p);
0056 
0057  private:
0058   friend class FileGenerator;
0059 
0060   struct ValueLimits {
0061     const EnumValueDescriptor* min;
0062     const EnumValueDescriptor* max;
0063 
0064     static ValueLimits FromEnum(const EnumDescriptor* descriptor);
0065   };
0066 
0067   const EnumDescriptor* enum_;
0068   Options options_;
0069 
0070   bool generate_array_size_;
0071   bool should_cache_;
0072   bool has_reflection_;
0073   ValueLimits limits_;
0074 };
0075 
0076 }  // namespace cpp
0077 }  // namespace compiler
0078 }  // namespace protobuf
0079 }  // namespace google
0080 
0081 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__