• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // 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_MESSAGE_FIELD_H__
36 #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__
37 
38 #include <map>
39 #include <string>
40 
41 #include <google/protobuf/compiler/cpp/cpp_field.h>
42 #include <google/protobuf/compiler/cpp/cpp_helpers.h>
43 
44 namespace google {
45 namespace protobuf {
46 namespace compiler {
47 namespace cpp {
48 
49 class MessageFieldGenerator : public FieldGenerator {
50  public:
51   MessageFieldGenerator(const FieldDescriptor* descriptor,
52                         const Options& options,
53                         MessageSCCAnalyzer* scc_analyzer);
54   ~MessageFieldGenerator() override;
55 
56   // implements FieldGenerator ---------------------------------------
57   void GeneratePrivateMembers(io::Printer* printer) const override;
58   void GenerateAccessorDeclarations(io::Printer* printer) const override;
59   void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
60   void GenerateNonInlineAccessorDefinitions(
61       io::Printer* printer) const override;
62   void GenerateInternalAccessorDeclarations(
63       io::Printer* printer) const override;
64   void GenerateInternalAccessorDefinitions(io::Printer* printer) const override;
65   void GenerateClearingCode(io::Printer* printer) const override;
66   void GenerateMessageClearingCode(io::Printer* printer) const override;
67   void GenerateMergingCode(io::Printer* printer) const override;
68   void GenerateSwappingCode(io::Printer* printer) const override;
69   void GenerateDestructorCode(io::Printer* printer) const override;
70   void GenerateConstructorCode(io::Printer* printer) const override;
71   void GenerateCopyConstructorCode(io::Printer* printer) const override;
72   void GenerateSerializeWithCachedSizesToArray(
73       io::Printer* printer) const override;
74   void GenerateByteSize(io::Printer* printer) const override;
75   void GenerateIsInitialized(io::Printer* printer) const override;
76   void GenerateConstinitInitializer(io::Printer* printer) const override;
77 
78  protected:
79   const bool implicit_weak_field_;
80   const bool has_required_fields_;
81 
82  private:
83   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
84 };
85 
86 class MessageOneofFieldGenerator : public MessageFieldGenerator {
87  public:
88   MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
89                              const Options& options,
90                              MessageSCCAnalyzer* scc_analyzer);
91   ~MessageOneofFieldGenerator() override;
92 
93   // implements FieldGenerator ---------------------------------------
94   void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
95   void GenerateNonInlineAccessorDefinitions(
96       io::Printer* printer) const override;
97   void GenerateClearingCode(io::Printer* printer) const override;
98 
99   // MessageFieldGenerator, from which we inherit, overrides this so we need to
100   // override it as well.
101   void GenerateMessageClearingCode(io::Printer* printer) const override;
102   void GenerateSwappingCode(io::Printer* printer) const override;
103   void GenerateDestructorCode(io::Printer* printer) const override;
104   void GenerateConstructorCode(io::Printer* printer) const override;
105   void GenerateIsInitialized(io::Printer* printer) const override;
106 
107  private:
108   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator);
109 };
110 
111 class RepeatedMessageFieldGenerator : public FieldGenerator {
112  public:
113   RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor,
114                                 const Options& options,
115                                 MessageSCCAnalyzer* scc_analyzer);
116   ~RepeatedMessageFieldGenerator() override;
117 
118   // implements FieldGenerator ---------------------------------------
119   void GeneratePrivateMembers(io::Printer* printer) const override;
120   void GenerateAccessorDeclarations(io::Printer* printer) const override;
121   void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
122   void GenerateClearingCode(io::Printer* printer) const override;
123   void GenerateMergingCode(io::Printer* printer) const override;
124   void GenerateSwappingCode(io::Printer* printer) const override;
125   void GenerateConstructorCode(io::Printer* printer) const override;
GenerateCopyConstructorCode(io::Printer * printer)126   void GenerateCopyConstructorCode(io::Printer* printer) const override {}
127   void GenerateSerializeWithCachedSizesToArray(
128       io::Printer* printer) const override;
129   void GenerateByteSize(io::Printer* printer) const override;
130   void GenerateIsInitialized(io::Printer* printer) const override;
131   void GenerateConstinitInitializer(io::Printer* printer) const override;
132 
133  private:
134   const bool implicit_weak_field_;
135   const bool has_required_fields_;
136 
137   GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator);
138 };
139 
140 }  // namespace cpp
141 }  // namespace compiler
142 }  // namespace protobuf
143 }  // namespace google
144 
145 #endif  // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__
146