javanano_field.h revision ccc48faf20dbf3b3cddcffe78d198876d543529b
190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// Protocol Buffers - Google's data interchange format 2f71323e297a928af368937089d3ed71239786f86Andreas Huber// Copyright 2008 Google Inc. All rights reserved. 390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// http://code.google.com/p/protobuf/ 4f71323e297a928af368937089d3ed71239786f86Andreas Huber// 5f71323e297a928af368937089d3ed71239786f86Andreas Huber// Redistribution and use in source and binary forms, with or without 6f71323e297a928af368937089d3ed71239786f86Andreas Huber// modification, are permitted provided that the following conditions are 7f71323e297a928af368937089d3ed71239786f86Andreas Huber// met: 8f71323e297a928af368937089d3ed71239786f86Andreas Huber// 990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// * Redistributions of source code must retain the above copyright 1090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// notice, this list of conditions and the following disclaimer. 1190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// * Redistributions in binary form must reproduce the above 12b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian// copyright notice, this list of conditions and the following disclaimer 13b08e2e23eec181e9951df33cd704ac294c5407b6Vignesh Venkatasubramanian// in the documentation and/or other materials provided with the 1490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// distribution. 1590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// * Neither the name of Google Inc. nor the names of its 1690d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// contributors may be used to endorse or promote products derived from 1790d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// this software without specific prior written permission. 1890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// 1990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2490d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2590d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 31ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// Author: kenton@google.com (Kenton Varda) 32ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// Based on original Protocol Buffers design by 33ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// Sanjay Ghemawat, Jeff Dean, and others. 34ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 35ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ 36ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ 37ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 3890d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <string> 3990d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <google/protobuf/stubs/common.h> 4090d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <google/protobuf/descriptor.h> 4190d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber#include <google/protobuf/compiler/javanano/javanano_params.h> 4290d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Huber 4390d3ed91ae9228e1c8bab561b6138d4cb8c1e4fdAndreas Hubernamespace google { 44ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangnamespace protobuf { 45ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang namespace io { 46ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang class Printer; // printer.h 47ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang } 48ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} 49ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 50ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangnamespace protobuf { 51ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangnamespace compiler { 52ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangnamespace javanano { 53ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 54ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangclass FieldGenerator { 55ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang public: 56ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang //FieldGenerator() {} 57ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang FieldGenerator(const Params& params) : params_(params) {} 58ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual ~FieldGenerator(); 59ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 60ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateMembers(io::Printer* printer) const = 0; 61ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateClearCode(io::Printer* printer) const = 0; 62ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateMergingCode(io::Printer* printer) const = 0; 63ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateSerializationCode(io::Printer* printer) const = 0; 64ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0; 65ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateEqualsCode(io::Printer* printer) const = 0; 66ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang virtual void GenerateHashCodeCode(io::Printer* printer) const = 0; 67ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 68ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang protected: 69ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const Params& params_; 70ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang private: 71ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); 72ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}; 73ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 74ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang// Convenience class which constructs FieldGenerators for a Descriptor. 75ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuangclass FieldGeneratorMap { 76ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang public: 77ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang explicit FieldGeneratorMap(const Descriptor* descriptor, const Params ¶ms); 78ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang ~FieldGeneratorMap(); 79ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 80ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const FieldGenerator& get(const FieldDescriptor* field) const; 81ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const FieldGenerator& get_extension(int index) const; 82ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int total_bits() const { return total_bits_; } 83ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 84ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang private: 85ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const Descriptor* descriptor_; 86ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang scoped_array<scoped_ptr<FieldGenerator> > field_generators_; 87ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang scoped_array<scoped_ptr<FieldGenerator> > extension_generators_; 88ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang int total_bits_; 89ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 90ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang static FieldGenerator* MakeGenerator(const FieldDescriptor* field, 91ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang const Params ¶ms, int* next_has_bit_index); 92ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 93ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); 94ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang}; 95ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 96ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} // namespace javanano 97ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} // namespace compiler 98ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} // namespace protobuf 99ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang 100ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang} // namespace google 101ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang#endif // GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ 102ba164dffc5a6795bce97fae02b51ccf3330e15e4hkuang