VariantInfo.h
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
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <memory>
27#include <optional>
28#include <set>
29#include <string>
30#include <vector>
31
32#include <Ice/BuiltinSequences.h>
33
35
36namespace armarx
37{
38 class VariantInfo;
39 using VariantInfoPtr = std::shared_ptr<VariantInfo>;
40
41 class DynamicLibrary;
42 using DynamicLibraryPtr = std::shared_ptr<DynamicLibrary>;
43
45 {
46 public:
47 class VariantEntry;
48 using VariantEntryPtr = std::shared_ptr<VariantEntry>;
49
51 {
52 friend class VariantInfo;
53
54 public:
56 const std::string& getHumanName() const;
57 const std::string& getBaseTypeName() const;
58 const std::string& getDataTypeName() const;
59 const std::optional<std::string>& getIncludePath() const;
60
61 private:
62 std::string baseTypeName;
63 std::string dataTypeName;
64 std::string humanName;
65 std::optional<std::string> includePath;
66 bool basic;
67 };
68
74
75 class ProxyEntry;
76 using ProxyEntryPtr = std::shared_ptr<ProxyEntry>;
77
79 {
80 friend class VariantInfo;
81
82 private:
83 std::string includePath;
84 std::string humanName;
85 std::string typeName;
86 std::string memberName;
87 std::string getterName;
88 std::string propertyName;
89 bool propertyIsOptional;
90 std::string propertyDefaultValue;
91 ProxyType proxyType;
92
93 std::vector<std::string> includes;
94 std::vector<std::string> libraries;
95 std::vector<std::pair<std::string, std::string>> methods;
96 std::vector<std::string> members;
97 std::vector<std::string> onInit;
98 std::vector<std::string> onConnect;
99 std::vector<std::pair<std::string, std::string>> stateMethods;
100
101 void
102 readVector(RapidXmlReaderNode node, const char* name, std::vector<std::string>& vec);
103
104 public:
106
107 std::string
109 {
110 return includePath;
111 }
112
113 std::string
115 {
116 return humanName;
117 }
118
119 std::string
121 {
122 return typeName;
123 }
124
125 std::string
127 {
128 return memberName;
129 }
130
131 std::string
133 {
134 return getterName;
135 }
136
137 std::string
139 {
140 return propertyName;
141 }
142
143 bool
145 {
146 return propertyIsOptional;
147 }
148
149 std::string
151 {
152 return propertyDefaultValue;
153 }
154
157 {
158 return proxyType;
159 }
160
161 std::string
163 {
164 return proxyType == Topic ? "Topic" : "Proxy";
165 }
166
167 std::vector<std::string>
169 {
170 return includes;
171 }
172
173 std::vector<std::string>
175 {
176 return libraries;
177 }
178
179 std::vector<std::pair<std::string, std::string>>
181 {
182 return methods;
183 }
184
185 std::vector<std::string>
187 {
188 return members;
189 }
190
191 std::vector<std::string>
193 {
194 return onInit;
195 }
196
197 std::vector<std::string>
199 {
200 return onConnect;
201 }
202
203 std::vector<std::pair<std::string, std::string>>
205 {
206 return stateMethods;
207 }
208 };
209
210 class LibEntry;
211 using LibEntryPtr = std::shared_ptr<LibEntry>;
212
214 {
215 friend class VariantInfo;
216
217 public:
218 LibEntry(RapidXmlReaderNode node, const std::string& packageName);
219 std::vector<std::string> getFactoryIncludes() const;
220 std::string getName() const;
221 std::vector<ProxyEntryPtr> getProxies() const;
222 const std::vector<VariantEntryPtr>& getVariants() const;
223 std::string getPackageName() const;
224 std::string getAbsoluteLibPath() const;
225 /**
226 * @brief Returns a list of includes for a specific variant (usually only one).
227 * If not set in the variantinfo xml for that particular variant, it will return the factory include.
228 * @param variantBaseTypeName
229 */
230 std::vector<std::string>
231 getVariantIncludes(const std::string& variantBaseTypeName) const;
232
233 private:
234 std::vector<std::string> factoryIncludes;
235 std::vector<VariantEntryPtr> variants;
236 std::vector<ProxyEntryPtr> proxies;
237 std::string name;
238 std::string packageName;
239 };
240
241 public:
242 VariantInfo();
243 std::vector<LibEntryPtr> readVariantInfo(RapidXmlReaderPtr reader,
244 const std::string& packagePath,
245 const std::string& packageName);
246 LibEntryPtr findLibByVariant(std::string variantTypeName) const;
247 LibEntryPtr findLibByProxy(std::string proxyTypeName) const;
248 std::set<LibEntryPtr> findLibs(const Ice::StringSeq& variantTypeNames,
249 const Ice::StringSeq& proxyTypeNames = {}) const;
250 Ice::StringSeq findLibNames(const Ice::StringSeq& variantTypeNames,
251 const Ice::StringSeq& proxyTypeNames = {}) const;
252 std::string getDataTypeName(std::string variantBaseTypeName);
253 std::string getReturnTypeName(std::string variantBaseTypeName);
254 bool isBasic(std::string variantBaseTypeName);
255 std::vector<LibEntryPtr> getLibs() const;
256 ProxyEntryPtr getProxyEntry(std::string proxyId);
257 VariantEntryPtr getVariantByName(std::string variantBaseTypeName);
258 VariantEntryPtr getVariantByHumanName(std::string humanName);
259 std::string getNestedHumanNameFromBaseName(std::string variantBaseTypeName);
260 std::string getNestedBaseNameFromHumanName(std::string humanName);
261 const std::map<std::string, std::string>& getPackagePaths() const;
262 bool isPackageLoaded(const std::string packageName) const;
263 std::string getDebugInfo() const;
264
265 static VariantInfoPtr ReadInfoFilesRecursive(const std::string& rootPackageName,
266 const std::string& rootPackagePath,
267 bool showErrors,
268 VariantInfoPtr variantInfo = VariantInfoPtr());
269 static VariantInfoPtr ReadInfoFiles(const std::vector<std::string>& packages,
270 bool showErrors = true,
271 bool throwOnError = true);
272
273 armarx::DynamicLibraryPtr loadLibraryOfVariant(std::string variantTypeName) const;
274
275 private:
276 std::vector<LibEntryPtr> libs;
277 std::map<std::string, LibEntryPtr> variantToLibMap;
278 std::map<std::string, VariantEntryPtr> variantMap;
279 std::map<std::string, VariantEntryPtr> humanNameToVariantMap;
280 std::map<std::string, ProxyEntryPtr> proxyMap;
281 std::map<std::string, std::string> packagePaths;
282 };
283} // namespace armarx
The DynamicLibrary class provides a mechanism to load libraries at runtime.
std::vector< std::string > getVariantIncludes(const std::string &variantBaseTypeName) const
Returns a list of includes for a specific variant (usually only one).
std::vector< ProxyEntryPtr > getProxies() const
LibEntry(RapidXmlReaderNode node, const std::string &packageName)
std::string getAbsoluteLibPath() const
std::string getPackageName() const
std::string getName() const
std::vector< std::string > getFactoryIncludes() const
const std::vector< VariantEntryPtr > & getVariants() const
std::vector< std::string > getIncludes()
std::vector< std::string > getLibraries()
std::vector< std::pair< std::string, std::string > > getStateMethods()
std::vector< std::string > getMembers()
std::vector< std::string > getOnConnect()
ProxyEntry(RapidXmlReaderNode node)
std::vector< std::string > getOnInit()
std::vector< std::pair< std::string, std::string > > getMethods()
const std::string & getBaseTypeName() const
const std::string & getDataTypeName() const
const std::string & getHumanName() const
const std::optional< std::string > & getIncludePath() const
VariantEntry(RapidXmlReaderNode node)
std::vector< LibEntryPtr > readVariantInfo(RapidXmlReaderPtr reader, const std::string &packagePath, const std::string &packageName)
static VariantInfoPtr ReadInfoFilesRecursive(const std::string &rootPackageName, const std::string &rootPackagePath, bool showErrors, VariantInfoPtr variantInfo=VariantInfoPtr())
const std::map< std::string, std::string > & getPackagePaths() const
armarx::DynamicLibraryPtr loadLibraryOfVariant(std::string variantTypeName) const
bool isPackageLoaded(const std::string packageName) const
VariantEntryPtr getVariantByName(std::string variantBaseTypeName)
LibEntryPtr findLibByVariant(std::string variantTypeName) const
ProxyEntryPtr getProxyEntry(std::string proxyId)
VariantEntryPtr getVariantByHumanName(std::string humanName)
static VariantInfoPtr ReadInfoFiles(const std::vector< std::string > &packages, bool showErrors=true, bool throwOnError=true)
Ice::StringSeq findLibNames(const Ice::StringSeq &variantTypeNames, const Ice::StringSeq &proxyTypeNames={}) const
std::vector< LibEntryPtr > getLibs() const
std::string getReturnTypeName(std::string variantBaseTypeName)
std::shared_ptr< LibEntry > LibEntryPtr
std::shared_ptr< VariantEntry > VariantEntryPtr
Definition VariantInfo.h:48
std::string getDataTypeName(std::string variantBaseTypeName)
std::string getDebugInfo() const
LibEntryPtr findLibByProxy(std::string proxyTypeName) const
std::string getNestedHumanNameFromBaseName(std::string variantBaseTypeName)
bool isBasic(std::string variantBaseTypeName)
std::set< LibEntryPtr > findLibs(const Ice::StringSeq &variantTypeNames, const Ice::StringSeq &proxyTypeNames={}) const
std::string getNestedBaseNameFromHumanName(std::string humanName)
std::shared_ptr< ProxyEntry > ProxyEntryPtr
Definition VariantInfo.h:76
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition VariantInfo.h:39
std::shared_ptr< DynamicLibrary > DynamicLibraryPtr