• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #ifndef GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__
9 #define GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__
10 
11 #include <string>
12 
13 #include "absl/container/flat_hash_map.h"
14 #include "absl/strings/string_view.h"
15 #include "google/protobuf/compiler/objectivec/options.h"
16 #include "google/protobuf/descriptor.h"
17 #include "google/protobuf/io/printer.h"
18 
19 namespace google {
20 namespace protobuf {
21 namespace compiler {
22 namespace objectivec {
23 
24 class OneofGenerator {
25  public:
26   OneofGenerator(const OneofDescriptor* descriptor,
27                  const GenerationOptions& generation_options);
28   ~OneofGenerator() = default;
29 
30   OneofGenerator(const OneofGenerator&) = delete;
31   OneofGenerator& operator=(const OneofGenerator&) = delete;
32 
33   void SetOneofIndexBase(int index_base);
34 
35   void GenerateCaseEnum(io::Printer* printer) const;
36 
37   void GeneratePublicCasePropertyDeclaration(io::Printer* printer) const;
38   void GenerateClearFunctionDeclaration(io::Printer* printer) const;
39 
40   void GeneratePropertyImplementation(io::Printer* printer) const;
41   void GenerateClearFunctionImplementation(io::Printer* printer) const;
42 
43   std::string DescriptorName() const;
44   std::string HasIndexAsString() const;
45 
46  private:
47   const OneofDescriptor* descriptor_;
48   const GenerationOptions& generation_options_;
49   absl::flat_hash_map<absl::string_view, std::string> variables_;
50 };
51 
52 }  // namespace objectivec
53 }  // namespace compiler
54 }  // namespace protobuf
55 }  // namespace google
56 
57 #endif  // GOOGLE_PROTOBUF_COMPILER_OBJECTIVEC_ONEOF_H__
58