| OLD | NEW |
| (Empty) | |
| 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ |
| 4 // |
| 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are |
| 7 // met: |
| 8 // |
| 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. |
| 18 // |
| 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. |
| 30 |
| 31 #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__ |
| 32 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__ |
| 33 |
| 34 #include <map> |
| 35 #include <string> |
| 36 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h> |
| 37 #include <google/protobuf/stubs/common.h> |
| 38 #include <google/protobuf/descriptor.h> |
| 39 |
| 40 namespace google { |
| 41 namespace protobuf { |
| 42 |
| 43 namespace io { |
| 44 class Printer; // printer.h |
| 45 } // namespace io |
| 46 |
| 47 namespace compiler { |
| 48 namespace objectivec { |
| 49 |
| 50 class FieldGenerator { |
| 51 public: |
| 52 static FieldGenerator* Make(const FieldDescriptor* field); |
| 53 |
| 54 virtual ~FieldGenerator(); |
| 55 |
| 56 virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const = 0; |
| 57 virtual void GeneratePropertyDeclaration(io::Printer* printer) const = 0; |
| 58 |
| 59 virtual void GeneratePropertyImplementation(io::Printer* printer) const = 0; |
| 60 |
| 61 virtual void GenerateFieldDescription(io::Printer* printer) const; |
| 62 virtual void GenerateFieldDescriptionTypeSpecific(io::Printer* printer) const; |
| 63 virtual void GenerateFieldNumberConstant(io::Printer* printer) const; |
| 64 |
| 65 virtual void GenerateCFunctionDeclarations(io::Printer* printer) const; |
| 66 virtual void GenerateCFunctionImplementations(io::Printer* printer) const; |
| 67 |
| 68 virtual void DetermineForwardDeclarations(set<string>* fwd_decls) const; |
| 69 |
| 70 void SetOneofIndexBase(int index_base); |
| 71 |
| 72 string variable(const char* key) const { |
| 73 return variables_.find(key)->second; |
| 74 } |
| 75 |
| 76 bool needs_textformat_name_support() const { |
| 77 const string& field_flags = variable("fieldflags"); |
| 78 return field_flags.find("GPBFieldTextFormatNameCustom") != string::npos; |
| 79 } |
| 80 string generated_objc_name() const { return variable("name"); } |
| 81 string raw_field_name() const { return variable("raw_field_name"); } |
| 82 |
| 83 protected: |
| 84 explicit FieldGenerator(const FieldDescriptor* descriptor); |
| 85 |
| 86 virtual void FinishInitialization(void); |
| 87 virtual bool WantsHasProperty(void) const = 0; |
| 88 |
| 89 const FieldDescriptor* descriptor_; |
| 90 map<string, string> variables_; |
| 91 |
| 92 private: |
| 93 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); |
| 94 }; |
| 95 |
| 96 class SingleFieldGenerator : public FieldGenerator { |
| 97 public: |
| 98 virtual ~SingleFieldGenerator(); |
| 99 |
| 100 virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const; |
| 101 virtual void GeneratePropertyDeclaration(io::Printer* printer) const; |
| 102 |
| 103 virtual void GeneratePropertyImplementation(io::Printer* printer) const; |
| 104 |
| 105 protected: |
| 106 explicit SingleFieldGenerator(const FieldDescriptor* descriptor); |
| 107 virtual bool WantsHasProperty(void) const; |
| 108 |
| 109 private: |
| 110 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SingleFieldGenerator); |
| 111 }; |
| 112 |
| 113 // Subclass with common support for when the field ends up as an ObjC Object. |
| 114 class ObjCObjFieldGenerator : public SingleFieldGenerator { |
| 115 public: |
| 116 virtual ~ObjCObjFieldGenerator(); |
| 117 |
| 118 virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const; |
| 119 virtual void GeneratePropertyDeclaration(io::Printer* printer) const; |
| 120 |
| 121 protected: |
| 122 explicit ObjCObjFieldGenerator(const FieldDescriptor* descriptor); |
| 123 |
| 124 private: |
| 125 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ObjCObjFieldGenerator); |
| 126 }; |
| 127 |
| 128 class RepeatedFieldGenerator : public ObjCObjFieldGenerator { |
| 129 public: |
| 130 virtual ~RepeatedFieldGenerator(); |
| 131 |
| 132 virtual void GenerateFieldStorageDeclaration(io::Printer* printer) const; |
| 133 virtual void GeneratePropertyDeclaration(io::Printer* printer) const; |
| 134 |
| 135 virtual void GeneratePropertyImplementation(io::Printer* printer) const; |
| 136 |
| 137 protected: |
| 138 explicit RepeatedFieldGenerator(const FieldDescriptor* descriptor); |
| 139 virtual void FinishInitialization(void); |
| 140 virtual bool WantsHasProperty(void) const; |
| 141 |
| 142 private: |
| 143 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedFieldGenerator); |
| 144 }; |
| 145 |
| 146 // Convenience class which constructs FieldGenerators for a Descriptor. |
| 147 class FieldGeneratorMap { |
| 148 public: |
| 149 explicit FieldGeneratorMap(const Descriptor* descriptor); |
| 150 ~FieldGeneratorMap(); |
| 151 |
| 152 const FieldGenerator& get(const FieldDescriptor* field) const; |
| 153 const FieldGenerator& get_extension(int index) const; |
| 154 |
| 155 void SetOneofIndexBase(int index_base); |
| 156 |
| 157 private: |
| 158 const Descriptor* descriptor_; |
| 159 scoped_array<scoped_ptr<FieldGenerator> > field_generators_; |
| 160 scoped_array<scoped_ptr<FieldGenerator> > extension_generators_; |
| 161 |
| 162 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); |
| 163 }; |
| 164 } // namespace objectivec |
| 165 } // namespace compiler |
| 166 } // namespace protobuf |
| 167 } // namespace google |
| 168 #endif // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_FIELD_H__ |
| OLD | NEW |