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 <boost/regex.hpp>
29 
30 #include <SimoxUtility/algorithm/string/string_tools.h>
31 
32 namespace armarx
33 {
34  std::string
36  std::string name,
37  std::string description,
38  std::string min,
39  std::string max,
40  std::string default_,
41  std::string casesensitivity,
42  std::string requirement,
43  std::string regex,
44  std::vector<std::string> values,
45  std::string value)
46  {
47  std::string pageHeader;
48 
49  if (prefix != lastPrefix)
50  {
51  const boost::regex rx("[a-zA-Z0-9_\\-]+\\.([a-zA-Z0-9_\\-]+)\\.");
52  boost::match_results<std::string::const_iterator> results;
53 
54  pageHeader = "\n<!-- Prefix: " + prefix + " -->\n";
55 
56  if (boost::regex_match(
57  prefix, results, rx)) // Skip application properties (no component set) for now
58  {
59  pageHeader +=
60  "\\defgroup " + results[1] + "_properties " + results[1] + " Properties\n";
61  pageHeader += "\\ingroup Component-" + results[1] + " componentproperties\n";
62  pageHeader +=
63  "\\brief This page shows the properties for the component \\ref Component-" +
64  results[1] + " \"" + results[1] + "\".\n\n";
65  }
66  else if (!lastPrefix.empty())
67  {
68  throw std::runtime_error("Non-component (application-specific) properties not at "
69  "beginning of iteration! (this should never happen)");
70  }
71 
72  // 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";
73  pageHeader += "Name & Description | Default | Bounds | Case-sensitive? | Required | "
74  "Regex | Values\n";
75  pageHeader +=
76  "---- | ------- | ------ | --------------- | -------- | ----- | ------\n";
77 
78  lastPrefix = prefix;
79  }
80 
81  std::string output = getFormat();
82 
83  output = simox::alg::replace_first(
84  output, "%name%", escapeMarkdown(formatName(getPrefix() + name)));
85  output = simox::alg::replace_first(
86  output, "%description%", escapeMarkdown(formatDescription(description)));
87  output =
88  simox::alg::replace_first(output, "%bounds%", escapeMarkdown(formatBounds(min, max)));
89  output =
90  simox::alg::replace_first(output, "%default%", escapeMarkdown(formatDefault(default_)));
91  output = simox::alg::replace_first(
92  output, "%casesensitive%", escapeMarkdown(formatCaseSensitivity(casesensitivity)));
93  output = simox::alg::replace_first(
94  output, "%required%", escapeMarkdown(formatRequirement(requirement)));
95  output = simox::alg::replace_first(output, "%regex%", escapeMarkdown(formatRegex(regex)));
96  output =
97  simox::alg::replace_first(output, "%values%", escapeMarkdown(formatValues(values)));
98 
99  return pageHeader + output;
100  }
101 
102  std::string
104  std::vector<std::string> mapValues)
105  {
106  // Largely copied from PropertyDefinitionDoxygenFormatter
107  std::string valueStrings;
108 
109  if (mapValues.size() > 0)
110  {
111  valueStrings += "{";
112 
113  std::vector<std::string>::iterator it = mapValues.begin();
114 
115  while (it != mapValues.end())
116  {
117  if (!it->empty())
118  {
119  valueStrings += formatValue(*it);
120  }
121 
122  ++it;
123 
124  if (it != mapValues.end())
125  {
126  valueStrings += ", ";
127  }
128  }
129 
130  valueStrings += "}";
131  }
132 
133  return valueStrings;
134  }
135 
136  std::string
138  std::string details)
139  {
140  return details;
141  }
142 
143  std::string
145  {
146  // 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");
147  return std::string("<b>%name%</b> <br/> %description% | <b>%default%</b> | %bounds% | "
148  "%casesensitive% | %required% | %regex% | %values%\n");
149  }
150 
151  std::string
152  PropertyDefinitionDoxygenComponentPagesFormatter::escapeMarkdown(std::string s)
153  {
154  s = simox::alg::replace_all(s, "\"", "\\\"");
155  s = simox::alg::replace_all(s, "*", "\\*");
156  s = simox::alg::replace_all(s, "#", "\\#");
157  s = simox::alg::replace_all(s, "(", "\\(");
158  s = simox::alg::replace_all(s, ")", "\\)");
159  s = simox::alg::replace_all(s, "[", "\\[");
160  s = simox::alg::replace_all(s, "]", "\\]");
161  s = simox::alg::replace_all(s, "<", "\\<");
162  s = simox::alg::replace_all(s, ">", "\\>");
163  // boost::replace_all(s, "/", "\\/");
164  // boost::replace_all(s, "{", "\\{");
165  // boost::replace_all(s, "}", "\\}");
166 
167  if (s.empty())
168  {
169  s = "-";
170  }
171 
172  return s;
173  }
174 } // namespace armarx
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::getFormat
std::string getFormat() override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:144
armarx::PropertyDefinitionDoxygenFormatter::formatRegex
std::string formatRegex(std::string regex) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:121
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::formatValues
std::string formatValues(std::vector< std::string > values) override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:103
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:297
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::PropertyDefinitionDoxygenFormatter::formatDescription
std::string formatDescription(std::string description) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:76
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:35
armarx::PropertyDefinitionFormatter::prefix
std::string prefix
Definition: PropertyDefinitionFormatter.h:84
armarx::PropertyDefinitionDoxygenFormatter::formatBounds
std::string formatBounds(std::string min, std::string max) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:82
armarx::PropertyDefinitionDoxygenFormatter::formatName
std::string formatName(std::string name) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:70
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
armarx::PropertyDefinitionDoxygenFormatter::formatDefault
std::string formatDefault(std::string default_) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:103
armarx::PropertyDefinitionDoxygenComponentPagesFormatter::formatAttribute
std::string formatAttribute(std::string name, std::string details) override
Definition: PropertyDefinitionDoxygenComponentPagesFormatter.cpp:137
armarx::PropertyDefinitionFormatter::getPrefix
virtual std::string getPrefix() const
Definition: PropertyDefinitionFormatter.h:78
PropertyDefinitionDoxygenComponentPagesFormatter.h
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:327
armarx::PropertyDefinitionDoxygenFormatter::formatValue
std::string formatValue(std::string value) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:159
armarx::PropertyDefinitionDoxygenFormatter::formatRequirement
std::string formatRequirement(std::string requirement) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:115
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:27
armarx::PropertyDefinitionDoxygenFormatter::formatCaseSensitivity
std::string formatCaseSensitivity(std::string caseSensitivity) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:109