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