OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // http://code.google.com/p/protobuf/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
11 // * Redistributions in binary form must reproduce the above | 11 // * Redistributions in binary form must reproduce the above |
12 // copyright notice, this list of conditions and the following disclaimer | 12 // copyright notice, this list of conditions and the following disclaimer |
13 // in the documentation and/or other materials provided with the | 13 // in the documentation and/or other materials provided with the |
(...skipping 14 matching lines...) Expand all Loading... |
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 | 30 |
31 // Author: kenton@google.com (Kenton Varda) | 31 // Author: kenton@google.com (Kenton Varda) |
32 // Based on original Protocol Buffers design by | 32 // Based on original Protocol Buffers design by |
33 // Sanjay Ghemawat, Jeff Dean, and others. | 33 // Sanjay Ghemawat, Jeff Dean, and others. |
34 | 34 |
35 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ | 35 #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ |
36 #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ | 36 #define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ |
37 | 37 |
| 38 #include <set> |
38 #include <string> | 39 #include <string> |
39 #include <google/protobuf/compiler/cpp/cpp_options.h> | 40 #include <google/protobuf/compiler/cpp/cpp_options.h> |
40 #include <google/protobuf/descriptor.h> | 41 #include <google/protobuf/descriptor.h> |
41 | 42 |
42 | 43 |
43 namespace google { | 44 namespace google { |
44 namespace protobuf { | 45 namespace protobuf { |
45 namespace io { | 46 namespace io { |
46 class Printer; // printer.h | 47 class Printer; // printer.h |
47 } | 48 } |
48 } | 49 } |
49 | 50 |
50 namespace protobuf { | 51 namespace protobuf { |
51 namespace compiler { | 52 namespace compiler { |
52 namespace cpp { | 53 namespace cpp { |
53 | 54 |
54 class EnumGenerator { | 55 class EnumGenerator { |
55 public: | 56 public: |
56 // See generator.cc for the meaning of dllexport_decl. | 57 // See generator.cc for the meaning of dllexport_decl. |
57 explicit EnumGenerator(const EnumDescriptor* descriptor, | 58 explicit EnumGenerator(const EnumDescriptor* descriptor, |
58 const Options& options); | 59 const Options& options); |
59 ~EnumGenerator(); | 60 ~EnumGenerator(); |
60 | 61 |
61 // Header stuff. | 62 // Header stuff. |
62 | 63 |
| 64 // Fills the name to use when declaring the enum. This is for use when |
| 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. |
| 68 void FillForwardDeclaration(set<string>* enum_names); |
| 69 |
63 // Generate header code defining the enum. This code should be placed | 70 // Generate header code defining the enum. This code should be placed |
64 // within the enum's package namespace, but NOT within any class, even for | 71 // within the enum's package namespace, but NOT within any class, even for |
65 // nested enums. | 72 // nested enums. |
66 void GenerateDefinition(io::Printer* printer); | 73 void GenerateDefinition(io::Printer* printer); |
67 | 74 |
68 // Generate specialization of GetEnumDescriptor<MyEnum>(). | 75 // Generate specialization of GetEnumDescriptor<MyEnum>(). |
69 // Precondition: in ::google::protobuf namespace. | 76 // Precondition: in ::google::protobuf namespace. |
70 void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); | 77 void GenerateGetEnumDescriptorSpecializations(io::Printer* printer); |
71 | 78 |
72 // For enums nested within a message, generate code to import all the enum's | 79 // For enums nested within a message, generate code to import all the enum's |
73 // symbols (e.g. the enum type name, all its values, etc.) into the class's | 80 // symbols (e.g. the enum type name, all its values, etc.) into the class's |
74 // namespace. This should be placed inside the class definition in the | 81 // namespace. This should be placed inside the class definition in the |
75 // header. | 82 // header. |
76 void GenerateSymbolImports(io::Printer* printer); | 83 void GenerateSymbolImports(io::Printer* printer); |
77 | 84 |
78 // Source file stuff. | 85 // Source file stuff. |
79 | 86 |
80 // Generate code that initializes the global variable storing the enum's | 87 // Generate code that initializes the global variable storing the enum's |
81 // descriptor. | 88 // descriptor. |
82 void GenerateDescriptorInitializer(io::Printer* printer, int index); | 89 void GenerateDescriptorInitializer(io::Printer* printer, int index); |
83 | 90 |
84 // Generate non-inline methods related to the enum, such as IsValidValue(). | 91 // Generate non-inline methods related to the enum, such as IsValidValue(). |
85 // Goes in the .cc file. | 92 // Goes in the .cc file. |
86 void GenerateMethods(io::Printer* printer); | 93 void GenerateMethods(io::Printer* printer); |
87 | 94 |
88 private: | 95 private: |
89 const EnumDescriptor* descriptor_; | 96 const EnumDescriptor* descriptor_; |
90 string classname_; | 97 string classname_; |
91 Options options_; | 98 Options options_; |
| 99 // whether to generate the *_ARRAYSIZE constant. |
| 100 bool generate_array_size_; |
92 | 101 |
93 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); | 102 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumGenerator); |
94 }; | 103 }; |
95 | 104 |
96 } // namespace cpp | 105 } // namespace cpp |
97 } // namespace compiler | 106 } // namespace compiler |
98 } // namespace protobuf | 107 } // namespace protobuf |
99 | 108 |
100 } // namespace google | 109 } // namespace google |
101 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ | 110 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_H__ |
OLD | NEW |