Initial import of v2.0.0beta
[protobuf.git] / src / google / protobuf / compiler / java / java_field.h
blobef47c735882e55b6f72d9f7d7ec6367f8c6dbe64
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.
3 // http://code.google.com/p/protobuf/
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
17 // Author: kenton@google.com (Kenton Varda)
18 // Based on original Protocol Buffers design by
19 // Sanjay Ghemawat, Jeff Dean, and others.
21 #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
22 #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__
24 #include <string>
25 #include <google/protobuf/stubs/common.h>
26 #include <google/protobuf/descriptor.h>
28 namespace google {
29 namespace protobuf {
30 namespace io {
31 class Printer; // printer.h
35 namespace protobuf {
36 namespace compiler {
37 namespace java {
39 class FieldGenerator {
40 public:
41 FieldGenerator() {}
42 virtual ~FieldGenerator();
44 virtual void GenerateMembers(io::Printer* printer) const = 0;
45 virtual void GenerateBuilderMembers(io::Printer* printer) const = 0;
46 virtual void GenerateMergingCode(io::Printer* printer) const = 0;
47 virtual void GenerateBuildingCode(io::Printer* printer) const = 0;
48 virtual void GenerateParsingCode(io::Printer* printer) const = 0;
49 virtual void GenerateSerializationCode(io::Printer* printer) const = 0;
50 virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0;
52 virtual string GetBoxedType() const = 0;
54 private:
55 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator);
58 // Convenience class which constructs FieldGenerators for a Descriptor.
59 class FieldGeneratorMap {
60 public:
61 explicit FieldGeneratorMap(const Descriptor* descriptor);
62 ~FieldGeneratorMap();
64 const FieldGenerator& get(const FieldDescriptor* field) const;
65 const FieldGenerator& get_extension(int index) const;
67 private:
68 const Descriptor* descriptor_;
69 scoped_array<scoped_ptr<FieldGenerator> > field_generators_;
70 scoped_array<scoped_ptr<FieldGenerator> > extension_generators_;
72 static FieldGenerator* MakeGenerator(const FieldDescriptor* field);
74 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap);
77 } // namespace java
78 } // namespace compiler
79 } // namespace protobuf
81 } // namespace google
82 #endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__