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/field.h>
42#include <google/protobuf/compiler/cpp/helpers.h>
43
44namespace google {
45namespace protobuf {
46namespace compiler {
47namespace cpp {
48
49class 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 GenerateConstexprAggregateInitializer(
77 io::Printer* printer) const override;
78 void GenerateAggregateInitializer(io::Printer* printer) const override;
79 void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
80
81 protected:
82 const bool implicit_weak_field_;
83 const bool has_required_fields_;
84
85 private:
86 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageFieldGenerator);
87};
88
89class MessageOneofFieldGenerator : public MessageFieldGenerator {
90 public:
91 MessageOneofFieldGenerator(const FieldDescriptor* descriptor,
92 const Options& options,
93 MessageSCCAnalyzer* scc_analyzer);
94 ~MessageOneofFieldGenerator() override;
95
96 // implements FieldGenerator ---------------------------------------
97 void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
98 void GenerateNonInlineAccessorDefinitions(
99 io::Printer* printer) const override;
100 void GenerateClearingCode(io::Printer* printer) const override;
101
102 // MessageFieldGenerator, from which we inherit, overrides this so we need to
103 // override it as well.
104 void GenerateMessageClearingCode(io::Printer* printer) const override;
105 void GenerateSwappingCode(io::Printer* printer) const override;
106 void GenerateDestructorCode(io::Printer* printer) const override;
107 void GenerateConstructorCode(io::Printer* printer) const override;
108 void GenerateIsInitialized(io::Printer* printer) const override;
109
110 private:
111 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageOneofFieldGenerator);
112};
113
114class RepeatedMessageFieldGenerator : public FieldGenerator {
115 public:
116 RepeatedMessageFieldGenerator(const FieldDescriptor* descriptor,
117 const Options& options,
118 MessageSCCAnalyzer* scc_analyzer);
119 ~RepeatedMessageFieldGenerator() override;
120
121 // implements FieldGenerator ---------------------------------------
122 void GeneratePrivateMembers(io::Printer* printer) const override;
123 void GenerateAccessorDeclarations(io::Printer* printer) const override;
124 void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
125 void GenerateClearingCode(io::Printer* printer) const override;
126 void GenerateMergingCode(io::Printer* printer) const override;
127 void GenerateSwappingCode(io::Printer* printer) const override;
128 void GenerateConstructorCode(io::Printer* printer) const override;
129 void GenerateCopyConstructorCode(io::Printer* printer) const override {}
130 void GenerateDestructorCode(io::Printer* printer) const override;
131 void GenerateSerializeWithCachedSizesToArray(
132 io::Printer* printer) const override;
133 void GenerateByteSize(io::Printer* printer) const override;
134 void GenerateIsInitialized(io::Printer* printer) const override;
135
136 private:
137 const bool implicit_weak_field_;
138 const bool has_required_fields_;
139
140 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedMessageFieldGenerator);
141};
142
143} // namespace cpp
144} // namespace compiler
145} // namespace protobuf
146} // namespace google
147
148#endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_FIELD_H__
149