Removing "using namespace std" everywhere.

pull/72/head
Nicolas Noble 10 years ago
parent 07c7c680e8
commit f5c5d80968
  1. 30
      src/compiler/cpp_generator.cc
  2. 10
      src/compiler/cpp_generator.h
  3. 25
      src/compiler/cpp_generator_helpers.h
  4. 10
      src/compiler/cpp_plugin.cc
  5. 30
      src/compiler/ruby_generator.cc
  6. 4
      src/compiler/ruby_generator.h
  7. 4
      src/compiler/ruby_generator_helpers-inl.h
  8. 9
      src/compiler/ruby_generator_map-inl.h
  9. 39
      src/compiler/ruby_generator_string-inl.h
  10. 8
      src/compiler/ruby_plugin.cc

@ -92,8 +92,8 @@ bool HasBidiStreaming(const google::protobuf::FileDescriptor* file) {
} }
} // namespace } // namespace
string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) { std::string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) {
string temp = std::string temp =
"#include \"grpc++/impl/internal_stub.h\"\n" "#include \"grpc++/impl/internal_stub.h\"\n"
"#include \"grpc++/status.h\"\n" "#include \"grpc++/status.h\"\n"
"\n" "\n"
@ -121,7 +121,7 @@ string GetHeaderIncludes(const google::protobuf::FileDescriptor* file) {
return temp; return temp;
} }
string GetSourceIncludes() { std::string GetSourceIncludes() {
return "#include \"grpc++/channel_interface.h\"\n" return "#include \"grpc++/channel_interface.h\"\n"
"#include \"grpc++/impl/rpc_method.h\"\n" "#include \"grpc++/impl/rpc_method.h\"\n"
"#include \"grpc++/impl/rpc_service_method.h\"\n" "#include \"grpc++/impl/rpc_service_method.h\"\n"
@ -130,7 +130,7 @@ string GetSourceIncludes() {
void PrintHeaderClientMethod(google::protobuf::io::Printer* printer, void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -159,7 +159,7 @@ void PrintHeaderClientMethod(google::protobuf::io::Printer* printer,
void PrintHeaderServerMethod(google::protobuf::io::Printer* printer, void PrintHeaderServerMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -193,7 +193,7 @@ void PrintHeaderServerMethod(google::protobuf::io::Printer* printer,
void PrintHeaderService(google::protobuf::io::Printer* printer, void PrintHeaderService(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service, const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) { std::map<std::string, std::string>* vars) {
(*vars)["Service"] = service->name(); (*vars)["Service"] = service->name();
printer->Print(*vars, printer->Print(*vars,
@ -238,11 +238,11 @@ void PrintHeaderService(google::protobuf::io::Printer* printer,
printer->Print("};\n"); printer->Print("};\n");
} }
string GetHeaderServices(const google::protobuf::FileDescriptor* file) { std::string GetHeaderServices(const google::protobuf::FileDescriptor* file) {
string output; std::string output;
google::protobuf::io::StringOutputStream output_stream(&output); google::protobuf::io::StringOutputStream output_stream(&output);
google::protobuf::io::Printer printer(&output_stream, '$'); google::protobuf::io::Printer printer(&output_stream, '$');
map<string, string> vars; std::map<std::string, std::string> vars;
for (int i = 0; i < file->service_count(); ++i) { for (int i = 0; i < file->service_count(); ++i) {
PrintHeaderService(&printer, file->service(i), &vars); PrintHeaderService(&printer, file->service(i), &vars);
@ -253,7 +253,7 @@ string GetHeaderServices(const google::protobuf::FileDescriptor* file) {
void PrintSourceClientMethod(google::protobuf::io::Printer* printer, void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -311,7 +311,7 @@ void PrintSourceClientMethod(google::protobuf::io::Printer* printer,
void PrintSourceServerMethod(google::protobuf::io::Printer* printer, void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
const google::protobuf::MethodDescriptor* method, const google::protobuf::MethodDescriptor* method,
map<string, string>* vars) { std::map<std::string, std::string>* vars) {
(*vars)["Method"] = method->name(); (*vars)["Method"] = method->name();
(*vars)["Request"] = (*vars)["Request"] =
grpc_cpp_generator::ClassName(method->input_type(), true); grpc_cpp_generator::ClassName(method->input_type(), true);
@ -361,7 +361,7 @@ void PrintSourceServerMethod(google::protobuf::io::Printer* printer,
void PrintSourceService(google::protobuf::io::Printer* printer, void PrintSourceService(google::protobuf::io::Printer* printer,
const google::protobuf::ServiceDescriptor* service, const google::protobuf::ServiceDescriptor* service,
map<string, string>* vars) { std::map<std::string, std::string>* vars) {
(*vars)["Service"] = service->name(); (*vars)["Service"] = service->name();
printer->Print( printer->Print(
*vars, *vars,
@ -455,11 +455,11 @@ void PrintSourceService(google::protobuf::io::Printer* printer,
printer->Print("}\n\n"); printer->Print("}\n\n");
} }
string GetSourceServices(const google::protobuf::FileDescriptor* file) { std::string GetSourceServices(const google::protobuf::FileDescriptor* file) {
string output; std::string output;
google::protobuf::io::StringOutputStream output_stream(&output); google::protobuf::io::StringOutputStream output_stream(&output);
google::protobuf::io::Printer printer(&output_stream, '$'); google::protobuf::io::Printer printer(&output_stream, '$');
map<string, string> vars; std::map<std::string, std::string> vars;
// Package string is empty or ends with a dot. It is used to fully qualify // Package string is empty or ends with a dot. It is used to fully qualify
// method names. // method names.
vars["Package"] = file->package(); vars["Package"] = file->package();

@ -42,21 +42,19 @@ class FileDescriptor;
} // namespace protobuf } // namespace protobuf
} // namespace google } // namespace google
using namespace std;
namespace grpc_cpp_generator { namespace grpc_cpp_generator {
// Return the includes needed for generated header file. // Return the includes needed for generated header file.
string GetHeaderIncludes(const google::protobuf::FileDescriptor* file); std::string GetHeaderIncludes(const google::protobuf::FileDescriptor* file);
// Return the includes needed for generated source file. // Return the includes needed for generated source file.
string GetSourceIncludes(); std::string GetSourceIncludes();
// Return the services for generated header file. // Return the services for generated header file.
string GetHeaderServices(const google::protobuf::FileDescriptor* file); std::string GetHeaderServices(const google::protobuf::FileDescriptor* file);
// Return the services for generated source file. // Return the services for generated source file.
string GetSourceServices(const google::protobuf::FileDescriptor* file); std::string GetSourceServices(const google::protobuf::FileDescriptor* file);
} // namespace grpc_cpp_generator } // namespace grpc_cpp_generator

@ -39,14 +39,12 @@
#include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.pb.h>
using namespace std;
namespace grpc_cpp_generator { namespace grpc_cpp_generator {
inline bool StripSuffix(string* filename, const string& suffix) { inline bool StripSuffix(std::string* filename, const std::string& suffix) {
if (filename->length() >= suffix.length()) { if (filename->length() >= suffix.length()) {
size_t suffix_pos = filename->length() - suffix.length(); size_t suffix_pos = filename->length() - suffix.length();
if (filename->compare(suffix_pos, string::npos, suffix) == 0) { if (filename->compare(suffix_pos, std::string::npos, suffix) == 0) {
filename->resize(filename->size() - suffix.size()); filename->resize(filename->size() - suffix.size());
return true; return true;
} }
@ -55,19 +53,20 @@ inline bool StripSuffix(string* filename, const string& suffix) {
return false; return false;
} }
inline string StripProto(string filename) { inline std::string StripProto(std::string filename) {
if (!StripSuffix(&filename, ".protodevel")) { if (!StripSuffix(&filename, ".protodevel")) {
StripSuffix(&filename, ".proto"); StripSuffix(&filename, ".proto");
} }
return filename; return filename;
} }
inline string StringReplace(string str, const string& from, const string& to) { inline std::string StringReplace(std::string str, const std::string& from,
const std::string& to) {
size_t pos = 0; size_t pos = 0;
for (;;) { for (;;) {
pos = str.find(from, pos); pos = str.find(from, pos);
if (pos == string::npos) { if (pos == std::string::npos) {
break; break;
} }
str.replace(pos, from.length(), to); str.replace(pos, from.length(), to);
@ -77,23 +76,23 @@ inline string StringReplace(string str, const string& from, const string& to) {
return str; return str;
} }
inline string DotsToColons(const string& name) { inline std::string DotsToColons(const std::string& name) {
return StringReplace(name, ".", "::"); return StringReplace(name, ".", "::");
} }
inline string DotsToUnderscores(const string& name) { inline std::string DotsToUnderscores(const std::string& name) {
return StringReplace(name, ".", "_"); return StringReplace(name, ".", "_");
} }
inline string ClassName(const google::protobuf::Descriptor* descriptor, inline std::string ClassName(const google::protobuf::Descriptor* descriptor,
bool qualified) { bool qualified) {
// Find "outer", the descriptor of the top-level message in which // Find "outer", the descriptor of the top-level message in which
// "descriptor" is embedded. // "descriptor" is embedded.
const google::protobuf::Descriptor* outer = descriptor; const google::protobuf::Descriptor* outer = descriptor;
while (outer->containing_type() != NULL) outer = outer->containing_type(); while (outer->containing_type() != NULL) outer = outer->containing_type();
const string& outer_name = outer->full_name(); const std::string& outer_name = outer->full_name();
string inner_name = descriptor->full_name().substr(outer_name.size()); std::string inner_name = descriptor->full_name().substr(outer_name.size());
if (qualified) { if (qualified) {
return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name); return "::" + DotsToColons(outer_name) + DotsToUnderscores(inner_name);

@ -50,9 +50,9 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
virtual ~CppGrpcGenerator() {} virtual ~CppGrpcGenerator() {}
virtual bool Generate(const google::protobuf::FileDescriptor* file, virtual bool Generate(const google::protobuf::FileDescriptor* file,
const string& parameter, const std::string& parameter,
google::protobuf::compiler::GeneratorContext* context, google::protobuf::compiler::GeneratorContext* context,
string* error) const { std::string* error) const {
if (file->options().cc_generic_services()) { if (file->options().cc_generic_services()) {
*error = *error =
"cpp grpc proto compiler plugin does not work with generic " "cpp grpc proto compiler plugin does not work with generic "
@ -61,7 +61,7 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
return false; return false;
} }
string file_name = grpc_cpp_generator::StripProto(file->name()); std::string file_name = grpc_cpp_generator::StripProto(file->name());
// Generate .pb.h // Generate .pb.h
Insert(context, file_name + ".pb.h", "includes", Insert(context, file_name + ".pb.h", "includes",
@ -80,8 +80,8 @@ class CppGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
private: private:
// Insert the given code into the given file at the given insertion point. // Insert the given code into the given file at the given insertion point.
void Insert(google::protobuf::compiler::GeneratorContext* context, void Insert(google::protobuf::compiler::GeneratorContext* context,
const string& filename, const string& insertion_point, const std::string& filename, const std::string& insertion_point,
const string& code) const { const std::string& code) const {
std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output( std::unique_ptr<google::protobuf::io::ZeroCopyOutputStream> output(
context->OpenForInsert(filename, insertion_point)); context->OpenForInsert(filename, insertion_point));
google::protobuf::io::CodedOutputStream coded_out(output.get()); google::protobuf::io::CodedOutputStream coded_out(output.get());

@ -56,17 +56,17 @@ namespace grpc_ruby_generator {
namespace { namespace {
// Prints out the method using the ruby gRPC DSL. // Prints out the method using the ruby gRPC DSL.
void PrintMethod(const MethodDescriptor* method, const string& package, void PrintMethod(const MethodDescriptor* method, const std::string& package,
Printer* out) { Printer* out) {
string input_type = RubyTypeOf(method->input_type()->name(), package); std::string input_type = RubyTypeOf(method->input_type()->name(), package);
if (method->client_streaming()) { if (method->client_streaming()) {
input_type = "stream(" + input_type + ")"; input_type = "stream(" + input_type + ")";
} }
string output_type = RubyTypeOf(method->output_type()->name(), package); std::string output_type = RubyTypeOf(method->output_type()->name(), package);
if (method->server_streaming()) { if (method->server_streaming()) {
output_type = "stream(" + output_type + ")"; output_type = "stream(" + output_type + ")";
} }
map<string, string> method_vars = ListToDict({ std::map<std::string, std::string> method_vars = ListToDict({
"mth.name", method->name(), "input.type", input_type, "output.type", "mth.name", method->name(), "input.type", input_type, "output.type",
output_type, output_type,
}); });
@ -74,22 +74,22 @@ void PrintMethod(const MethodDescriptor* method, const string& package,
} }
// Prints out the service using the ruby gRPC DSL. // Prints out the service using the ruby gRPC DSL.
void PrintService(const ServiceDescriptor* service, const string& package, void PrintService(const ServiceDescriptor* service, const std::string& package,
Printer* out) { Printer* out) {
if (service->method_count() == 0) { if (service->method_count() == 0) {
return; return;
} }
// Begin the service module // Begin the service module
map<string, string> module_vars = ListToDict({ std::map<std::string, std::string> module_vars = ListToDict({
"module.name", CapitalizeFirst(service->name()), "module.name", CapitalizeFirst(service->name()),
}); });
out->Print(module_vars, "module $module.name$\n"); out->Print(module_vars, "module $module.name$\n");
out->Indent(); out->Indent();
// TODO(temiola): add documentation // TODO(temiola): add documentation
string doc = "TODO: add proto service documentation here"; std::string doc = "TODO: add proto service documentation here";
map<string, string> template_vars = ListToDict({ std::map<std::string, std::string> template_vars = ListToDict({
"Documentation", doc, "Documentation", doc,
}); });
out->Print("\n"); out->Print("\n");
@ -103,7 +103,7 @@ void PrintService(const ServiceDescriptor* service, const string& package,
out->Print("\n"); out->Print("\n");
out->Print("self.marshal_class_method = :encode\n"); out->Print("self.marshal_class_method = :encode\n");
out->Print("self.unmarshal_class_method = :decode\n"); out->Print("self.unmarshal_class_method = :decode\n");
map<string, string> pkg_vars = ListToDict({ std::map<std::string, std::string> pkg_vars = ListToDict({
"service.name", service->name(), "pkg.name", package, "service.name", service->name(), "pkg.name", package,
}); });
out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n"); out->Print(pkg_vars, "self.service_name = '$pkg.name$.$service.name$'\n");
@ -124,8 +124,8 @@ void PrintService(const ServiceDescriptor* service, const string& package,
} // namespace } // namespace
string GetServices(const FileDescriptor* file) { std::string GetServices(const FileDescriptor* file) {
string output; std::string output;
StringOutputStream output_stream(&output); StringOutputStream output_stream(&output);
Printer out(&output_stream, '$'); Printer out(&output_stream, '$');
@ -136,7 +136,7 @@ string GetServices(const FileDescriptor* file) {
} }
// Write out a file header. // Write out a file header.
map<string, string> header_comment_vars = ListToDict({ std::map<std::string, std::string> header_comment_vars = ListToDict({
"file.name", file->name(), "file.package", file->package(), "file.name", file->name(), "file.package", file->package(),
}); });
out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n"); out.Print("# Generated by the protocol buffer compiler. DO NOT EDIT!\n");
@ -148,16 +148,16 @@ string GetServices(const FileDescriptor* file) {
// Write out require statemment to import the separately generated file // Write out require statemment to import the separately generated file
// that defines the messages used by the service. This is generated by the // that defines the messages used by the service. This is generated by the
// main ruby plugin. // main ruby plugin.
map<string, string> dep_vars = ListToDict({ std::map<std::string, std::string> dep_vars = ListToDict({
"dep.name", MessagesRequireName(file), "dep.name", MessagesRequireName(file),
}); });
out.Print(dep_vars, "require '$dep.name$'\n"); out.Print(dep_vars, "require '$dep.name$'\n");
// Write out services within the modules // Write out services within the modules
out.Print("\n"); out.Print("\n");
vector<string> modules = Split(file->package(), '.'); std::vector<std::string> modules = Split(file->package(), '.');
for (size_t i = 0; i < modules.size(); ++i) { for (size_t i = 0; i < modules.size(); ++i) {
map<string, string> module_vars = ListToDict({ std::map<std::string, std::string> module_vars = ListToDict({
"module.name", CapitalizeFirst(modules[i]), "module.name", CapitalizeFirst(modules[i]),
}); });
out.Print(module_vars, "module $module.name$\n"); out.Print(module_vars, "module $module.name$\n");

@ -36,8 +36,6 @@
#include <string> #include <string>
using namespace std;
namespace google { namespace google {
namespace protobuf { namespace protobuf {
class FileDescriptor; class FileDescriptor;
@ -46,7 +44,7 @@ class FileDescriptor;
namespace grpc_ruby_generator { namespace grpc_ruby_generator {
string GetServices(const google::protobuf::FileDescriptor* file); std::string GetServices(const google::protobuf::FileDescriptor* file);
} // namespace grpc_ruby_generator } // namespace grpc_ruby_generator

@ -42,7 +42,7 @@
namespace grpc_ruby_generator { namespace grpc_ruby_generator {
inline bool ServicesFilename(const google::protobuf::FileDescriptor* file, inline bool ServicesFilename(const google::protobuf::FileDescriptor* file,
string* file_name_or_error) { std::string* file_name_or_error) {
// Get output file name. // Get output file name.
static const unsigned proto_suffix_length = 6; // length of ".proto" static const unsigned proto_suffix_length = 6; // length of ".proto"
if (file->name().size() > proto_suffix_length && if (file->name().size() > proto_suffix_length &&
@ -57,7 +57,7 @@ inline bool ServicesFilename(const google::protobuf::FileDescriptor* file,
} }
} }
inline string MessagesRequireName( inline std::string MessagesRequireName(
const google::protobuf::FileDescriptor* file) { const google::protobuf::FileDescriptor* file) {
return Replace(file->name(), ".proto", ""); return Replace(file->name(), ".proto", "");
} }

@ -48,17 +48,18 @@ namespace grpc_ruby_generator {
// Converts an initializer list of the form { key0, value0, key1, value1, ... } // Converts an initializer list of the form { key0, value0, key1, value1, ... }
// into a map of key* to value*. Is merely a readability helper for later code. // into a map of key* to value*. Is merely a readability helper for later code.
inline map<string, string> ListToDict(const initializer_list<string>& values) { inline std::map<std::string, std::string> ListToDict(
const initializer_list<std::string>& values) {
if (values.size() % 2 != 0) { if (values.size() % 2 != 0) {
// MOE: insert std::cerr << "Not every 'key' has a value in `values`." // MOE: insert std::cerr << "Not every 'key' has a value in `values`."
// << std::endl; // << std::endl;
} }
map<string, string> value_map; std::map<std::string, std::string> value_map;
auto value_iter = values.begin(); auto value_iter = values.begin();
for (unsigned i = 0; i < values.size() / 2; ++i) { for (unsigned i = 0; i < values.size() / 2; ++i) {
string key = *value_iter; std::string key = *value_iter;
++value_iter; ++value_iter;
string value = *value_iter; std::string value = *value_iter;
value_map[key] = value; value_map[key] = value;
++value_iter; ++value_iter;
} }

@ -45,10 +45,10 @@ using std::transform;
namespace grpc_ruby_generator { namespace grpc_ruby_generator {
// Split splits a string using char into elems. // Split splits a string using char into elems.
inline vector<string>& Split(const string& s, char delim, inline std::vector<std::string>& Split(const std::string& s, char delim,
vector<string>* elems) { std::vector<std::string>* elems) {
stringstream ss(s); std::stringstream ss(s);
string item; std::string item;
while (getline(ss, item, delim)) { while (getline(ss, item, delim)) {
elems->push_back(item); elems->push_back(item);
} }
@ -56,16 +56,17 @@ inline vector<string>& Split(const string& s, char delim,
} }
// Split splits a string using char, returning the result in a vector. // Split splits a string using char, returning the result in a vector.
inline vector<string> Split(const string& s, char delim) { inline std::vector<std::string> Split(const std::string& s, char delim) {
vector<string> elems; std::vector<std::string> elems;
Split(s, delim, &elems); Split(s, delim, &elems);
return elems; return elems;
} }
// Replace replaces from with to in s. // Replace replaces from with to in s.
inline string Replace(string s, const string& from, const string& to) { inline std::string Replace(std::string s, const std::string& from,
const std::string& to) {
size_t start_pos = s.find(from); size_t start_pos = s.find(from);
if (start_pos == string::npos) { if (start_pos == std::string::npos) {
return s; return s;
} }
s.replace(start_pos, from.length(), to); s.replace(start_pos, from.length(), to);
@ -73,10 +74,10 @@ inline string Replace(string s, const string& from, const string& to) {
} }
// ReplaceAll replaces all instances of search with replace in s. // ReplaceAll replaces all instances of search with replace in s.
inline string ReplaceAll(string s, const string& search, inline std::string ReplaceAll(std::string s, const std::string& search,
const string& replace) { const std::string& replace) {
size_t pos = 0; size_t pos = 0;
while ((pos = s.find(search, pos)) != string::npos) { while ((pos = s.find(search, pos)) != std::string::npos) {
s.replace(pos, search.length(), replace); s.replace(pos, search.length(), replace);
pos += replace.length(); pos += replace.length();
} }
@ -84,9 +85,10 @@ inline string ReplaceAll(string s, const string& search,
} }
// ReplacePrefix replaces from with to in s if search is a prefix of s. // ReplacePrefix replaces from with to in s if search is a prefix of s.
inline bool ReplacePrefix(string* s, const string& from, const string& to) { inline bool ReplacePrefix(std::string* s, const std::string& from,
const std::string& to) {
size_t start_pos = s->find(from); size_t start_pos = s->find(from);
if (start_pos == string::npos || start_pos != 0) { if (start_pos == std::string::npos || start_pos != 0) {
return false; return false;
} }
s->replace(start_pos, from.length(), to); s->replace(start_pos, from.length(), to);
@ -94,7 +96,7 @@ inline bool ReplacePrefix(string* s, const string& from, const string& to) {
} }
// CapitalizeFirst capitalizes the first char in a string. // CapitalizeFirst capitalizes the first char in a string.
inline string CapitalizeFirst(string s) { inline std::string CapitalizeFirst(std::string s) {
if (s.empty()) { if (s.empty()) {
return s; return s;
} }
@ -103,14 +105,15 @@ inline string CapitalizeFirst(string s) {
} }
// RubyTypeOf updates a proto type to the required ruby equivalent. // RubyTypeOf updates a proto type to the required ruby equivalent.
inline string RubyTypeOf(const string& a_type, const string& package) { inline std::string RubyTypeOf(const std::string& a_type,
string res(a_type); const std::string& package) {
std::string res(a_type);
ReplacePrefix(&res, package, ""); // remove the leading package if present ReplacePrefix(&res, package, ""); // remove the leading package if present
ReplacePrefix(&res, ".", ""); // remove the leading . (no package) ReplacePrefix(&res, ".", ""); // remove the leading . (no package)
if (res.find('.') == string::npos) { if (res.find('.') == std::string::npos) {
return res; return res;
} else { } else {
vector<string> prefixes_and_type = Split(res, '.'); std::vector<std::string> prefixes_and_type = Split(res, '.');
for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) { for (unsigned int i = 0; i < prefixes_and_type.size(); ++i) {
if (i != 0) { if (i != 0) {
res += "::"; // switch '.' to the ruby module delim res += "::"; // switch '.' to the ruby module delim

@ -52,16 +52,16 @@ class RubyGrpcGenerator : public google::protobuf::compiler::CodeGenerator {
~RubyGrpcGenerator() override {} ~RubyGrpcGenerator() override {}
bool Generate(const google::protobuf::FileDescriptor* file, bool Generate(const google::protobuf::FileDescriptor* file,
const string& parameter, const std::string& parameter,
google::protobuf::compiler::GeneratorContext* context, google::protobuf::compiler::GeneratorContext* context,
string* error) const override { std::string* error) const override {
string code = grpc_ruby_generator::GetServices(file); std::string code = grpc_ruby_generator::GetServices(file);
if (code.size() == 0) { if (code.size() == 0) {
return true; // don't generate a file if there are no services return true; // don't generate a file if there are no services
} }
// Get output file name. // Get output file name.
string file_name; std::string file_name;
if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) { if (!grpc_ruby_generator::ServicesFilename(file, &file_name)) {
return false; return false;
} }

Loading…
Cancel
Save