PropertyDefinitionDoxygenFormatter.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 name,
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(output, "%casesensitive%", formatCaseSensitivity(casesensitivity));
54  output = simox::alg::replace_first(output, "%required%", formatRequirement(requirement));
55  output = simox::alg::replace_first(output, "%regex%", formatRegex(regex));
56  output = simox::alg::replace_first(output, "%values%", formatValues(values));
57 
58  return formatDocComment(output);
59  }
60 
62  {
63  return std::string("\\prop %name%: \n")
64  + "%description%<br />\n"
65  + "Attributes:\n"
66  + "%default%"
67  + "%bounds%"
68  + "%casesensitive%"
69  + "%required%"
70  + "%regex%"
71  + "%values%";
72  }
73 
74  std::string PropertyDefinitionDoxygenFormatter::formatName(std::string name)
75  {
76  return name;
77  }
78 
79  std::string PropertyDefinitionDoxygenFormatter::formatDescription(std::string description)
80  {
81  return description;
82  }
83 
84  std::string PropertyDefinitionDoxygenFormatter::formatBounds(std::string min, std::string max)
85  {
86  std::string bounds;
87 
88  if (!min.empty() && max.empty())
89  {
90  bounds = formatAttribute("Min:", min);
91  }
92  else if (min.empty() && !max.empty())
93  {
94  bounds = formatAttribute("Max:", max);
95  }
96  else if (!min.empty() && !max.empty())
97  {
98  bounds = formatAttribute("Bounds:", "[" + min + "; " + max + "]");
99  }
100 
101  return bounds;
102  }
103 
104  std::string PropertyDefinitionDoxygenFormatter::formatDefault(std::string default_)
105  {
106  return formatAttribute("Default:", default_);
107  }
108 
109  std::string PropertyDefinitionDoxygenFormatter::formatCaseSensitivity(std::string caseSensitivity)
110  {
111  return formatAttribute("Case sensitivity:", caseSensitivity);
112  }
113 
114  std::string PropertyDefinitionDoxygenFormatter::formatRequirement(std::string requirement)
115  {
116  return formatAttribute("Required:", requirement);
117  }
118 
119  std::string PropertyDefinitionDoxygenFormatter::formatRegex(std::string regex)
120  {
121  return formatAttribute("Format:", regex);
122  }
123 
124  std::string PropertyDefinitionDoxygenFormatter::formatValues(std::vector<std::string> mapValues)
125  {
126  std::string valueStrings;
127 
128  if (mapValues.size() > 0)
129  {
130  valueStrings += " - Possible values: {";
131 
132  std::vector<std::string>::iterator it = mapValues.begin();
133 
134  while (it != mapValues.end())
135  {
136  if (!it->empty())
137  {
138  valueStrings += formatValue(*it);
139  }
140 
141  ++it;
142 
143  if (it != mapValues.end())
144  {
145  valueStrings += ", ";
146  }
147  }
148 
149  valueStrings += "}";
150  }
151 
152  return valueStrings;
153  }
154 
155 
157  {
158  return value;
159  }
160 
161 
162  std::string PropertyDefinitionDoxygenFormatter::formatAttribute(std::string name, std::string details)
163  {
164  if (!details.empty())
165  {
166  std::stringstream strStream;
167  strStream << std::setfill(' ') << std::left << std::setw(20) << name;
168  strStream << details;
169 
170  return " - " + strStream.str() + "\n";
171  }
172 
173  return std::string();
174  }
175 
176 
177  std::string PropertyDefinitionDoxygenFormatter::formatHeader(std::string headerText)
178  {
179  return "\n";
180  }
181 
182 
184  const std::string& text)
185  {
186  std::string line;
187  std::string docComment = "\n";
188 
189  std::stringstream textStream(text);
190 
191  while (std::getline(textStream, line, '\n'))
192  {
193  docComment += "" + line + "\n";
194  }
195 
196  docComment += " \n";
197 
198  return docComment;
199  }
200 }
armarx::PropertyDefinitionDoxygenFormatter::formatValues
std::string formatValues(std::vector< std::string > values) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:124
armarx::PropertyDefinitionDoxygenFormatter::formatRegex
std::string formatRegex(std::string regex) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:119
armarx::PropertyDefinitionDoxygenFormatter::getFormat
std::string getFormat() override
Definition: PropertyDefinitionDoxygenFormatter.cpp:61
PropertyDefinitionDoxygenFormatter.h
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::PropertyDefinitionDoxygenFormatter::formatDescription
std::string formatDescription(std::string description) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:79
armarx::PropertyDefinitionDoxygenFormatter::formatDocComment
virtual std::string formatDocComment(const std::string &text)
Definition: PropertyDefinitionDoxygenFormatter.cpp:183
armarx::PropertyDefinitionDoxygenFormatter::formatHeader
std::string formatHeader(std::string headerText) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:177
armarx::PropertyDefinitionDoxygenFormatter::formatBounds
std::string formatBounds(std::string min, std::string max) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:84
armarx::PropertyDefinitionDoxygenFormatter::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: PropertyDefinitionDoxygenFormatter.cpp:35
armarx::PropertyDefinitionDoxygenFormatter::formatName
std::string formatName(std::string name) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:74
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::PropertyDefinitionDoxygenFormatter::formatDefault
std::string formatDefault(std::string default_) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:104
armarx::PropertyDefinitionFormatter::getPrefix
virtual std::string getPrefix() const
Definition: PropertyDefinitionFormatter.h:75
armarx::PropertyDefinitionDoxygenFormatter::formatAttribute
std::string formatAttribute(std::string name, std::string details) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:162
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::PropertyDefinitionDoxygenFormatter::formatValue
std::string formatValue(std::string value) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:156
armarx::PropertyDefinitionDoxygenFormatter::formatRequirement
std::string formatRequirement(std::string requirement) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:114
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PropertyDefinitionDoxygenFormatter::formatCaseSensitivity
std::string formatCaseSensitivity(std::string caseSensitivity) override
Definition: PropertyDefinitionDoxygenFormatter.cpp:109