cpp_enum_field.h revision d0332953cda33fb4f8e24ebff9c49159b69c43d6
15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Protocol Buffers - Google's data interchange format 25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Copyright 2008 Google Inc. All rights reserved. 35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// http://code.google.com/p/protobuf/ 45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Redistribution and use in source and binary forms, with or without 65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// modification, are permitted provided that the following conditions are 75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// met: 85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// * Redistributions of source code must retain the above copyright 105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// notice, this list of conditions and the following disclaimer. 115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// * Redistributions in binary form must reproduce the above 125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// copyright notice, this list of conditions and the following disclaimer 135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// in the documentation and/or other materials provided with the 145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// distribution. 155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// * Neither the name of Google Inc. nor the names of its 165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// contributors may be used to endorse or promote products derived from 175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// this software without specific prior written permission. 185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// 195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) 315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Author: kenton@google.com (Kenton Varda) 325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Based on original Protocol Buffers design by 335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)// Sanjay Ghemawat, Jeff Dean, and others. 345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#ifndef GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ 365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#define GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ 375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 385c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <map> 395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <string> 405c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include <google/protobuf/compiler/cpp/cpp_field.h> 415c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 425c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace google { 435c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace protobuf { 445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace compiler { 455c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace cpp { 465c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 475c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)class EnumFieldGenerator : public FieldGenerator { 485c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) public: 495c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) explicit EnumFieldGenerator(const FieldDescriptor* descriptor); 505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) ~EnumFieldGenerator(); 515c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) 525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) // implements FieldGenerator --------------------------------------- 531e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles) void GeneratePrivateMembers(io::Printer* printer) const; 545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void GenerateAccessorDeclarations(io::Printer* printer) const; 555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void GenerateInlineAccessorDefinitions(io::Printer* printer) const; 56d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void GenerateClearingCode(io::Printer* printer) const; 57d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void GenerateMergingCode(io::Printer* printer) const; 58d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) void GenerateSwappingCode(io::Printer* printer) const; 59d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void GenerateConstructorCode(io::Printer* printer) const; 60d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void GenerateMergeFromCodedStream(io::Printer* printer) const; 61d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void GenerateSerializeWithCachedSizes(io::Printer* printer) const; 62c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles) void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; 635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) void GenerateByteSize(io::Printer* printer) const; 64 65 private: 66 const FieldDescriptor* descriptor_; 67 map<string, string> variables_; 68 69 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EnumFieldGenerator); 70}; 71 72class RepeatedEnumFieldGenerator : public FieldGenerator { 73 public: 74 explicit RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor); 75 ~RepeatedEnumFieldGenerator(); 76 77 // implements FieldGenerator --------------------------------------- 78 void GeneratePrivateMembers(io::Printer* printer) const; 79 void GenerateAccessorDeclarations(io::Printer* printer) const; 80 void GenerateInlineAccessorDefinitions(io::Printer* printer) const; 81 void GenerateClearingCode(io::Printer* printer) const; 82 void GenerateMergingCode(io::Printer* printer) const; 83 void GenerateSwappingCode(io::Printer* printer) const; 84 void GenerateConstructorCode(io::Printer* printer) const; 85 void GenerateMergeFromCodedStream(io::Printer* printer) const; 86 void GenerateMergeFromCodedStreamWithPacking(io::Printer* printer) const; 87 void GenerateSerializeWithCachedSizes(io::Printer* printer) const; 88 void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; 89 void GenerateByteSize(io::Printer* printer) const; 90 91 private: 92 const FieldDescriptor* descriptor_; 93 map<string, string> variables_; 94 95 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedEnumFieldGenerator); 96}; 97 98} // namespace cpp 99} // namespace compiler 100} // namespace protobuf 101 102} // namespace google 103#endif // GOOGLE_PROTOBUF_COMPILER_CPP_ENUM_FIELD_H__ 104