| 
									
										
										
										
											2014-11-14 00:28:05 +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 TemplateSubstitution.h | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |  * @brief Auxiliary class for template substitutions | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  * @date Nov 13, 2014 | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  | #include "ReturnType.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * e.g. TemplateSubstitution("T", gtsam::Point2, gtsam::PriorFactorPoint2) | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  | class TemplateSubstitution { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::string templateArg_; | 
					
						
							|  |  |  |   Qualified qualifiedType_, expandedClass_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   TemplateSubstitution(const std::string& a, const Qualified& t, | 
					
						
							|  |  |  |       const Qualified& e) : | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |       templateArg_(a), qualifiedType_(t), expandedClass_(e) { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 04:53:33 +08:00
										 |  |  |   std::string expandedClassName() const { | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |     return expandedClass_.name(); | 
					
						
							| 
									
										
										
										
											2014-11-14 04:53:33 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |   // Substitute if needed
 | 
					
						
							| 
									
										
										
										
											2014-11-30 07:13:29 +08:00
										 |  |  |   Qualified tryToSubstitite(const Qualified& type) const { | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |     if (type.match(templateArg_)) | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |       return qualifiedType_; | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |     else if (type.match("This")) | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |       return expandedClass_; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       return type; | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Substitute if needed
 | 
					
						
							| 
									
										
										
										
											2014-11-30 07:13:29 +08:00
										 |  |  |   ReturnType tryToSubstitite(const ReturnType& type) const { | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  |     ReturnType instType = type; | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |     if (type.match(templateArg_)) | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |       instType.rename(qualifiedType_); | 
					
						
							| 
									
										
										
										
											2014-12-01 03:12:03 +08:00
										 |  |  |     else if (type.match("This")) | 
					
						
							| 
									
										
										
										
											2014-11-14 02:34:15 +08:00
										 |  |  |       instType.rename(expandedClass_); | 
					
						
							|  |  |  |     return instType; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   friend std::ostream& operator<<(std::ostream& os, | 
					
						
							|  |  |  |       const TemplateSubstitution& ts) { | 
					
						
							|  |  |  |     os << ts.templateArg_ << '/' << ts.qualifiedType_.qualifiedName("::") | 
					
						
							|  |  |  |         << " (" << ts.expandedClass_.qualifiedName("::") << ")"; | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } // \namespace wrap
 | 
					
						
							|  |  |  | 
 |