| 
									
										
										
										
											2012-07-14 05:54:48 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation,  | 
					
						
							|  |  |  |  * Atlanta, Georgia 30332-0415 | 
					
						
							|  |  |  |  * All Rights Reserved | 
					
						
							|  |  |  |  * Authors: Frank Dellaert, et al. (see THANKS for the full author list) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * See LICENSE for the license information | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * @file Class.cpp | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  * @author Andrew Melim | 
					
						
							|  |  |  |  * @author Richard Roberts | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "TemplateInstantiationTypedef.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "utilities.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include <boost/optional.hpp>
 | 
					
						
							| 
									
										
										
										
											2012-07-14 05:54:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  | Class TemplateInstantiationTypedef::findAndExpand( | 
					
						
							|  |  |  |     const vector<Class>& classes) const { | 
					
						
							|  |  |  |   // Find matching class
 | 
					
						
							|  |  |  |   boost::optional<Class const &> matchedClass; | 
					
						
							|  |  |  |   BOOST_FOREACH(const Class& cls, classes) { | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |     if (cls.name() == class_.name() && cls.namespaces() == class_.namespaces() | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  |         && cls.templateArgs.size() == typeList.size()) { | 
					
						
							|  |  |  |       matchedClass.reset(cls); | 
					
						
							|  |  |  |       break; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-07-14 05:54:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  |   if (!matchedClass) | 
					
						
							|  |  |  |     throw DependencyMissing(class_.qualifiedName("::"), | 
					
						
							|  |  |  |         "instantiation into typedef name " + qualifiedName("::") | 
					
						
							|  |  |  |             + ".  Ensure that the typedef provides the correct number of template arguments."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Instantiate it
 | 
					
						
							|  |  |  |   Class classInst = *matchedClass; | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   for (size_t i = 0; i < typeList.size(); ++i) { | 
					
						
							|  |  |  |     TemplateSubstitution ts(classInst.templateArgs[i], typeList[i], *this); | 
					
						
							|  |  |  |     classInst = classInst.expandTemplate(ts); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Fix class properties
 | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |   classInst.name_ = name(); | 
					
						
							|  |  |  |   classInst.namespaces_ = namespaces(); | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  |   classInst.templateArgs.clear(); | 
					
						
							|  |  |  |   classInst.typedefName = matchedClass->qualifiedName("::") + "<"; | 
					
						
							|  |  |  |   if (typeList.size() > 0) | 
					
						
							|  |  |  |     classInst.typedefName += typeList[0].qualifiedName("::"); | 
					
						
							|  |  |  |   for (size_t i = 1; i < typeList.size(); ++i) | 
					
						
							|  |  |  |     classInst.typedefName += (", " + typeList[i].qualifiedName("::")); | 
					
						
							|  |  |  |   classInst.typedefName += ">"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return classInst; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |