3 * Copyright 2015 gRPC authors.
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.
19 #ifndef GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
20 #define GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H
23 #include "src/compiler/config.h"
24 #include "src/compiler/generator_helpers.h"
26 #include <google/protobuf/compiler/objectivec/objectivec_helpers.h>
28 namespace grpc_objective_c_generator {
30 using ::grpc::protobuf::FileDescriptor;
31 using ::grpc::protobuf::ServiceDescriptor;
34 inline string MessageHeaderName(const FileDescriptor* file) {
35 return google::protobuf::compiler::objectivec::FilePath(file) + ".pbobjc.h";
38 inline string ServiceClassName(const ServiceDescriptor* service) {
39 const FileDescriptor* file = service->file();
40 string prefix = file->options().objc_class_prefix();
41 return prefix + service->name();
44 inline ::grpc::string LocalImport(const ::grpc::string& import) {
45 return ::grpc::string("#import \"" + import + "\"\n");
48 inline ::grpc::string SystemImport(const ::grpc::string& import) {
49 return ::grpc::string("#import <" + import + ">\n");
52 inline ::grpc::string PreprocConditional(::grpc::string symbol, bool invert) {
53 return invert ? "!defined(" + symbol + ") || !" + symbol
54 : "defined(" + symbol + ") && " + symbol;
57 inline ::grpc::string PreprocIf(const ::grpc::string& symbol,
58 const ::grpc::string& if_true) {
59 return ::grpc::string("#if " + PreprocConditional(symbol, false) + "\n" +
60 if_true + "#endif\n");
63 inline ::grpc::string PreprocIfNot(const ::grpc::string& symbol,
64 const ::grpc::string& if_true) {
65 return ::grpc::string("#if " + PreprocConditional(symbol, true) + "\n" +
66 if_true + "#endif\n");
69 inline ::grpc::string PreprocIfElse(const ::grpc::string& symbol,
70 const ::grpc::string& if_true,
71 const ::grpc::string& if_false) {
72 return ::grpc::string("#if " + PreprocConditional(symbol, false) + "\n" +
73 if_true + "#else\n" + if_false + "#endif\n");
76 inline ::grpc::string PreprocIfNotElse(const ::grpc::string& symbol,
77 const ::grpc::string& if_true,
78 const ::grpc::string& if_false) {
79 return ::grpc::string("#if " + PreprocConditional(symbol, true) + "\n" +
80 if_true + "#else\n" + if_false + "#endif\n");
83 } // namespace grpc_objective_c_generator
84 #endif // GRPC_INTERNAL_COMPILER_OBJECTIVE_C_GENERATOR_HELPERS_H