Go to the documentation of this file.
34 #include <google/protobuf/compiler/objectivec/objectivec_enum.h>
35 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
36 #include <google/protobuf/io/printer.h>
37 #include <google/protobuf/stubs/strutil.h>
43 namespace objectivec {
57 std::set<std::string> value_names;
64 if (
value == canonical_value) {
69 if (value_names.find(value_name) != value_names.end()) {
72 value_names.insert(value_name);
91 "#pragma mark - Enum $name$\n"
109 printer->Print(
"$comments$typedef$deprecated_attribute$ GPB_ENUM($name$) {\n",
110 "comments", enum_comments,
119 " * Value used if any message's field encounters a value that is not defined\n"
120 " * by this enum. The message will also have C functions to get/set the rawValue\n"
123 "$name$_GPBUnrecognizedEnumeratorValue = kGPBUnrecognizedEnumeratorValue,\n",
130 if (
all_values_[i]->GetSourceLocation(&location)) {
132 if (comments.length() > 0) {
134 printer->Print(
"\n");
136 printer->Print(comments.c_str());
141 "$name$$deprecated_attribute$ = $value$,\n",
150 "GPBEnumDescriptor *$name$_EnumDescriptor(void);\n"
153 " * Checks to see if the given value is defined by the enum or was not known at\n"
154 " * the time this source was generated.\n"
156 "BOOL $name$_IsValidValue(int32_t value);\n"
163 "#pragma mark - Enum $name$\n"
172 TextFormatDecodeData text_format_decode_data;
173 int enum_value_description_key = -1;
177 ++enum_value_description_key;
179 text_blob += short_name +
'\0';
181 text_format_decode_data.AddString(enum_value_description_key, short_name,
187 "GPBEnumDescriptor *$name$_EnumDescriptor(void) {\n"
188 " static _Atomic(GPBEnumDescriptor*) descriptor = nil;\n"
189 " if (!descriptor) {\n",
192 static const int kBytesPerLine = 40;
194 " static const char *valueNames =");
195 for (
int i = 0;
i < text_blob.size();
i += kBytesPerLine) {
202 " static const int32_t values[] = {\n");
206 printer->Print(
" };\n");
208 if (text_format_decode_data.num_entries() == 0) {
210 " GPBEnumDescriptor *worker =\n"
211 " [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
212 " valueNames:valueNames\n"
214 " count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n"
215 " enumVerifier:$name$_IsValidValue];\n",
219 " static const char *extraTextFormatInfo = \"$extraTextFormatInfo$\";\n"
220 " GPBEnumDescriptor *worker =\n"
221 " [GPBEnumDescriptor allocDescriptorForName:GPBNSStringifySymbol($name$)\n"
222 " valueNames:valueNames\n"
224 " count:(uint32_t)(sizeof(values) / sizeof(int32_t))\n"
225 " enumVerifier:$name$_IsValidValue\n"
226 " extraTextFormatInfo:extraTextFormatInfo];\n",
228 "extraTextFormatInfo",
CEscape(text_format_decode_data.Data()));
231 " GPBEnumDescriptor *expected = nil;\n"
232 " if (!atomic_compare_exchange_strong(&descriptor, &expected, worker)) {\n"
233 " [worker release];\n"
236 " return descriptor;\n"
240 "BOOL $name$_IsValidValue(int32_t value__) {\n"
241 " switch (value__) {\n",
std::set< const EnumValueDescriptor * > alias_values_to_skip_
const Descriptor::ReservedRange value
bool HasPreservingUnknownEnumSemantics(const FileDescriptor *file)
const string & name() const
const EnumDescriptor * descriptor_
string CEscape(const string &src)
GRPC_CUSTOM_PRINTER Printer
string EnumValueName(const EnumValueDescriptor *descriptor)
string StrCat(const AlphaNum &a, const AlphaNum &b)
string EnumValueShortName(const EnumValueDescriptor *descriptor)
const EnumValueDescriptor * FindValueByNumber(int number) const
string GetOptionalDeprecatedAttribute(const TDescriptor *descriptor, const FileDescriptor *file=NULL, bool preSpace=true, bool postNewline=false)
const FileDescriptor * file() const
const EnumValueDescriptor * value(int index) const
void GenerateSource(io::Printer *printer)
string UnCamelCaseEnumShortName(const string &name)
void GenerateHeader(io::Printer *printer)
GRPC_CUSTOM_SOURCELOCATION SourceLocation
std::vector< const EnumValueDescriptor * > base_values_
string EnumName(const EnumDescriptor *descriptor)
bool GetSourceLocation(SourceLocation *out_location) const
EnumGenerator(const EnumDescriptor *descriptor)
string EscapeTrigraphs(const string &to_escape)
static const char descriptor[1336]
string BuildCommentsString(const SourceLocation &location, bool prefer_single_line)
std::vector< const EnumValueDescriptor * > all_values_
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:34