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 <SimoxUtility/algorithm/string/string_tools.h>
29 
30 #include <sstream>
31 #include <iomanip>
32 
33 namespace armarx
34 {
36  std::string description,
37  std::string min,
38  std::string max,
39  std::string default_,
40  std::string casesensitivity,
41  std::string requirement,
42  std::string regex,
43  std::vector<std::string> values, std::string value)
44  {
45  std::string output = getFormat();
46 
47  output = simox::alg::replace_first(output, "%name%", formatName(getPrefix() + name));
48  output = simox::alg::replace_first(output, "%description%", formatDescription(description));
49  output = simox::alg::replace_first(output, "%bounds%", formatBounds(min, max));
50  output = simox::alg::replace_first(output, "%default%", formatDefault(default_));
51  output = simox::alg::replace_first(output, "%casesensitive%", formatCaseSensitivity(casesensitivity));
52  output = simox::alg::replace_first(output, "%required%", formatRequirement(requirement));
53  output = simox::alg::replace_first(output, "%regex%", formatRegex(regex));
54  output = simox::alg::replace_first(output, "%values%", formatValues(values));
55 
56  return output + "\n";
57  }
58 
60  {
61  return std::string("%name%:")
62  + " %description%\n"
63  + " Attributes:\n"
64  + "%default%"
65  + "%bounds%"
66  + "%casesensitive%"
67  + "%required%"
68  + "%regex%"
69  + "%values%";
70  }
71 
72  std::string PropertyDefinitionHelpFormatter::formatName(std::string name)
73  {
74  return name;
75  }
76 
77  std::string PropertyDefinitionHelpFormatter::formatDescription(std::string description)
78  {
79  return description;
80  }
81 
82  std::string PropertyDefinitionHelpFormatter::formatBounds(std::string min, std::string max)
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 PropertyDefinitionHelpFormatter::formatDefault(std::string default_)
103  {
104  return formatAttribute("Default:", default_);
105  }
106 
107  std::string PropertyDefinitionHelpFormatter::formatCaseSensitivity(std::string caseSensitivity)
108  {
109  return formatAttribute("Case sensitivity:", caseSensitivity);
110  }
111 
112  std::string PropertyDefinitionHelpFormatter::formatRequirement(std::string requirement)
113  {
114  return formatAttribute("Required:", requirement);
115  }
116 
117  std::string PropertyDefinitionHelpFormatter::formatRegex(std::string regex)
118  {
119  return formatAttribute("Format:", regex);
120  }
121 
122  std::string PropertyDefinitionHelpFormatter::formatValues(std::vector<std::string> mapValues)
123  {
124  std::string valueStrings;
125 
126  if (mapValues.size() > 0)
127  {
128  valueStrings += " - Possible values: ";
129 
130  std::vector<std::string>::iterator it = mapValues.begin();
131 
132  while (it != mapValues.end())
133  {
134  if (!it->empty())
135  {
136  valueStrings += formatValue(*it);
137  }
138 
139  ++it;
140 
141  valueStrings += (it != mapValues.end() ? ", " : "\n");
142  }
143  }
144 
145  return valueStrings;
146  }
147 
149  {
150  return value;
151  }
152 
153  std::string PropertyDefinitionHelpFormatter::formatAttribute(std::string name, std::string details)
154  {
155  if (!details.empty())
156  {
157  std::stringstream strStream;
158  strStream << std::setfill(' ') << std::left << std::setw(20) << name;
159  strStream << details;
160 
161  return " - " + strStream.str() + "\n";
162  }
163 
164  return std::string();
165  }
166 
167  std::string PropertyDefinitionHelpFormatter::formatHeader(std::string headerText)
168  {
169  return "==================================================================\n"
170  + headerText + "\n"
171  + "==================================================================\n\n";
172  }
173 }
armarx::PropertyDefinitionHelpFormatter::formatDescription
std::string formatDescription(std::string description) override
Definition: PropertyDefinitionHelpFormatter.cpp:77
armarx::PropertyDefinitionHelpFormatter::formatValue
std::string formatValue(std::string value) override
Definition: PropertyDefinitionHelpFormatter.cpp:148
armarx::PropertyDefinitionHelpFormatter::formatName
std::string formatName(std::string name) override
Definition: PropertyDefinitionHelpFormatter.cpp:72
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::PropertyDefinitionHelpFormatter::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: PropertyDefinitionHelpFormatter.cpp:35
PropertyDefinitionHelpFormatter.h
armarx::PropertyDefinitionHelpFormatter::formatHeader
std::string formatHeader(std::string headerText) override
Definition: PropertyDefinitionHelpFormatter.cpp:167
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::PropertyDefinitionHelpFormatter::getFormat
std::string getFormat() override
Definition: PropertyDefinitionHelpFormatter.cpp:59
armarx::PropertyDefinitionHelpFormatter::formatRegex
std::string formatRegex(std::string regex) override
Definition: PropertyDefinitionHelpFormatter.cpp:117
armarx::PropertyDefinitionHelpFormatter::formatRequirement
std::string formatRequirement(std::string requirement) override
Definition: PropertyDefinitionHelpFormatter.cpp:112
armarx::PropertyDefinitionFormatter::getPrefix
virtual std::string getPrefix() const
Definition: PropertyDefinitionFormatter.h:75
armarx::PropertyDefinitionHelpFormatter::formatDefault
std::string formatDefault(std::string default_) override
Definition: PropertyDefinitionHelpFormatter.cpp:102
armarx::PropertyDefinitionHelpFormatter::formatValues
std::string formatValues(std::vector< std::string > values) override
Definition: PropertyDefinitionHelpFormatter.cpp:122
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::PropertyDefinitionHelpFormatter::formatCaseSensitivity
std::string formatCaseSensitivity(std::string caseSensitivity) override
Definition: PropertyDefinitionHelpFormatter.cpp:107
armarx::PropertyDefinitionHelpFormatter::formatBounds
std::string formatBounds(std::string min, std::string max) override
Definition: PropertyDefinitionHelpFormatter.cpp:82
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PropertyDefinitionHelpFormatter::formatAttribute
std::string formatAttribute(std::string name, std::string details) override
Definition: PropertyDefinitionHelpFormatter.cpp:153