CppPbUtils.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Generates C++ tars service interface out of Protobuf IDL.
  2. //
  3. // This is a Proto2 compiler plugin. See net/proto2/compiler/proto/plugin.proto
  4. // and net/proto2/compiler/public/plugin.h for more information on plugins.
  5. #include <cassert>
  6. #include "CppPbUtils.h"
  7. std::string ProtoFileBaseName(const std::string& fullName) {
  8. std::size_t p = fullName.rfind(".");
  9. assert (p != std::string::npos);
  10. return fullName.substr(0, p);
  11. }
  12. const std::string kDeclaration = "/**\n"
  13. " * Tencent is pleased to support the open source community by making Tars available.\n"
  14. " * Copyright (C) 2016 THL A29 Limited, a Tencent company. All rights reserved.\n"
  15. " * Licensed under the BSD 3-Clause License (the \"License\"); you may not use this file\n"
  16. " * except in compliance with the License. You may obtain a copy of the License at\n"
  17. " * https://opensource.org/licenses/BSD-3-Clause\n"
  18. " * Unless required by applicable law or agreed to in writing, software distributed\n"
  19. " * under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR\n"
  20. " * CONDITIONS OF ANY KIND, either express or implied. See the License for the\n"
  21. " * specific language governing permissions and limitations under the License.\n"
  22. " */\n\n";
  23. const std::string kIndent = " ";
  24. std::string LineFeed(int indent) {
  25. std::string data("\n");
  26. for (int i = 0; i < indent; ++i)
  27. data += kIndent;
  28. return data;
  29. }
  30. std::string ToCppNamespace(const std::string& name) {
  31. std::string ret;
  32. for(auto &c: name) {
  33. if(c == '.') {
  34. ret += "::";
  35. } else {
  36. ret += c;
  37. }
  38. }
  39. return ret;
  40. }