PropertyDefinitionHelpFormatter.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 output + "\n";
60 }
61
62 std::string
64 {
65 return std::string("%name%:") + " %description%\n" + " Attributes:\n" + "%default%" +
66 "%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 PropertyDefinitionHelpFormatter::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 valueStrings += (it != mapValues.end() ? ", " : "\n");
147 }
148 }
149
150 return valueStrings;
151 }
152
153 std::string
155 {
156 return value;
157 }
158
159 std::string
160 PropertyDefinitionHelpFormatter::formatAttribute(std::string name, std::string details)
161 {
162 if (!details.empty())
163 {
164 std::stringstream strStream;
165 strStream << std::setfill(' ') << std::left << std::setw(20) << name;
166 strStream << details;
167
168 return " - " + strStream.str() + "\n";
169 }
170
171 return std::string();
172 }
173
174 std::string
176 {
177 return "==================================================================\n" + headerText +
178 "\n" + "==================================================================\n\n";
179 }
180} // 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 formatName(std::string name) override
std::string formatValue(std::string value) override
std::string formatRequirement(std::string requirement) override
std::string formatRegex(std::string regex) 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
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)