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 
35 namespace 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
armarx::PropertyDefinitionXmlFormatter::formatName
std::string formatName(std::string name) override
Definition: PropertyDefinitionXmlFormatter.cpp:74
PropertyDefinitionXmlFormatter.h
armarx::PropertyDefinitionXmlFormatter::formatValue
std::string formatValue(std::string value) override
Definition: PropertyDefinitionXmlFormatter.cpp:148
armarx::PropertyDefinitionXmlFormatter::formatDefault
std::string formatDefault(std::string default_) override
Definition: PropertyDefinitionXmlFormatter.cpp:97
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:297
ProsthesisInterface.values
values
Definition: ProsthesisInterface.py:190
armarx::PropertyDefinitionXmlFormatter::formatValues
std::string formatValues(std::vector< std::string > values) override
Definition: PropertyDefinitionXmlFormatter.cpp:121
armarx::Encode
std::string Encode(const std::string &data)
Definition: StringHelpers.cpp:68
armarx::PropertyDefinitionXmlFormatter::formatHeader
std::string formatHeader(std::string headerText) override
Definition: PropertyDefinitionXmlFormatter.cpp:171
armarx::PropertyDefinitionXmlFormatter::formatAttribute
std::string formatAttribute(std::string name, std::string details) override
Definition: PropertyDefinitionXmlFormatter.cpp:159
StringHelpers.h
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:855
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:78
armarx::PropertyDefinitionXmlFormatter::formatRegex
std::string formatRegex(std::string regex) override
Definition: PropertyDefinitionXmlFormatter.cpp:115
armarx::PropertyDefinitionXmlFormatter::formatDescription
std::string formatDescription(std::string description) override
Definition: PropertyDefinitionXmlFormatter.cpp:80
armarx::PropertyDefinitionXmlFormatter::formatRequirement
std::string formatRequirement(std::string requirement) override
Definition: PropertyDefinitionXmlFormatter.cpp:109
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:327
armarx::PropertyDefinitionXmlFormatter::getFormat
std::string getFormat() override
Definition: PropertyDefinitionXmlFormatter.cpp:66
armarx::PropertyDefinitionXmlFormatter::formatCaseSensitivity
std::string formatCaseSensitivity(std::string caseSensitivity) override
Definition: PropertyDefinitionXmlFormatter.cpp:103
armarx::PropertyDefinitionXmlFormatter::formatBounds
std::string formatBounds(std::string min, std::string max) override
Definition: PropertyDefinitionXmlFormatter.cpp:86
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27