PropertyDefinitionDoxygenComponentPagesFormatter.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package ArmarXCore::core
19  * @author Christian Mandery (mandery@kit.edu)
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 
27 
28 #include <SimoxUtility/algorithm/string/string_tools.h>
29 
30 #include <boost/regex.hpp>
31 
32 namespace armarx
33 {
35  std::string name,
36  std::string description,
37  std::string min,
38  std::string max,
39  std::string default_,
40  std::string casesensitivity,
41  std::string requirement,
42  std::string regex,
43  std::vector<std::string> values,
44  std::string value)
45  {
46  std::string pageHeader;
47 
48  if (prefix != lastPrefix)
49  {
50  const boost::regex rx("[a-zA-Z0-9_\\-]+\\.([a-zA-Z0-9_\\-]+)\\.");
51  boost::match_results<std::string::const_iterator> results;
52 
53  pageHeader = "\n<!-- Prefix: " + prefix + " -->\n";
54 
55  if (boost::regex_match(prefix, results, rx)) // Skip application properties (no component set) for now
56  {
57  pageHeader += "\\defgroup " + results[1] + "_properties " + results[1] + " Properties\n";
58  pageHeader += "\\ingroup Component-" + results[1] + " componentproperties\n";
59  pageHeader += "\\brief This page shows the properties for the component \\ref Component-" + results[1] + " \"" + results[1] + "\".\n\n";
60  }
61  else if (!lastPrefix.empty())
62  {
63  throw std::runtime_error("Non-component (application-specific) properties not at beginning of iteration! (this should never happen)");
64  }
65 
66  // pageHeader += "<th><td>Name</td><td>Description</td><td>Default</td><td>Bounds</td><td>Case-sensitive?</td><td>Required</td><td>Regex</td><td>Values</td></th>\n";
67  pageHeader += "Name & Description | Default | Bounds | Case-sensitive? | Required | Regex | Values\n";
68  pageHeader += "---- | ------- | ------ | --------------- | -------- | ----- | ------\n";
69 
70  lastPrefix = prefix;
71  }
72 
73  std::string output = getFormat();
74 
75  output = simox::alg::replace_first(output, "%name%", escapeMarkdown(formatName(getPrefix() + name)));
76  output = simox::alg::replace_first(output, "%description%", escapeMarkdown(formatDescription(description)));
77  output = simox::alg::replace_first(output, "%bounds%", escapeMarkdown(formatBounds(min, max)));
78  output = simox::alg::replace_first(output, "%default%", escapeMarkdown(formatDefault(default_)));
79  output = simox::alg::replace_first(output, "%casesensitive%", escapeMarkdown(formatCaseSensitivity(casesensitivity)));
80  output = simox::alg::replace_first(output, "%required%", escapeMarkdown(formatRequirement(requirement)));
81  output = simox::alg::replace_first(output, "%regex%", escapeMarkdown(formatRegex(regex)));
82  output = simox::alg::replace_first(output, "%values%", escapeMarkdown(formatValues(values)));
83 
84  return pageHeader + output;
85  }
86 
87  std::string PropertyDefinitionDoxygenComponentPagesFormatter::formatValues(std::vector<std::string> mapValues)
88  {
89  // Largely copied from PropertyDefinitionDoxygenFormatter
90  std::string valueStrings;
91 
92  if (mapValues.size() > 0)
93  {
94  valueStrings += "{";
95 
96  std::vector<std::string>::iterator it = mapValues.begin();
97 
98  while (it != mapValues.end())
99  {
100  if (!it->empty())
101  {
102  valueStrings += formatValue(*it);
103  }
104 
105  ++it;
106 
107  if (it != mapValues.end())
108  {
109  valueStrings += ", ";
110  }
111  }
112 
113  valueStrings += "}";
114  }
115 
116  return valueStrings;
117  }
118 
119  std::string PropertyDefinitionDoxygenComponentPagesFormatter::formatAttribute(std::string name, std::string details)
120  {
121  return details;
122  }
123 
125  {
126  // return std::string("<tr><td>%name%</td><td>%description%</td><td>%default%</td><td>%bounds%</td><td>%casesensitive%</td><td>%required%</td><td>%regex%</td><td>%values%</td></tr>\n");
127  return std::string("<b>%name%</b> <br/> %description% | <b>%default%</b> | %bounds% | %casesensitive% | %required% | %regex% | %values%\n");
128  }
129 
130  std::string PropertyDefinitionDoxygenComponentPagesFormatter::escapeMarkdown(std::string s)
131  {
132  s = simox::alg::replace_all(s, "\"", "\\\"");
133  s = simox::alg::replace_all(s, "*", "\\*");
134  s = simox::alg::replace_all(s, "#", "\\#");
135  s = simox::alg::replace_all(s, "(", "\\(");
136  s = simox::alg::replace_all(s, ")", "\\)");
137  s = simox::alg::replace_all(s, "[", "\\[");
138  s = simox::alg::replace_all(s, "]", "\\]");
139  s = simox::alg::replace_all(s, "<", "\\<");
140  s = simox::alg::replace_all(s, ">", "\\>");
141  // boost::replace_all(s, "/", "\\/");
142  // boost::replace_all(s, "{", "\\{");
143  // boost::replace_all(s, "}", "\\}");
144 
145  if (s.empty())
146  {
147  s = "-";
148  }
149 
150  return s;
151  }
152 }
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::getFormat
std::string getFormat() override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:124
armarx::PropertyDefinitionDoxygenFormatter::formatRegex
std::string formatRegex(std::string regex) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:119
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::formatValues
std::string formatValues(std::vector< std::string > values) override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:87
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::PropertyDefinitionDoxygenFormatter::formatDescription
std::string formatDescription(std::string description) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:79
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::formatDefinition
std::string formatDefinition(std::string name, std::string description, std::string min, std::string max, std::string default_, std::string casesensitivity, std::string requirement, std::string reged, std::vector< std::string > values, std::string value) override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:34
armarx::PropertyDefinitionFormatter::prefix
std::string prefix
Definition: PropertyDefinitionFormatter.h:81
armarx::PropertyDefinitionDoxygenFormatter::formatBounds
std::string formatBounds(std::string min, std::string max) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:84
armarx::PropertyDefinitionDoxygenFormatter::formatName
std::string formatName(std::string name) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:74
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::PropertyDefinitionDoxygenFormatter::formatDefault
std::string formatDefault(std::string default_) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:104
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::formatAttribute
std::string formatAttribute(std::string name, std::string details) override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:119
armarx::PropertyDefinitionFormatter::getPrefix
virtual std::string getPrefix() const
Definition: PropertyDefinitionFormatter.h:75
PropertyDefinitionDoxygenComponentPagesFormatter.h
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::PropertyDefinitionDoxygenFormatter::formatValue
std::string formatValue(std::string value) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:156
armarx::PropertyDefinitionDoxygenFormatter::formatRequirement
std::string formatRequirement(std::string requirement) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:114
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PropertyDefinitionDoxygenFormatter::formatCaseSensitivity
std::string formatCaseSensitivity(std::string caseSensitivity) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:109