YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
generate_md.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024-2024 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "generator.h"
7#include <sstream>
8#include <iomanip>
9#include <algorithm>
10#include <string>
11
12// Example:
13
14// | Group | Parameter | Type | Units | Default Value | Required | Description | Notes |
15// |:--------------:|:------------:|:---------:|:--------:|:--------------:|:---------:|:-------------:|:-------:|
16// | myGroupName | myParamName | string | myUnits | myDefaultValue | true | myDescription | myNotes |
17// | myGroupName | myParamName | string | myUnits | myDefaultValue | true | myDescription | myNotes |
18// | myGroupName | myParamName | string | myUnits | myDefaultValue | true | myDescription | myNotes |
19
21{
22 std::ostringstream s;
23
24 std::vector<size_t> fill_siz(8);
25 fill_siz[0] = std::string("Group name").length();
26 fill_siz[1] = std::string("Parameter name").length();
27 fill_siz[2] = std::string("Type").length();
28 fill_siz[3] = std::string("Units").length();
29 fill_siz[4] = std::string("Default Value").length();
30 fill_siz[5] = std::string("Required").length();
31 fill_siz[6] = std::string("Description").length();
32 fill_siz[7] = std::string("Notes").length();
33
34 for (const auto& param : m_params) {
35 std::string fullgroupname = param.getFullGroupOnlyName();
36 std::string paramname = param.getParamOnly();
37 fill_siz[0] = std::max(fill_siz[0], fullgroupname.length());
38 fill_siz[1] = std::max(fill_siz[1], paramname.length());
39 fill_siz[2] = std::max(fill_siz[2], param.type.length());
40 fill_siz[3] = std::max(fill_siz[3], param.units.length());
41 fill_siz[4] = std::max(fill_siz[4], param.defaultValue.length());
42 fill_siz[5] = std::max(fill_siz[5], std::string("true").length());
43 fill_siz[6] = std::max(fill_siz[6], param.description.length());
44 fill_siz[7] = std::max(fill_siz[7], param.notes.length());
45 }
46
47 s << " | " << std::setw(fill_siz[0]) << std::left << "Group name";
48 s << " | " << std::setw(fill_siz[1]) << std::left << "Parameter name";
49 s << " | " << std::setw(fill_siz[2]) << std::left << "Type";
50 s << " | " << std::setw(fill_siz[3]) << std::left << "Units";
51 s << " | " << std::setw(fill_siz[4]) << std::left << "Default Value";
52 s << " | " << std::setw(fill_siz[5]) << std::left << "Required";
53 s << " | " << std::setw(fill_siz[6]) << std::left << "Description";
54 s << " | " << std::setw(fill_siz[7]) << std::left << "Notes";
55 s << " |\n";
56
57 s << std::setfill('-');
58 s << " |:" << std::setw(fill_siz[0]) << std::left << "-";
59 s << ":|:" << std::setw(fill_siz[1]) << std::left << "-";
60 s << ":|:" << std::setw(fill_siz[2]) << std::left << "-";
61 s << ":|:" << std::setw(fill_siz[3]) << std::left << "-";
62 s << ":|:" << std::setw(fill_siz[4]) << std::left << "-";
63 s << ":|:" << std::setw(fill_siz[5]) << std::left << "-";
64 s << ":|:" << std::setw(fill_siz[6]) << std::left << "-";
65 s << ":|:" << std::setw(fill_siz[7]) << std::left << "-";
66 s << ":|\n";
67
68 s << std::setfill(' ');
69 for (auto param : m_params)
70 {
71 std::string paramGroup = param.getFullGroupOnlyName();
72 std::string paramName = param.getParamOnly();
73 std::string type = param.type;
74 std::string units = param.units;
75 std::string defaultValue = param.defaultValue;
76 std::string description = param.description;
77 std::string notes = param.notes;
78 if (paramGroup.empty()) paramGroup = "-";
79 if (paramName.empty()) paramName = "-";
80 if (type.empty()) type = "-";
81 if (units.empty()) units = "-";
82 if (defaultValue.empty()) defaultValue = "-";
83 if (description.empty()) description = "-";
84 if (notes.empty()) notes = "-";
85
86 s << " | " << std::setw(fill_siz[0]) << std::left << paramGroup;
87 s << " | " << std::setw(fill_siz[1]) << std::left << paramName;
88 s << " | " << std::setw(fill_siz[2]) << std::left << type;
89 s << " | " << std::setw(fill_siz[3]) << std::left << units;
90 s << " | " << std::setw(fill_siz[4]) << std::left << defaultValue;
91 s << " | " << std::setw(fill_siz[5]) << std::left << param.required;
92 s << " | " << std::setw(fill_siz[6]) << std::left << description;
93 s << " | " << std::setw(fill_siz[7]) << std::left << notes;
94 s << " |\n";
95 }
96 s << "\n";
97 return s.str();
98}
99
101{
102 std::ostringstream s;
103 s << "These are the parameters used by class:" << m_classname << ".\n";
104 s << generateMdParams();
105 return s.str();
106}
std::string m_classname
Definition generator.h:38
std::string generateReadmeMd()
std::string generateMdParams()
std::deque< Parameter > m_params
Definition generator.h:34