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 // https://developers.google.com/protocol-buffers/ | 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. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 variables_["enum_name"] = OneofEnumName(descriptor_); | 46 variables_["enum_name"] = OneofEnumName(descriptor_); |
47 variables_["name"] = OneofName(descriptor_); | 47 variables_["name"] = OneofName(descriptor_); |
48 variables_["capitalized_name"] = OneofNameCapitalized(descriptor_); | 48 variables_["capitalized_name"] = OneofNameCapitalized(descriptor_); |
49 variables_["raw_index"] = SimpleItoa(descriptor_->index()); | 49 variables_["raw_index"] = SimpleItoa(descriptor_->index()); |
50 const Descriptor* msg_descriptor = descriptor_->containing_type(); | 50 const Descriptor* msg_descriptor = descriptor_->containing_type(); |
51 variables_["owning_message_class"] = ClassName(msg_descriptor); | 51 variables_["owning_message_class"] = ClassName(msg_descriptor); |
52 | 52 |
53 string comments; | 53 string comments; |
54 SourceLocation location; | 54 SourceLocation location; |
55 if (descriptor_->GetSourceLocation(&location)) { | 55 if (descriptor_->GetSourceLocation(&location)) { |
56 comments = BuildCommentsString(location, true); | 56 comments = BuildCommentsString(location); |
57 } else { | 57 } else { |
58 comments = ""; | 58 comments = ""; |
59 } | 59 } |
60 variables_["comments"] = comments; | 60 variables_["comments"] = comments; |
61 } | 61 } |
62 | 62 |
63 OneofGenerator::~OneofGenerator() {} | 63 OneofGenerator::~OneofGenerator() {} |
64 | 64 |
65 void OneofGenerator::SetOneofIndexBase(int index_base) { | 65 void OneofGenerator::SetOneofIndexBase(int index_base) { |
66 int index = descriptor_->index() + index_base; | 66 int index = descriptor_->index() + index_base; |
(...skipping 30 matching lines...) Expand all Loading... |
97 printer->Print( | 97 printer->Print( |
98 variables_, | 98 variables_, |
99 "$comments$" | 99 "$comments$" |
100 "@property(nonatomic, readonly) $enum_name$ $name$OneOfCase;\n" | 100 "@property(nonatomic, readonly) $enum_name$ $name$OneOfCase;\n" |
101 "\n"); | 101 "\n"); |
102 } | 102 } |
103 | 103 |
104 void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { | 104 void OneofGenerator::GenerateClearFunctionDeclaration(io::Printer* printer) { |
105 printer->Print( | 105 printer->Print( |
106 variables_, | 106 variables_, |
107 "/**\n" | 107 "/// Clears whatever value was set for the oneof '$name$'.\n" |
108 " * Clears whatever value was set for the oneof '$name$'.\n" | |
109 " **/\n" | |
110 "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_mess
age_class$ *message);\n"); | 108 "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_mess
age_class$ *message);\n"); |
111 } | 109 } |
112 | 110 |
113 void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) { | 111 void OneofGenerator::GeneratePropertyImplementation(io::Printer* printer) { |
114 printer->Print( | 112 printer->Print( |
115 variables_, | 113 variables_, |
116 "@dynamic $name$OneOfCase;\n"); | 114 "@dynamic $name$OneOfCase;\n"); |
117 } | 115 } |
118 | 116 |
119 void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) { | 117 void OneofGenerator::GenerateClearFunctionImplementation(io::Printer* printer) { |
120 printer->Print( | 118 printer->Print( |
121 variables_, | 119 variables_, |
122 "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_mess
age_class$ *message) {\n" | 120 "void $owning_message_class$_Clear$capitalized_name$OneOfCase($owning_mess
age_class$ *message) {\n" |
123 " GPBDescriptor *descriptor = [message descriptor];\n" | 121 " GPBDescriptor *descriptor = [message descriptor];\n" |
124 " GPBOneofDescriptor *oneof = [descriptor.oneofs objectAtIndex:$raw_index
$];\n" | 122 " GPBOneofDescriptor *oneof = descriptor->oneofs_[$raw_index$];\n" |
125 " GPBMaybeClearOneof(message, oneof, $index$, 0);\n" | 123 " GPBMaybeClearOneof(message, oneof, $index$, 0);\n" |
126 "}\n"); | 124 "}\n"); |
127 } | 125 } |
128 | 126 |
129 string OneofGenerator::DescriptorName(void) const { | 127 string OneofGenerator::DescriptorName(void) const { |
130 return variables_.find("name")->second; | 128 return variables_.find("name")->second; |
131 } | 129 } |
132 | 130 |
133 string OneofGenerator::HasIndexAsString(void) const { | 131 string OneofGenerator::HasIndexAsString(void) const { |
134 return variables_.find("index")->second; | 132 return variables_.find("index")->second; |
135 } | 133 } |
136 | 134 |
137 } // namespace objectivec | 135 } // namespace objectivec |
138 } // namespace compiler | 136 } // namespace compiler |
139 } // namespace protobuf | 137 } // namespace protobuf |
140 } // namespace google | 138 } // namespace google |
OLD | NEW |