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 
29 
30 #include <SimoxUtility/algorithm/string/string_tools.h>
31 
32 #include <sstream>
33 #include <iomanip>
34 
35 
36 namespace armarx
37 {
39  std::string name,
40  std::string description,
41  std::string min,
42  std::string max,
43  std::string default_,
44  std::string casesensitivity,
45  std::string requirement,
46  std::string regex,
47  std::vector<std::string> values,
48  std::string value)
49  {
50  std::string output = getFormat();
51 
52  output = simox::alg::replace_first(output, "%name%", formatName(getPrefix() + name));
53  output = simox::alg::replace_first(output, "%description%", formatDescription(description));
54  output = simox::alg::replace_first(output, "%bounds%", formatBounds(min, max));
55  output = simox::alg::replace_first(output, "%default%", formatDefault(default_));
56  output = simox::alg::replace_first(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 
67  {
68  return std::string("<property name=\"%name%\">\n")
69  + " %description%"
70  + " <attributes>\n"
71  + "%default%"
72  + "%bounds%"
73  + "%casesensitive%"
74  + "%required%"
75  + "%regex%"
76  + "%values%"
77  + "%value%"
78  + " </attributes>\n"
79  + "</property>\n";
80  }
81 
82 
83  std::string PropertyDefinitionXmlFormatter::formatName(std::string name)
84  {
85  return name;
86  }
87 
88 
89  std::string PropertyDefinitionXmlFormatter::formatDescription(std::string description)
90  {
91  return "<description>" + Encode(description) + "</description>\n";
92  }
93 
94 
95  std::string PropertyDefinitionXmlFormatter::formatBounds(std::string min, std::string max)
96  {
97  std::string bounds;
98 
99  bounds = formatAttribute("min", min);
100  bounds += formatAttribute("max", max);
101 
102  return bounds;
103  }
104 
105 
106  std::string PropertyDefinitionXmlFormatter::formatDefault(std::string default_)
107  {
108  return formatAttribute("Default", default_);
109  }
110 
111 
112  std::string PropertyDefinitionXmlFormatter::formatCaseSensitivity(std::string caseSensitivity)
113  {
114  return formatAttribute("CaseSensitivity", caseSensitivity);
115  }
116 
117 
118  std::string PropertyDefinitionXmlFormatter::formatRequirement(std::string requirement)
119  {
120  return formatAttribute("Required", requirement);
121  }
122 
123 
124  std::string PropertyDefinitionXmlFormatter::formatRegex(std::string regex)
125  {
126  return formatAttribute("Format", regex);
127  }
128 
129 
130  std::string PropertyDefinitionXmlFormatter::formatValues(std::vector<std::string> mapValues)
131  {
132  std::string valueStrings;
133 
134  if (mapValues.size() > 0)
135  {
136  valueStrings += " <values>\n";
137 
138  std::vector<std::string>::iterator it = mapValues.begin();
139 
140  while (it != mapValues.end())
141  {
142  if (!it->empty())
143  {
144  valueStrings += formatValue(*it);
145  }
146 
147  ++it;
148  }
149 
150  valueStrings += " </values>\n";
151  }
152 
153  return valueStrings;
154  }
155 
156 
158  {
159  if (value.empty())
160  {
161  return "";
162  }
163 
164  return " <value>" + value + "</value>\n";
165  }
166 
167 
168  std::string PropertyDefinitionXmlFormatter::formatAttribute(std::string name, std::string details)
169  {
170  if (!details.empty())
171  {
172  return " <attribute name=\"" + getPrefix() + name + "\">" + details + "</attribute>\n";
173  }
174 
175  return std::string();
176  }
177 
178 
179  std::string PropertyDefinitionXmlFormatter::formatHeader(std::string headerText)
180  {
181  return "<!-- " + headerText + " -->\n\n";
182  }
183 }
armarx::PropertyDefinitionXmlFormatter::formatName
std::string formatName(std::string name) override
Definition: PropertyDefinitionXmlFormatter.cpp:83
PropertyDefinitionXmlFormatter.h
armarx::PropertyDefinitionXmlFormatter::formatValue
std::string formatValue(std::string value) override
Definition: PropertyDefinitionXmlFormatter.cpp:157
armarx::PropertyDefinitionXmlFormatter::formatDefault
std::string formatDefault(std::string default_) override
Definition: PropertyDefinitionXmlFormatter.cpp:106
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::PropertyDefinitionXmlFormatter::formatValues
std::string formatValues(std::vector< std::string > values) override
Definition: PropertyDefinitionXmlFormatter.cpp:130
armarx::Encode
std::string Encode(const std::string &data)
Definition: StringHelpers.cpp:65
armarx::PropertyDefinitionXmlFormatter::formatHeader
std::string formatHeader(std::string headerText) override
Definition: PropertyDefinitionXmlFormatter.cpp:179
armarx::PropertyDefinitionXmlFormatter::formatAttribute
std::string formatAttribute(std::string name, std::string details) override
Definition: PropertyDefinitionXmlFormatter.cpp:168
StringHelpers.h
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::PropertyDefinitionXmlFormatter::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: PropertyDefinitionXmlFormatter.cpp:38
armarx::PropertyDefinitionFormatter::getPrefix
virtual std::string getPrefix() const
Definition: PropertyDefinitionFormatter.h:75
armarx::PropertyDefinitionXmlFormatter::formatRegex
std::string formatRegex(std::string regex) override
Definition: PropertyDefinitionXmlFormatter.cpp:124
armarx::PropertyDefinitionXmlFormatter::formatDescription
std::string formatDescription(std::string description) override
Definition: PropertyDefinitionXmlFormatter.cpp:89
armarx::PropertyDefinitionXmlFormatter::formatRequirement
std::string formatRequirement(std::string requirement) override
Definition: PropertyDefinitionXmlFormatter.cpp:118
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::PropertyDefinitionXmlFormatter::getFormat
std::string getFormat() override
Definition: PropertyDefinitionXmlFormatter.cpp:66
armarx::PropertyDefinitionXmlFormatter::formatCaseSensitivity
std::string formatCaseSensitivity(std::string caseSensitivity) override
Definition: PropertyDefinitionXmlFormatter.cpp:112
armarx::PropertyDefinitionXmlFormatter::formatBounds
std::string formatBounds(std::string min, std::string max) override
Definition: PropertyDefinitionXmlFormatter.cpp:95
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28