| 
									
										
										
										
											2011-10-14 02:41:56 +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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |  * -------------------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							| 
									
										
										
										
											2011-10-14 11:23:14 +08:00
										 |  |  |  * @file Method.ccp | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							| 
									
										
										
										
											2012-07-13 06:28:28 +08:00
										 |  |  |  * @author Richard Roberts | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 01:22:10 +08:00
										 |  |  | #include "Method.h"
 | 
					
						
							|  |  |  | #include "utilities.h"
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <boost/foreach.hpp>
 | 
					
						
							| 
									
										
										
										
											2012-07-05 22:04:36 +08:00
										 |  |  | #include <boost/lexical_cast.hpp>
 | 
					
						
							| 
									
										
										
										
											2014-05-26 01:22:10 +08:00
										 |  |  | #include <boost/algorithm/string.hpp>
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 01:22:10 +08:00
										 |  |  | #include <iostream>
 | 
					
						
							|  |  |  | #include <fstream>
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | using namespace wrap; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  | bool Method::addOverload(Str name, const ArgumentList& args, | 
					
						
							| 
									
										
										
										
											2014-12-01 16:48:56 +08:00
										 |  |  |     const ReturnValue& retVal, bool is_const, | 
					
						
							|  |  |  |     boost::optional<const Qualified> instName, bool verbose) { | 
					
						
							| 
									
										
										
										
											2014-11-29 22:31:29 +08:00
										 |  |  |   bool first = MethodBase::addOverload(name, args, retVal, instName, verbose); | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  |   if (first) | 
					
						
							|  |  |  |     is_const_ = is_const; | 
					
						
							|  |  |  |   else if (is_const && !is_const_) | 
					
						
							|  |  |  |     throw std::runtime_error( | 
					
						
							|  |  |  |         "Method::addOverload now designated as const whereas before it was not"); | 
					
						
							|  |  |  |   else if (!is_const && is_const_) | 
					
						
							|  |  |  |     throw std::runtime_error( | 
					
						
							|  |  |  |         "Method::addOverload now designated as non-const whereas before it was"); | 
					
						
							|  |  |  |   return first; | 
					
						
							| 
									
										
										
										
											2012-07-05 22:05:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-28 03:03:19 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | void Method::proxy_header(FileWriter& proxyFile) const { | 
					
						
							| 
									
										
										
										
											2014-11-14 23:43:53 +08:00
										 |  |  |   proxyFile.oss << "    function varargout = " << matlabName() | 
					
						
							|  |  |  |       << "(this, varargin)\n"; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  | string Method::wrapper_call(FileWriter& wrapperFile, Str cppClassName, | 
					
						
							| 
									
										
										
										
											2014-11-30 17:38:24 +08:00
										 |  |  |     Str matlabUniqueName, const ArgumentList& args) const { | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |   // check arguments
 | 
					
						
							|  |  |  |   // extra argument obj -> nargin-1 is passed !
 | 
					
						
							|  |  |  |   // example: checkArguments("equals",nargout,nargin-1,2);
 | 
					
						
							| 
									
										
										
										
											2014-11-30 02:34:46 +08:00
										 |  |  |   wrapperFile.oss << "  checkArguments(\"" << matlabName() | 
					
						
							|  |  |  |       << "\",nargout,nargin-1," << args.size() << ");\n"; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // get class pointer
 | 
					
						
							|  |  |  |   // example: shared_ptr<Test> = unwrap_shared_ptr< Test >(in[0], "Test");
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |   wrapperFile.oss << "  Shared obj = unwrap_shared_ptr<" << cppClassName | 
					
						
							| 
									
										
										
										
											2014-05-26 00:06:34 +08:00
										 |  |  |       << ">(in[0], \"ptr_" << matlabUniqueName << "\");" << endl; | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // unwrap arguments, see Argument.cpp, we start at 1 as first is obj
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |   args.matlab_unwrap(wrapperFile, 1); | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-10 04:19:37 +08:00
										 |  |  |   // call method and wrap result
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   // example: out[0]=wrap<bool>(obj->return_field(t));
 | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:41 +08:00
										 |  |  |   string expanded = "obj->" + name_; | 
					
						
							| 
									
										
										
										
											2014-11-30 17:38:24 +08:00
										 |  |  |   if (templateArgValue_) | 
					
						
							|  |  |  |     expanded += ("<" + templateArgValue_->qualifiedName("::") + ">"); | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   return expanded; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ |