cpp_generator.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  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
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  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.
  16. *
  17. */
  18. #ifndef GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
  19. #define GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H
  20. // cpp_generator.h/.cc do not directly depend on GRPC/ProtoBuf, such that they
  21. // can be used to generate code for other serialization systems, such as
  22. // FlatBuffers.
  23. #include <memory>
  24. #include <vector>
  25. #include "src/compiler/config.h"
  26. #include "src/compiler/schema_interface.h"
  27. #ifndef GRPC_CUSTOM_STRING
  28. #include <string>
  29. #define GRPC_CUSTOM_STRING std::string
  30. #endif
  31. namespace grpc {
  32. typedef GRPC_CUSTOM_STRING string;
  33. } // namespace grpc
  34. namespace grpc_cpp_generator {
  35. // Contains all the parameters that are parsed from the command line.
  36. struct Parameters {
  37. // Puts the service into a namespace
  38. grpc::string services_namespace;
  39. // Use system includes (<>) or local includes ("")
  40. bool use_system_headers;
  41. // Prefix to any grpc include
  42. grpc::string grpc_search_path;
  43. // Generate Google Mock code to facilitate unit testing.
  44. bool generate_mock_code;
  45. // Google Mock search path, when non-empty, local includes will be used.
  46. grpc::string gmock_search_path;
  47. // *EXPERIMENTAL* Additional include files in grpc.pb.h
  48. std::vector<grpc::string> additional_header_includes;
  49. // By default, use "pb.h"
  50. grpc::string message_header_extension;
  51. // Whether to include headers corresponding to imports in source file.
  52. bool include_import_headers;
  53. };
  54. // Return the prologue of the generated header file.
  55. grpc::string GetHeaderPrologue(grpc_generator::File* file,
  56. const Parameters& params);
  57. // Return the includes needed for generated header file.
  58. grpc::string GetHeaderIncludes(grpc_generator::File* file,
  59. const Parameters& params);
  60. // Return the includes needed for generated source file.
  61. grpc::string GetSourceIncludes(grpc_generator::File* file,
  62. const Parameters& params);
  63. // Return the epilogue of the generated header file.
  64. grpc::string GetHeaderEpilogue(grpc_generator::File* file,
  65. const Parameters& params);
  66. // Return the prologue of the generated source file.
  67. grpc::string GetSourcePrologue(grpc_generator::File* file,
  68. const Parameters& params);
  69. // Return the services for generated header file.
  70. grpc::string GetHeaderServices(grpc_generator::File* file,
  71. const Parameters& params);
  72. // Return the services for generated source file.
  73. grpc::string GetSourceServices(grpc_generator::File* file,
  74. const Parameters& params);
  75. // Return the epilogue of the generated source file.
  76. grpc::string GetSourceEpilogue(grpc_generator::File* file,
  77. const Parameters& params);
  78. // Return the prologue of the generated mock file.
  79. grpc::string GetMockPrologue(grpc_generator::File* file,
  80. const Parameters& params);
  81. // Return the includes needed for generated mock file.
  82. grpc::string GetMockIncludes(grpc_generator::File* file,
  83. const Parameters& params);
  84. // Return the services for generated mock file.
  85. grpc::string GetMockServices(grpc_generator::File* file,
  86. const Parameters& params);
  87. // Return the epilogue of generated mock file.
  88. grpc::string GetMockEpilogue(grpc_generator::File* file,
  89. const Parameters& params);
  90. // Return the prologue of the generated mock file.
  91. grpc::string GetMockPrologue(grpc_generator::File* file,
  92. const Parameters& params);
  93. // Return the includes needed for generated mock file.
  94. grpc::string GetMockIncludes(grpc_generator::File* file,
  95. const Parameters& params);
  96. // Return the services for generated mock file.
  97. grpc::string GetMockServices(grpc_generator::File* file,
  98. const Parameters& params);
  99. // Return the epilogue of generated mock file.
  100. grpc::string GetMockEpilogue(grpc_generator::File* file,
  101. const Parameters& params);
  102. } // namespace grpc_cpp_generator
  103. #endif // GRPC_INTERNAL_COMPILER_CPP_GENERATOR_H