PropertyDefinitionXmlFormatter.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
34
35namespace armarx
36{
37 std::string
39 std::string description,
40 std::string min,
41 std::string max,
42 std::string default_,
43 std::string casesensitivity,
44 std::string requirement,
45 std::string regex,
46 std::vector<std::string> values,
47 std::string value)
48 {
49 std::string output = getFormat();
50
51 output = simox::alg::replace_first(output, "%name%", formatName(getPrefix() + name));
52 output = simox::alg::replace_first(output, "%description%", formatDescription(description));
53 output = simox::alg::replace_first(output, "%bounds%", formatBounds(min, max));
54 output = simox::alg::replace_first(output, "%default%", formatDefault(default_));
55 output = simox::alg::replace_first(
56 output, "%casesensitive%", formatCaseSensitivity(casesensitivity));
57 output = simox::alg::replace_first(output, "%required%", formatRequirement(requirement));
58 output = simox::alg::replace_first(output, "%regex%", formatRegex(regex));
59 output = simox::alg::replace_first(output, "%values%", formatValues(values));
60 output = simox::alg::replace_first(output, "%value%", formatValue(value));
61
62 return output + "\n";
63 }
64
65 std::string
67 {
68 return std::string("<property name=\"%name%\">\n") + " %description%" +
69 " <attributes>\n" + "%default%" + "%bounds%" + "%casesensitive%" + "%required%" +
70 "%regex%" + "%values%" + "%value%" + " </attributes>\n" + "</property>\n";
71 }
72
73 std::string
75 {
76 return name;
77 }
78
79 std::string
81 {
82 return "<description>" + Encode(description) + "</description>\n";
83 }
84
85 std::string
87 {
88 std::string bounds;
89
90 bounds = formatAttribute("min", min);
91 bounds += formatAttribute("max", max);
92
93 return bounds;
94 }
95
96 std::string
98 {
99 return formatAttribute("Default", default_);
100 }
101
102 std::string
104 {
105 return formatAttribute("CaseSensitivity", caseSensitivity);
106 }
107
108 std::string
110 {
111 return formatAttribute("Required", requirement);
112 }
113
114 std::string
116 {
117 return formatAttribute("Format", regex);
118 }
119
120 std::string
121 PropertyDefinitionXmlFormatter::formatValues(std::vector<std::string> mapValues)
122 {
123 std::string valueStrings;
124
125 if (mapValues.size() > 0)
126 {
127 valueStrings += " <values>\n";
128
129 std::vector<std::string>::iterator it = mapValues.begin();
130
131 while (it != mapValues.end())
132 {
133 if (!it->empty())
134 {
135 valueStrings += formatValue(*it);
136 }
137
138 ++it;
139 }
140
141 valueStrings += " </values>\n";
142 }
143
144 return valueStrings;
145 }
146
147 std::string
149 {
150 if (value.empty())
151 {
152 return "";
153 }
154
155 return " <value>" + value + "</value>\n";
156 }
157
158 std::string
159 PropertyDefinitionXmlFormatter::formatAttribute(std::string name, std::string details)
160 {
161 if (!details.empty())
162 {
163 return " <attribute name=\"" + getPrefix() + name + "\">" + details +
164 "</attribute>\n";
165 }
166
167 return std::string();
168 }
169
170 std::string
172 {
173 return "<!-- " + headerText + " -->\n\n";
174 }
175} // 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::string Encode(const std::string &data)
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)