1
// Protocol Buffers - Google's data interchange format
2
// Copyright 2008 Google Inc.
3
// http://code.google.com/p/protobuf/
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
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_CPP_HELPERS_H__
22
#define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
25
#include <google/protobuf/descriptor.h>
32
// Commonly-used separator comments. Thick is a line of '=', thin is a line
34
extern const char kThickSeparator[];
35
extern const char kThinSeparator[];
37
// Returns the non-nested type name for the given type. If "qualified" is
38
// true, prefix the type with the full namespace. For example, if you had:
40
// message Baz { message Qux {} }
41
// Then the qualified ClassName for Qux would be:
42
// ::foo::bar::Baz_Qux
43
// While the non-qualified version would be:
45
string ClassName(const Descriptor* descriptor, bool qualified);
46
string ClassName(const EnumDescriptor* enum_descriptor, bool qualified);
48
// Get the (unqualified) name that should be used for this field in C++ code.
49
// The name is coerced to lower-case to emulate proto1 behavior. People
50
// should be using lowercase-with-underscores style for proto field names
51
// anyway, so normally this just returns field->name().
52
string FieldName(const FieldDescriptor* field);
54
// Returns the scope where the field was defined (for extensions, this is
55
// different from the message type to which the field applies).
56
inline const Descriptor* FieldScope(const FieldDescriptor* field) {
57
return field->is_extension() ?
58
field->extension_scope() : field->containing_type();
61
// Strips ".proto" or ".protodevel" from the end of a filename.
62
string StripProto(const string& filename);
64
// Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.).
65
// Note: non-built-in type names will be qualified, meaning they will start
66
// with a ::. If you are using the type as a template parameter, you will
67
// need to insure there is a space between the < and the ::, because the
68
// ridiculous C++ standard defines "<:" to be a synonym for "[".
69
const char* PrimitiveTypeName(FieldDescriptor::CppType type);
71
// Get the declared type name in CamelCase format, as is used e.g. for the
72
// methods of WireFormat. For example, TYPE_INT32 becomes "Int32".
73
const char* DeclaredTypeMethodName(FieldDescriptor::Type type);
75
// Convert a file name into a valid identifier.
76
string FilenameIdentifier(const string& filename);
78
// Return the name of the BuildDescriptors() function for a given file.
79
string GlobalBuildDescriptorsName(const string& filename);
82
} // namespace compiler
83
} // namespace protobuf
86
#endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__