Commit 65713933 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

modules.cc: merged from python_interface_changes.

parent bf7d07f6
...@@ -1349,50 +1349,21 @@ void close_library_handles() { ...@@ -1349,50 +1349,21 @@ void close_library_handles() {
#endif #endif
// helper function for setting the spacing in operatorPrintList // helper function for setting the spacing in operatorPrintList
std::string get_spacing_for(std::string str) { std::string get_spacing_for(int p_space, std::string str) {
int max = 16;
std::string spacing = ""; std::string spacing = "";
for (int i = str.size(); i <= max; i++) { for (int i = str.size(); i <= p_space; i++) {
spacing += " "; spacing += " ";
} }
return spacing; return spacing;
} }
/*** std::string get_operator_description(std::string p_current_op_name, std::vector<std::string> help)
* Prints all operator names and their short descriptions {
* Aliases are listed and point to their original operator name. std::string description = "";
* If the module is not documented the description is empty
* If a module has only one operator the short module description is listed
* If the operator is not documented the description is empty
*/
void operatorPrintList(bool print_no_output) {
std::vector<std::string> output_list ;
if(print_no_output)
{
output_list = get_no_output_operator_list();
}
else
{
output_list = get_sorted_operator_name_list();
}
std::vector<std::string> help;
unsigned long list_length = output_list.size();
unsigned long cur_help_idx; unsigned long cur_help_idx;
std::string line;
std::string description;
bool help_contains_name; bool help_contains_name;
std::string line;
for (unsigned long out_list_idx = 0; out_list_idx < list_length; out_list_idx++) {
std::string current_op_name = output_list[out_list_idx];
help = modules[get_module_name_to(current_op_name)].help;
if (aliases.find(current_op_name) != aliases.end()) {
output_list[out_list_idx] +=
std::string(get_spacing_for(current_op_name) + "--> " + aliases[current_op_name]);
}
else if (!help.empty()) {
description = "";
unsigned long operator_section = 0; unsigned long operator_section = 0;
cur_help_idx = 0; cur_help_idx = 0;
//search for operator section //search for operator section
while (operator_section == 0 && cur_help_idx < help.size() - 1) { while (operator_section == 0 && cur_help_idx < help.size() - 1) {
...@@ -1410,7 +1381,7 @@ void operatorPrintList(bool print_no_output) { ...@@ -1410,7 +1381,7 @@ void operatorPrintList(bool print_no_output) {
//search for the operator name in the description //search for the operator name in the description
while (!line.empty()) { while (!line.empty()) {
line = help[++cur_help_idx]; line = help[++cur_help_idx];
if (line.find(current_op_name) != std::string::npos) { if (line.find(p_current_op_name) != std::string::npos) {
help_contains_name = true; help_contains_name = true;
} }
name_section += line; name_section += line;
...@@ -1422,25 +1393,63 @@ void operatorPrintList(bool print_no_output) { ...@@ -1422,25 +1393,63 @@ void operatorPrintList(bool print_no_output) {
} }
} else { } else {
line = help[++operator_section]; line = help.at(++operator_section);
//search the operator section for current operator line //search the operator section for current operator line
while (line.find(current_op_name + " ") == std::string::npos && !line.empty() && while (line.find(p_current_op_name + " ") == std::string::npos && !line.empty() &&
operator_section < help.size()) { operator_section < help.size() - 1) {
line = help[++operator_section]; line = help.at(++operator_section);
;
} }
//if operator line found save description for later use //if operator line found save description for later use
if (!line.empty() && operator_section < help.size()) { if (!line.empty() && operator_section < help.size()) {
auto op_name_start = line.find_first_not_of(" \t"); auto op_name_start = line.find_first_not_of(" \t");
description = line.substr( description = line.substr(
line.find_first_not_of(" \t", op_name_start + current_op_name.size()), line.find_first_not_of(" \t", op_name_start + p_current_op_name.size()),
line.size()); line.size());
} }
} }
return description;
}
/***
* Prints all operator names and their short descriptions
* Aliases are listed and point to their original operator name.
* If the module is not documented the description is empty
* If a module has only one operator the short module description is listed
* If the operator is not documented the description is empty
*/
void operatorPrintList(bool print_no_output) {
std::vector<std::string> output_list ;
if(print_no_output)
{
output_list = get_no_output_operator_list();
}
else
{
output_list = get_sorted_operator_name_list();
}
unsigned long list_length = output_list.size();
modules_t *current_module;
//help variables
for (unsigned long out_list_idx = 0; out_list_idx < list_length; out_list_idx++) {
std::string current_op_name = output_list[out_list_idx];
current_module = &modules[get_module_name_to(current_op_name)];
if (aliases.find(current_op_name) != aliases.end()) {
output_list[out_list_idx] +=
std::string(get_spacing_for(16, current_op_name) + "--> " + aliases[current_op_name]);
}
else if (!current_module->help.empty()) {
//add spaceing and saving output line to the output list //add spaceing and saving output line to the output list
output_list[out_list_idx] += get_spacing_for(current_op_name) + description; std::string description = get_operator_description(current_op_name, current_module->help);
output_list[out_list_idx] += get_spacing_for(16, current_op_name) + description;
} }
std::string in_out_info = "(" + std::to_string(current_module->streamInCnt)
+ "|" + std::to_string(current_module->streamOutCnt)
+ ")";
output_list[out_list_idx] += get_spacing_for(90, output_list[out_list_idx]) + in_out_info;
} }
//print generated output list //print generated output list
for (std::string str : output_list) { for (std::string str : output_list) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment