PropertyDefinitionDoxygenFormatter.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 Jan Issac (jan dot issac at gmx dot de)
20 * @date 2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25
27
28#include <iomanip>
29#include <sstream>
30
31#include <SimoxUtility/algorithm/string/string_tools.h>
32
33namespace armarx
34{
35 std::string
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 output = getFormat();
48
49 output = simox::alg::replace_first(output, "%name%", formatName(getPrefix() + name));
50 output = simox::alg::replace_first(output, "%description%", formatDescription(description));
51 output = simox::alg::replace_first(output, "%bounds%", formatBounds(min, max));
52 output = simox::alg::replace_first(output, "%default%", formatDefault(default_));
53 output = simox::alg::replace_first(
54 output, "%casesensitive%", formatCaseSensitivity(casesensitivity));
55 output = simox::alg::replace_first(output, "%required%", formatRequirement(requirement));
56 output = simox::alg::replace_first(output, "%regex%", formatRegex(regex));
57 output = simox::alg::replace_first(output, "%values%", formatValues(values));
58
59 return formatDocComment(output);
60 }
61
62 std::string
64 {
65 return std::string("\\prop %name%: \n") + "%description%<br />\n" + "Attributes:\n" +
66 "%default%" + "%bounds%" + "%casesensitive%" + "%required%" + "%regex%" + "%values%";
67 }
68
69 std::string
71 {
72 return name;
73 }
74
75 std::string
77 {
78 return description;
79 }
80
81 std::string
83 {
84 std::string bounds;
85
86 if (!min.empty() && max.empty())
87 {
88 bounds = formatAttribute("Min:", min);
89 }
90 else if (min.empty() && !max.empty())
91 {
92 bounds = formatAttribute("Max:", max);
93 }
94 else if (!min.empty() && !max.empty())
95 {
96 bounds = formatAttribute("Bounds:", "[" + min + "; " + max + "]");
97 }
98
99 return bounds;
100 }
101
102 std::string
104 {
105 return formatAttribute("Default:", default_);
106 }
107
108 std::string
110 {
111 return formatAttribute("Case sensitivity:", caseSensitivity);
112 }
113
114 std::string
116 {
117 return formatAttribute("Required:", requirement);
118 }
119
120 std::string
122 {
123 return formatAttribute("Format:", regex);
124 }
125
126 std::string
127 PropertyDefinitionDoxygenFormatter::formatValues(std::vector<std::string> mapValues)
128 {
129 std::string valueStrings;
130
131 if (mapValues.size() > 0)
132 {
133 valueStrings += " - Possible values: {";
134
135 std::vector<std::string>::iterator it = mapValues.begin();
136
137 while (it != mapValues.end())
138 {
139 if (!it->empty())
140 {
141 valueStrings += formatValue(*it);
142 }
143
144 ++it;
145
146 if (it != mapValues.end())
147 {
148 valueStrings += ", ";
149 }
150 }
151
152 valueStrings += "}";
153 }
154
155 return valueStrings;
156 }
157
158 std::string
160 {
161 return value;
162 }
163
164 std::string
165 PropertyDefinitionDoxygenFormatter::formatAttribute(std::string name, std::string details)
166 {
167 if (!details.empty())
168 {
169 std::stringstream strStream;
170 strStream << std::setfill(' ') << std::left << std::setw(20) << name;
171 strStream << details;
172
173 return " - " + strStream.str() + "\n";
174 }
175
176 return std::string();
177 }
178
179 std::string
181 {
182 return "\n";
183 }
184
185 std::string
187 {
188 std::string line;
189 std::string docComment = "\n";
190
191 std::stringstream textStream(text);
192
193 while (std::getline(textStream, line, '\n'))
194 {
195 docComment += "" + line + "\n";
196 }
197
198 docComment += " \n";
199
200 return docComment;
201 }
202} // namespace armarx
std::string formatDefault(std::string default_) override
std::string formatBounds(std::string min, std::string max) override
std::string formatAttribute(std::string name, std::string details) override
std::string formatRequirement(std::string requirement) override
std::string formatValues(std::vector< std::string > values) override
std::string formatHeader(std::string headerText) override
std::string formatDescription(std::string description) override
std::string formatCaseSensitivity(std::string caseSensitivity) 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
virtual std::string formatDocComment(const std::string &text)
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)