| 
									
										
										
										
											2014-11-13 19:52:01 +08:00
										 |  |  | /* ----------------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-11 22:39:48 +08:00
										 |  |  |  * GTSAM Copyright 2010, Georgia Tech Research Corporation, | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:01 +08:00
										 |  |  |  * 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 Function.ccp | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							|  |  |  |  * @date Nov 13, 2014 | 
					
						
							|  |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Function.h"
 | 
					
						
							|  |  |  | #include "utilities.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <boost/lexical_cast.hpp>
 | 
					
						
							|  |  |  | #include <boost/algorithm/string.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							|  |  |  | using namespace wrap; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-30 17:38:24 +08:00
										 |  |  | bool Function::initializeOrCheck(const string& name, | 
					
						
							|  |  |  |     boost::optional<const Qualified> instName, bool verbose) { | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:01 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  |   if (name.empty()) | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  |     throw runtime_error("Function::initializeOrCheck called with empty name"); | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:01 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Check if this overload is give to the correct method
 | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  |   if (name_.empty()) { | 
					
						
							|  |  |  |     name_ = name; | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:01 +08:00
										 |  |  |     templateArgValue_ = instName; | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  |     verbose_ = verbose; | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  |   } else { | 
					
						
							| 
									
										
										
										
											2014-12-02 05:29:27 +08:00
										 |  |  |     if (name_ != name || verbose_ != verbose | 
					
						
							|  |  |  |         || ((bool) templateArgValue_ != (bool) instName) | 
					
						
							|  |  |  |         || ((bool) templateArgValue_ && (bool) instName | 
					
						
							|  |  |  |             && !(*templateArgValue_ == *instName))) | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  |       throw runtime_error( | 
					
						
							| 
									
										
										
										
											2014-11-30 17:38:24 +08:00
										 |  |  |           "Function::initializeOrCheck called with different arguments"); | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return false; | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:01 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  | void Function::emit_call(FileWriter& proxyFile, const ReturnValue& returnVal, | 
					
						
							| 
									
										
										
										
											2014-11-30 03:59:38 +08:00
										 |  |  |     const string& wrapperName, int id) const { | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  |   returnVal.emit_matlab(proxyFile); | 
					
						
							|  |  |  |   proxyFile.oss << wrapperName << "(" << id; | 
					
						
							| 
									
										
										
										
											2014-11-30 03:59:38 +08:00
										 |  |  |   if (!isStatic()) | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  |     proxyFile.oss << ", this"; | 
					
						
							|  |  |  |   proxyFile.oss << ", varargin{:});\n"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							|  |  |  | void Function::emit_conditional_call(FileWriter& proxyFile, | 
					
						
							|  |  |  |     const ReturnValue& returnVal, const ArgumentList& args, | 
					
						
							| 
									
										
										
										
											2014-11-30 03:59:38 +08:00
										 |  |  |     const string& wrapperName, int id) const { | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // Check all arguments
 | 
					
						
							| 
									
										
										
										
											2014-11-30 04:11:13 +08:00
										 |  |  |   args.proxy_check(proxyFile); | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // output call to C++ wrapper
 | 
					
						
							|  |  |  |   proxyFile.oss << "        "; | 
					
						
							| 
									
										
										
										
											2014-11-30 03:59:38 +08:00
										 |  |  |   emit_call(proxyFile, returnVal, wrapperName, id); | 
					
						
							| 
									
										
										
										
											2014-11-30 03:53:38 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ |