MCPcopy Create free account
hub / github.com/Tracktion/choc / demonstrateCodePrinter

Function demonstrateCodePrinter

examples/text_processing.cpp:312–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

310}
311
312void demonstrateCodePrinter()
313{
314 std::cout << "\n=== Code Printer Demo ===\n";
315
316 choc::text::CodePrinter printer;
317
318 // Generate some C++ code
319 printer << "// Auto-generated employee data structure\n";
320 printer << "#include <string>\n";
321 printer << "#include <vector>\n\n";
322
323 printer << "namespace Company" << choc::text::CodePrinter::NewLine();
324
325 {
326 auto ns_indent = printer.createIndentWithBraces();
327
328 printer << "struct Employee" << choc::text::CodePrinter::NewLine();
329
330 {
331 auto struct_indent = printer.createIndentWithBraces();
332
333 printer << "std::string name;" << choc::text::CodePrinter::NewLine();
334 printer << "std::string department;" << choc::text::CodePrinter::NewLine();
335 printer << "int age;" << choc::text::CodePrinter::NewLine();
336 printer << "double salary;" << choc::text::CodePrinter::NewLine();
337 printer << "std::string email;" << choc::text::CodePrinter::BlankLine();
338
339 printer << "Employee (const std::string& n, const std::string& d, int a, double s, const std::string& e)" << choc::text::CodePrinter::NewLine();
340
341 {
342 auto ctor_indent = printer.createIndent();
343 printer << ": name (n), department (d), age (a), salary (s), email (e) {}" << choc::text::CodePrinter::NewLine();
344 }
345 }
346 printer << choc::text::CodePrinter::BlankLine();
347
348 printer << "std::vector<Employee> getEmployees()" << choc::text::CodePrinter::NewLine();
349
350 {
351 auto func_indent = printer.createIndentWithBraces();
352
353 printer << "return" << choc::text::CodePrinter::NewLine();
354
355 {
356 auto return_indent = printer.createIndentWithBraces();
357
358 std::vector<Employee> employees =
359 {
360 {"Alice Johnson", "Engineering", 28, 75000.0, "alice@company.com"},
361 {"Bob Smith", "Marketing", 35, 65000.0, "bob@company.com"},
362 {"Carol Williams", "Engineering", 31, 82000.0, "carol@company.com"}
363 };
364
365 for (size_t i = 0; i < employees.size(); ++i)
366 {
367 const auto& emp = employees[i];
368
369 printer << "Employee (\"" << emp.name << "\", \"" << emp.department

Callers 1

mainFunction · 0.85

Calls 7

NewLineClass · 0.85
BlankLineClass · 0.85
createIndentMethod · 0.80
sizeMethod · 0.45
toStringMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected