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
32namespace 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
std::string formatAttribute(std::string name, std::string details) override
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
std::string formatDefault(std::string default_) override
std::string formatBounds(std::string min, std::string max) override
std::string formatRequirement(std::string requirement) override
std::string formatDescription(std::string description) override
std::string formatCaseSensitivity(std::string caseSensitivity) override
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)