| 
									
										
										
										
											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"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Class TemplateInstantiationTypedef::findAndExpand(const vector<Class>& classes) const { | 
					
						
							|  |  |  |     // Find matching class
 | 
					
						
							|  |  |  |     std::vector<Class>::const_iterator clsIt = classes.end(); | 
					
						
							|  |  |  |     for(std::vector<Class>::const_iterator it = classes.begin(); it != classes.end(); ++it) { | 
					
						
							|  |  |  |       if(it->name == className && it->namespaces == classNamespaces && it->templateArgs.size() == typeList.size()) { | 
					
						
							|  |  |  |         clsIt = it; | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(clsIt == classes.end()) | 
					
						
							|  |  |  |       throw DependencyMissing(wrap::qualifiedName("::", classNamespaces, className), | 
					
						
							|  |  |  |       "instantiation into typedef name " + wrap::qualifiedName("::", namespaces, name) + | 
					
						
							|  |  |  |       ".  Ensure that the typedef provides the correct number of template arguments."); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Instantiate it
 | 
					
						
							|  |  |  |     Class classInst = *clsIt; | 
					
						
							|  |  |  |     for(size_t i = 0; i < typeList.size(); ++i) | 
					
						
							|  |  |  |       classInst = classInst.expandTemplate(classInst.templateArgs[i], typeList[i], namespaces, name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Fix class properties
 | 
					
						
							|  |  |  |     classInst.name = name; | 
					
						
							|  |  |  |     classInst.templateArgs.clear(); | 
					
						
							|  |  |  |     classInst.typedefName = clsIt->qualifiedName("::") + "<"; | 
					
						
							|  |  |  |     if(typeList.size() > 0) | 
					
						
							|  |  |  |       classInst.typedefName += wrap::qualifiedName("::", typeList[0]); | 
					
						
							|  |  |  |     for(size_t i = 1; i < typeList.size(); ++i) | 
					
						
							|  |  |  |       classInst.typedefName += (", " + wrap::qualifiedName("::", typeList[i])); | 
					
						
							|  |  |  |     classInst.typedefName += ">"; | 
					
						
							|  |  |  |     classInst.namespaces = namespaces; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return classInst; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2012-07-14 05:54:48 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | } |