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 
27 
28 #include <Ice/BuiltinSequences.h>
29 
30 #include <optional>
31 #include <vector>
32 #include <string>
33 #include <memory>
34 #include <set>
35 
36 namespace 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  private:
61  std::string baseTypeName;
62  std::string dataTypeName;
63  std::string humanName;
64  std::optional<std::string> includePath;
65  bool basic;
66  };
67 
69 
70  class ProxyEntry;
71  using ProxyEntryPtr = std::shared_ptr<ProxyEntry>;
72 
73  class ProxyEntry
74  {
75  friend class VariantInfo;
76 
77  private:
78  std::string includePath;
79  std::string humanName;
80  std::string typeName;
81  std::string memberName;
82  std::string getterName;
83  std::string propertyName;
84  bool propertyIsOptional;
85  std::string propertyDefaultValue;
86  ProxyType proxyType;
87 
88  std::vector<std::string> includes;
89  std::vector<std::string> libraries;
90  std::vector<std::pair<std::string, std::string>> methods;
91  std::vector<std::string> members;
92  std::vector<std::string> onInit;
93  std::vector<std::string> onConnect;
94  std::vector<std::pair<std::string, std::string>> stateMethods;
95 
96  void readVector(RapidXmlReaderNode node, const char* name, std::vector<std::string>& vec);
97 
98  public:
100  std::string getIncludePath()
101  {
102  return includePath;
103  }
104  std::string getHumanName()
105  {
106  return humanName;
107  }
108  std::string getTypeName()
109  {
110  return typeName;
111  }
112  std::string getMemberName()
113  {
114  return memberName;
115  }
116  std::string getGetterName()
117  {
118  return getterName;
119  }
120  std::string getPropertyName()
121  {
122  return propertyName;
123  }
125  {
126  return propertyIsOptional;
127  }
129  {
130  return propertyDefaultValue;
131  }
133  {
134  return proxyType;
135  }
136  std::string getProxyTypeAsString()
137  {
138  return proxyType == Topic ? "Topic" : "Proxy";
139  }
140 
141  std::vector<std::string> getIncludes()
142  {
143  return includes;
144  }
145  std::vector<std::string> getLibraries()
146  {
147  return libraries;
148  }
149  std::vector<std::pair<std::string, std::string>> getMethods()
150  {
151  return methods;
152  }
153  std::vector<std::string> getMembers()
154  {
155  return members;
156  }
157  std::vector<std::string> getOnInit()
158  {
159  return onInit;
160  }
161  std::vector<std::string> getOnConnect()
162  {
163  return onConnect;
164  }
165  std::vector<std::pair<std::string, std::string>> getStateMethods()
166  {
167  return stateMethods;
168  }
169  };
170 
171  class LibEntry;
172  using LibEntryPtr = std::shared_ptr<LibEntry>;
173 
174  class LibEntry
175  {
176  friend class VariantInfo;
177 
178  public:
179  LibEntry(RapidXmlReaderNode node, const std::string& packageName);
180  std::vector<std::string> getFactoryIncludes() const;
181  std::string getName() const;
182  std::vector<ProxyEntryPtr> getProxies() const ;
183  const std::vector<VariantEntryPtr>& getVariants() const;
184  std::string getPackageName() const;
185  std::string getAbsoluteLibPath() const;
186  /**
187  * @brief Returns a list of includes for a specific variant (usually only one).
188  * If not set in the variantinfo xml for that particular variant, it will return the factory include.
189  * @param variantBaseTypeName
190  */
191  std::vector<std::string> getVariantIncludes(const std::string& variantBaseTypeName) const;
192 
193  private:
194  std::vector<std::string> factoryIncludes;
195  std::vector<VariantEntryPtr> variants;
196  std::vector<ProxyEntryPtr> proxies;
197  std::string name;
198  std::string packageName;
199  };
200 
201  public:
202  VariantInfo();
203  std::vector<LibEntryPtr> readVariantInfo(RapidXmlReaderPtr reader, const std::string& packagePath, const std::string& packageName);
204  LibEntryPtr findLibByVariant(std::string variantTypeName) const;
205  LibEntryPtr findLibByProxy(std::string proxyTypeName) const;
206  std::set<LibEntryPtr> findLibs(const Ice::StringSeq& variantTypeNames, const Ice::StringSeq& proxyTypeNames = {}) const;
207  Ice::StringSeq findLibNames(const Ice::StringSeq& variantTypeNames, const Ice::StringSeq& proxyTypeNames = {}) const;
208  std::string getDataTypeName(std::string variantBaseTypeName);
209  std::string getReturnTypeName(std::string variantBaseTypeName);
210  bool isBasic(std::string variantBaseTypeName);
211  std::vector<LibEntryPtr> getLibs() const;
212  ProxyEntryPtr getProxyEntry(std::string proxyId);
213  VariantEntryPtr getVariantByName(std::string variantBaseTypeName);
214  VariantEntryPtr getVariantByHumanName(std::string humanName);
215  std::string getNestedHumanNameFromBaseName(std::string variantBaseTypeName);
216  std::string getNestedBaseNameFromHumanName(std::string humanName);
217  const std::map<std::string, std::string>& getPackagePaths() const;
218  bool isPackageLoaded(const std::string packageName) const;
219  std::string getDebugInfo() const;
220 
221  static VariantInfoPtr ReadInfoFilesRecursive(const std::string& rootPackageName, const std::string& rootPackagePath, bool showErrors, VariantInfoPtr variantInfo = VariantInfoPtr());
222  static VariantInfoPtr ReadInfoFiles(const std::vector<std::string>& packages, bool showErrors = true, bool throwOnError = true);
223 
224  armarx::DynamicLibraryPtr loadLibraryOfVariant(std::string variantTypeName) const;
225 
226  private:
227  std::vector<LibEntryPtr> libs;
228  std::map<std::string, LibEntryPtr> variantToLibMap;
229  std::map<std::string, VariantEntryPtr> variantMap;
230  std::map<std::string, VariantEntryPtr> humanNameToVariantMap;
231  std::map<std::string, ProxyEntryPtr> proxyMap;
232  std::map<std::string, std::string> packagePaths;
233  };
234 }
235 
armarx::RapidXmlReaderPtr
std::shared_ptr< RapidXmlReader > RapidXmlReaderPtr
Definition: RapidXmlReader.h:66
armarx::VariantInfo::ProxyEntry::getIncludePath
std::string getIncludePath()
Definition: VariantInfo.h:100
armarx::VariantInfo::ProxyEntry::getTypeName
std::string getTypeName()
Definition: VariantInfo.h:108
armarx::VariantInfo::ProxyEntry::getStateMethods
std::vector< std::pair< std::string, std::string > > getStateMethods()
Definition: VariantInfo.h:165
armarx::VariantInfo::findLibs
std::set< LibEntryPtr > findLibs(const Ice::StringSeq &variantTypeNames, const Ice::StringSeq &proxyTypeNames={}) const
Definition: VariantInfo.cpp:123
armarx::VariantInfo::ProxyEntry::getOnInit
std::vector< std::string > getOnInit()
Definition: VariantInfo.h:157
armarx::VariantInfo::getDataTypeName
std::string getDataTypeName(std::string variantBaseTypeName)
Definition: VariantInfo.cpp:145
armarx::DynamicLibraryPtr
std::shared_ptr< DynamicLibrary > DynamicLibraryPtr
Definition: DynamicLibrary.h:123
armarx::VariantInfo::loadLibraryOfVariant
armarx::DynamicLibraryPtr loadLibraryOfVariant(std::string variantTypeName) const
Definition: VariantInfo.cpp:467
armarx::VariantInfo::ProxyType
ProxyType
Definition: VariantInfo.h:68
armarx::VariantInfo::getNestedBaseNameFromHumanName
std::string getNestedBaseNameFromHumanName(std::string humanName)
Definition: VariantInfo.cpp:273
armarx::VariantInfo::ProxyEntry::getGetterName
std::string getGetterName()
Definition: VariantInfo.h:116
armarx::VariantInfo::ProxyEntry
Definition: VariantInfo.h:73
armarx::VariantInfo::ProxyEntry::getPropertyName
std::string getPropertyName()
Definition: VariantInfo.h:120
armarx::VariantInfo::getReturnTypeName
std::string getReturnTypeName(std::string variantBaseTypeName)
Definition: VariantInfo.cpp:159
armarx::VariantInfo::ProxyEntry::getPropertyDefaultValue
std::string getPropertyDefaultValue()
Definition: VariantInfo.h:128
armarx::VariantInfo::LibEntry::LibEntry
LibEntry(RapidXmlReaderNode node, const std::string &packageName)
Definition: VariantInfo.cpp:491
armarx::VariantInfo::LibEntry::getProxies
std::vector< ProxyEntryPtr > getProxies() const
Definition: VariantInfo.cpp:568
armarx::VariantInfo::LibEntry::getName
std::string getName() const
Definition: VariantInfo.cpp:563
armarx::VariantInfo::isBasic
bool isBasic(std::string variantBaseTypeName)
Definition: VariantInfo.cpp:176
armarx::VariantInfo::VariantEntryPtr
std::shared_ptr< VariantEntry > VariantEntryPtr
Definition: VariantInfo.h:48
armarx::VariantInfo::findLibNames
Ice::StringSeq findLibNames(const Ice::StringSeq &variantTypeNames, const Ice::StringSeq &proxyTypeNames={}) const
Definition: VariantInfo.cpp:110
armarx::VariantInfo::LibEntry::getAbsoluteLibPath
std::string getAbsoluteLibPath() const
Definition: VariantInfo.cpp:543
armarx::VariantInfo::SingleProxy
@ SingleProxy
Definition: VariantInfo.h:68
armarx::VariantInfo::VariantEntry::getBaseTypeName
const std::string & getBaseTypeName() const
Definition: VariantInfo.cpp:595
armarx::VariantInfo::ProxyEntry::getHumanName
std::string getHumanName()
Definition: VariantInfo.h:104
armarx::VariantInfo::getDebugInfo
std::string getDebugInfo() const
Definition: VariantInfo.cpp:325
armarx::VariantInfo::isPackageLoaded
bool isPackageLoaded(const std::string packageName) const
Definition: VariantInfo.cpp:313
armarx::VariantInfo::VariantInfo
VariantInfo()
Definition: VariantInfo.cpp:43
armarx::VariantInfo::ReadInfoFilesRecursive
static VariantInfoPtr ReadInfoFilesRecursive(const std::string &rootPackageName, const std::string &rootPackagePath, bool showErrors, VariantInfoPtr variantInfo=VariantInfoPtr())
Definition: VariantInfo.cpp:347
armarx::VariantInfo::ProxyEntry::getMembers
std::vector< std::string > getMembers()
Definition: VariantInfo.h:153
armarx::VariantInfo::ProxyEntry::getProxyTypeAsString
std::string getProxyTypeAsString()
Definition: VariantInfo.h:136
armarx::VariantInfo::VariantEntry::getIncludePath
const std::optional< std::string > & getIncludePath() const
Definition: VariantInfo.cpp:605
armarx::VariantInfo::ProxyEntry::getProxyType
ProxyType getProxyType()
Definition: VariantInfo.h:132
armarx::VariantInfo::ProxyEntryPtr
std::shared_ptr< ProxyEntry > ProxyEntryPtr
Definition: VariantInfo.h:71
armarx::VariantInfo::LibEntry::getPackageName
std::string getPackageName() const
Definition: VariantInfo.cpp:538
armarx::VariantInfo::Topic
@ Topic
Definition: VariantInfo.h:68
armarx::VariantInfo::VariantEntry::getHumanName
const std::string & getHumanName() const
Definition: VariantInfo.cpp:590
armarx::RapidXmlReaderNode
Definition: RapidXmlReader.h:68
armarx::VariantInfo::getPackagePaths
const std::map< std::string, std::string > & getPackagePaths() const
Definition: VariantInfo.cpp:308
armarx::VariantInfo::LibEntry::getVariants
const std::vector< VariantEntryPtr > & getVariants() const
Definition: VariantInfo.cpp:573
armarx::VariantInfo::ReadInfoFiles
static VariantInfoPtr ReadInfoFiles(const std::vector< std::string > &packages, bool showErrors=true, bool throwOnError=true)
Definition: VariantInfo.cpp:414
armarx::VariantInfo::LibEntry
Definition: VariantInfo.h:174
armarx::VariantInfo::getProxyEntry
ProxyEntryPtr getProxyEntry(std::string proxyId)
Definition: VariantInfo.cpp:196
armarx::VariantInfo::ProxyEntry::getLibraries
std::vector< std::string > getLibraries()
Definition: VariantInfo.h:145
armarx::VariantInfo::getVariantByHumanName
VariantEntryPtr getVariantByHumanName(std::string humanName)
Definition: VariantInfo.cpp:224
armarx::VariantInfo::ProxyEntry::ProxyEntry
ProxyEntry(RapidXmlReaderNode node)
Definition: VariantInfo.cpp:619
armarx::VariantInfoPtr
std::shared_ptr< VariantInfo > VariantInfoPtr
Definition: VariantInfo.h:39
RapidXmlReader.h
armarx::VariantInfo::ProxyEntry::getIncludes
std::vector< std::string > getIncludes()
Definition: VariantInfo.h:141
armarx::VariantInfo::LibEntry::getVariantIncludes
std::vector< std::string > getVariantIncludes(const std::string &variantBaseTypeName) const
Returns a list of includes for a specific variant (usually only one).
Definition: VariantInfo.cpp:522
armarx::VariantInfo
Definition: VariantInfo.h:44
armarx::VariantInfo::readVariantInfo
std::vector< LibEntryPtr > readVariantInfo(RapidXmlReaderPtr reader, const std::string &packagePath, const std::string &packageName)
Definition: VariantInfo.cpp:47
armarx::VariantInfo::LibEntry::getFactoryIncludes
std::vector< std::string > getFactoryIncludes() const
Definition: VariantInfo.cpp:517
armarx::DynamicLibrary
The DynamicLibrary class provides a mechanism to load libraries at runtime.
Definition: DynamicLibrary.h:49
armarx::VariantInfo::VariantEntry::VariantEntry
VariantEntry(RapidXmlReaderNode node)
Definition: VariantInfo.cpp:578
armarx::VariantInfo::ProxyEntry::getPropertyIsOptional
bool getPropertyIsOptional()
Definition: VariantInfo.h:124
armarx::VariantInfo::getLibs
std::vector< LibEntryPtr > getLibs() const
Definition: VariantInfo.cpp:191
armarx::VariantInfo::findLibByVariant
LibEntryPtr findLibByVariant(std::string variantTypeName) const
Definition: VariantInfo.cpp:79
armarx::VariantInfo::LibEntryPtr
std::shared_ptr< LibEntry > LibEntryPtr
Definition: VariantInfo.h:172
armarx::VariantInfo::VariantEntry
Definition: VariantInfo.h:50
armarx::VariantInfo::getNestedHumanNameFromBaseName
std::string getNestedHumanNameFromBaseName(std::string variantBaseTypeName)
Definition: VariantInfo.cpp:238
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::VariantInfo::ProxyEntry::getMethods
std::vector< std::pair< std::string, std::string > > getMethods()
Definition: VariantInfo.h:149
armarx::VariantInfo::getVariantByName
VariantEntryPtr getVariantByName(std::string variantBaseTypeName)
Definition: VariantInfo.cpp:210
armarx::VariantInfo::VariantEntry::getDataTypeName
const std::string & getDataTypeName() const
Definition: VariantInfo.cpp:600
armarx::VariantInfo::ProxyEntry::getMemberName
std::string getMemberName()
Definition: VariantInfo.h:112
armarx::VariantInfo::ProxyEntry::getOnConnect
std::vector< std::string > getOnConnect()
Definition: VariantInfo.h:161
armarx::VariantInfo::findLibByProxy
LibEntryPtr findLibByProxy(std::string proxyTypeName) const
Definition: VariantInfo.cpp:93