temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 2 | // Copyright 2008 Google Inc. All rights reserved. |
Feng Xiao | e428862 | 2014-10-01 16:26:23 -0700 | [diff] [blame] | 3 | // https://developers.google.com/protocol-buffers/ |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 4 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 5 | // Redistribution and use in source and binary forms, with or without |
| 6 | // modification, are permitted provided that the following conditions are |
| 7 | // met: |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 8 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 9 | // * Redistributions of source code must retain the above copyright |
| 10 | // notice, this list of conditions and the following disclaimer. |
| 11 | // * Redistributions in binary form must reproduce the above |
| 12 | // copyright notice, this list of conditions and the following disclaimer |
| 13 | // in the documentation and/or other materials provided with the |
| 14 | // distribution. |
| 15 | // * Neither the name of Google Inc. nor the names of its |
| 16 | // contributors may be used to endorse or promote products derived from |
| 17 | // this software without specific prior written permission. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 18 | // |
kenton@google.com | 24bf56f | 2008-09-24 20:31:01 +0000 | [diff] [blame] | 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 22 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 23 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 25 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 26 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 27 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 29 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 30 | |
| 31 | // Author: kenton@google.com (Kenton Varda) |
| 32 | // Based on original Protocol Buffers design by |
| 33 | // Sanjay Ghemawat, Jeff Dean, and others. |
| 34 | |
| 35 | #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ |
| 36 | #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ |
| 37 | |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 38 | #include <set> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 39 | #include <string> |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 40 | #include <google/protobuf/compiler/cpp/cpp_options.h> |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 41 | #include <google/protobuf/descriptor.h> |
| 42 | |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 43 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 44 | namespace google { |
| 45 | namespace protobuf { |
| 46 | namespace io { |
| 47 | class Printer; // printer.h |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | namespace protobuf { |
| 52 | namespace compiler { |
| 53 | namespace cpp { |
| 54 | |
| 55 | class EnumGenerator { |
| 56 | public: |
| 57 | // See generator.cc for the meaning of dllexport_decl. |
| 58 | explicit EnumGenerator(const EnumDescriptor* descriptor, |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 59 | const Options& options); |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 60 | ~EnumGenerator(); |
| 61 | |
| 62 | // Header stuff. |
| 63 | |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 64 | // Fills the name to use when declaring the enum. This is for use when |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 65 | // generating other .proto.h files. This code should be placed within the |
| 66 | // enum's package namespace, but NOT within any class, even for nested |
| 67 | // enums. |
Feng Xiao | eee38b0 | 2015-08-22 18:25:48 -0700 | [diff] [blame] | 68 | void FillForwardDeclaration(set<string>* enum_names); |
Bo Yang | 5db2173 | 2015-05-21 14:28:59 -0700 | [diff] [blame] | 69 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 70 | // Generate header code defining the enum. This code should be placed |
| 71 | // within the enum's package namespace, but NOT within any class, even for |
| 72 | // nested enums. |
| 73 | void GenerateDefinition(io::Printer* printer); |
| 74 | |
kenton@google.com | 80b1d62 | 2009-07-29 01:13:20 +0000 | [diff] [blame] | 75 | // Generate specialization of GetEnumDescriptor<MyEnum>(). |
| 76 | // Precondition: in ::google::protobuf namespace. |
| 77 | void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); |
| 78 | |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 79 | // For enums nested within a message, generate code to import all the enum's |
| 80 | // symbols (e.g. the enum type name, all its values, etc.) into the class's |
| 81 | // namespace. This should be placed inside the class definition in the |
| 82 | // header. |
| 83 | void GenerateSymbolImports(io::Printer* printer); |
| 84 | |
| 85 | // Source file stuff. |
| 86 | |
| 87 | // Generate code that initializes the global variable storing the enum's |
| 88 | // descriptor. |
| 89 | void GenerateDescriptorInitializer(io::Printer* printer, int index); |
| 90 | |
| 91 | // Generate non-inline methods related to the enum, such as IsValidValue(). |
| 92 | // Goes in the .cc file. |
| 93 | void GenerateMethods(io::Printer* printer); |
| 94 | |
| 95 | private: |
| 96 | const EnumDescriptor* descriptor_; |
| 97 | string classname_; |
xiaofeng@google.com | b55a20f | 2012-09-22 02:40:50 +0000 | [diff] [blame] | 98 | Options options_; |
jieluo@google.com | 4de8f55 | 2014-07-18 00:47:59 +0000 | [diff] [blame] | 99 | // whether to generate the *_ARRAYSIZE constant. |
| 100 | bool generate_array_size_; |
temporal | 40ee551 | 2008-07-10 02:12:20 +0000 | [diff] [blame] | 101 | |
| 102 | GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); |
| 103 | }; |
| 104 | |
| 105 | } // namespace cpp |
| 106 | } // namespace compiler |
| 107 | } // namespace protobuf |
| 108 | |
| 109 | } // namespace google |
| 110 | #endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ |