PropertyDefinitionFormatter.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 <boost/algorithm/string.hpp>
29 
30 using namespace armarx;
31 
32 std::string PropertyDefinitionFormatter::formatDefinition(std::string name,
33  std::string description,
34  std::string min,
35  std::string max,
36  std::string default_,
37  std::string casesensitivity,
38  std::string requirement,
39  std::string regex,
40  std::vector<std::string> mapValues,
41  std::string value)
42 {
43  std::string output = getFormat();
44 
45  boost::replace_first(output, "%name%", formatName(name));
46  boost::replace_first(output, "%description%", formatDescription(description));
47  boost::replace_first(output, "%bounds%", formatBounds(min, max));
48  boost::replace_first(output, "%default%", formatDefault(getValue(name, default_)));
49  boost::replace_first(output, "%casesensitive%", formatCaseSennsitivity(casesensitivity));
50  boost::replace_first(output, "%required%", formatRequirement(requirement));
51  boost::replace_first(output, "%regex%", formatRegex(regex));
52  boost::replace_first(output, "%values%", formatValues(mapValues));
53 
54  return output;
55 }
56 
58 {
59  return std::string("%name%:")
60  + "\t%description%\n"
61  + "\tAttributes:\n"
62  + "%default%"
63  + "%bounds%"
64  + "%casesensitive%"
65  + "%required%"
66  + "%regex%"
67  + "%values%";
68 }
69 
70 std::string PropertyDefinitionFormatter::formatName(std::string name)
71 {
72  return name;
73 }
74 
75 std::string PropertyDefinitionFormatter::formatDescription(std::string description)
76 {
77  return description;
78 }
79 
80 std::string PropertyDefinitionFormatter::formatBounds(std::string min, std::string max)
81 {
82  std::string bounds;
83 
84  if (!min.empty() && max.empty())
85  {
86  bounds = formatEntry(min, "Min: ");
87  }
88  else if (min.empty() && !max.empty())
89  {
90  bounds = formatEntry(max, "Max: ");
91  }
92  else if (!min.empty() && !max.empty())
93  {
94  bounds = formatEntry("Bounds: [" + min + "; " + max + "]");
95  }
96 
97  return bounds;
98 }
99 
100 std::string PropertyDefinitionFormatter::formatDefault(std::string default_)
101 {
102  return formatEntry(default_, "Default: ");
103 }
104 
105 std::string PropertyDefinitionFormatter::formatCaseSennsitivity(std::string caseSensitivity)
106 {
107  return formatEntry(caseSensitivity, "Case sensitivity: ");
108 }
109 
110 std::string PropertyDefinitionFormatter::formatRequirement(std::string requirement)
111 {
112  return formatEntry(requirement, "Required: ");
113 }
114 
115 std::string PropertyDefinitionFormatter::formatRegex(std::string regex)
116 {
117  return formatEntry(regex, "Format: ");
118 }
119 
120 std::string PropertyDefinitionFormatter::formatValues(std::vector<std::string> mapValues)
121 {
122  std::string valueStrings;
123 
124  if (mapValues.size() > 0)
125  {
126  valueStrings += formatEntry("Possible values:");
127 
128  std::vector<std::string>::iterator it = mapValues.begin();
129 
130  while (it != mapValues.end())
131  {
132  if (!it->empty())
133  {
134  valueStrings += formatValue(*it);
135  }
136 
137  ++it;
138  }
139  }
140 
141  return valueStrings;
142 }
143 
145 {
146  return "\t\t - " + value + "\n";
147 }
148 
149 std::string PropertyDefinitionFormatter::formatEntry(std::string entry, std::string prefix, std::string suffix)
150 {
151  if (!entry.empty())
152  {
153  return "\t - " + prefix + entry + suffix + "\n";
154  }
155 
156  return std::string();
157 }
158 
159 
armarx::PropertyDefinitionFormatter::formatDefault
virtual std::string formatDefault(std::string default_)=0
Definition: PropertyDefinitionFormatter.cpp:100
armarx::PropertyDefinitionFormatter::formatRegex
virtual std::string formatRegex(std::string regex)=0
Definition: PropertyDefinitionFormatter.cpp:115
armarx::PropertyDefinitionFormatter::formatBounds
virtual std::string formatBounds(std::string min, std::string max)=0
Definition: PropertyDefinitionFormatter.cpp:80
armarx::PropertyDefinitionFormatter::getFormat
virtual std::string getFormat()=0
Definition: PropertyDefinitionFormatter.cpp:57
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
PropertyDefinitionFormatter.h
armarx::PropertyDefinitionFormatter::formatValue
virtual std::string formatValue(std::string value)=0
Definition: PropertyDefinitionFormatter.cpp:144
armarx::PropertyDefinitionFormatter::prefix
std::string prefix
Definition: PropertyDefinitionFormatter.h:81
armarx::PropertyDefinitionFormatter::formatName
virtual std::string formatName(std::string name)=0
Definition: PropertyDefinitionFormatter.cpp:70
armarx::PropertyDefinitionFormatter::formatDescription
virtual std::string formatDescription(std::string description)=0
Definition: PropertyDefinitionFormatter.cpp:75
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
armarx::PropertyDefinitionFormatter::formatValues
virtual std::string formatValues(std::vector< std::string > values)=0
Definition: PropertyDefinitionFormatter.cpp:120
armarx::PropertyDefinitionFormatter::formatRequirement
virtual std::string formatRequirement(std::string requirement)=0
Definition: PropertyDefinitionFormatter.cpp:110
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::PropertyDefinitionFormatter::formatDefinition
virtual 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)=0
Definition: PropertyDefinitionFormatter.cpp:32
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28