MCPcopy Create free account
hub / github.com/Tencent/phxrpc / GenerateClientCpp

Method GenerateClientCpp

codegen/client_code_render.cpp:271–361  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269}
270
271void ClientCodeRender::GenerateClientCpp(SyntaxTree *stree, FILE *write, const bool is_uthread_mode) {
272 char client_class[128]{'\0'}, client_file[128]{'\0'};
273 char client_class_lower[128]{'\0'};
274 char stub_class[128]{'\0'}, stub_file[128]{'\0'};
275 name_render_.GetClientClassName(stree->GetName(), client_class, sizeof(client_class));
276 name_render_.GetClientClassNameLower(stree->GetName(), client_class_lower, sizeof(client_class_lower));
277 name_render_.GetClientFileName(stree->GetName(), client_file, sizeof(client_file));
278 name_render_.GetStubClassName(stree->GetName(), stub_class, sizeof(stub_class));
279 name_render_.GetStubFileName(stree->GetName(), stub_file, sizeof(stub_file));
280
281 string client_class_str = string(client_class);
282 string client_class_lower_str = string(client_class_lower);
283 if (is_uthread_mode) {
284 client_class_str += "UThread";
285 client_class_lower_str += "uthread";
286 }
287
288 string buffer;
289 name_render_.GetCopyright("phxrpc_pb2client", stree->GetProtoFile(), &buffer, false);
290
291 fprintf(write, "/* %s.cpp\n", client_file);
292 fprintf(write, "%s", buffer.c_str());
293 fprintf(write, "*/\n");
294
295 fprintf(write, "\n");
296
297 string functions;
298
299 {
300 SyntaxFuncVector *flist = stree->GetFuncList();
301 auto fit(flist->cbegin());
302 for (; flist->cend() != fit; ++fit) {
303 string buffer;
304 GetClienfuncDeclaration(stree, &(*fit), 0, &buffer, is_uthread_mode);
305
306 functions.append(buffer).append("\n");
307
308 string content;
309 if (!is_uthread_mode) {
310 content = PHXRPC_CLIENT_FUNC_TEMPLATE;
311 } else {
312 content = PHXRPC_UTHREAD_CLIENT_FUNC_TEMPLATE;
313 }
314
315 StrTrim(&content);
316 StrReplaceAll(&content, "$ClientClass$", client_class_str.c_str());
317 StrReplaceAll(&content, "$ClientClassLower$", client_class_lower_str.c_str());
318 StrReplaceAll(&content, "$StubClass$", stub_class);
319 StrReplaceAll(&content, "$Func$", fit->GetName());
320
321 functions.append(content).append("\n\n");
322
323 if (0 == strcmp(fit->GetName(), "PHXEcho")) {
324 SyntaxFunc echo_func = *fit;
325 echo_func.SetName("PHXBatchEcho");
326
327 string buffer;
328 GetClienfuncDeclaration(stree, &echo_func, 0, &buffer, is_uthread_mode);

Callers 1

Proto2ClientFunction · 0.80

Calls 13

StrTrimFunction · 0.85
StrReplaceAllFunction · 0.85
GetClientClassNameMethod · 0.80
GetNameMethod · 0.80
GetClientFileNameMethod · 0.80
GetStubClassNameMethod · 0.80
GetStubFileNameMethod · 0.80
GetCopyrightMethod · 0.80
GetProtoFileMethod · 0.80
GetFuncListMethod · 0.80
SetNameMethod · 0.80

Tested by

no test coverage detected