| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * @file ReturnValue.cpp | 
					
						
							|  |  |  |  * @date Dec 1, 2011 | 
					
						
							|  |  |  |  * @author Alex Cunningham | 
					
						
							| 
									
										
										
										
											2012-06-27 02:52:27 +08:00
										 |  |  |  * @author Andrew Melim | 
					
						
							| 
									
										
										
										
											2012-07-13 06:28:28 +08:00
										 |  |  |  * @author Richard Roberts | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "ReturnValue.h"
 | 
					
						
							|  |  |  | #include "utilities.h"
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include <iostream>
 | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | using namespace std; | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | using namespace wrap; | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 07:39:15 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | ReturnValue ReturnValue::expandTemplate(const TemplateSubstitution& ts) const { | 
					
						
							| 
									
										
										
										
											2014-11-13 07:39:15 +08:00
										 |  |  |   ReturnValue instRetVal = *this; | 
					
						
							| 
									
										
										
										
											2014-11-30 07:13:29 +08:00
										 |  |  |   instRetVal.type1 = ts.tryToSubstitite(type1); | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  |   if (isPair) | 
					
						
							| 
									
										
										
										
											2014-11-30 07:13:29 +08:00
										 |  |  |     instRetVal.type2 = ts.tryToSubstitite(type2); | 
					
						
							| 
									
										
										
										
											2014-11-13 07:39:15 +08:00
										 |  |  |   return instRetVal; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-09 04:51:17 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  | string ReturnValue::return_type(bool add_ptr) const { | 
					
						
							| 
									
										
										
										
											2014-11-12 22:31:40 +08:00
										 |  |  |   if (isPair) | 
					
						
							|  |  |  |     return "pair< " + type1.str(add_ptr) + ", " + type2.str(add_ptr) + " >"; | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     return type1.str(add_ptr); | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-12 20:31:46 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  | string ReturnValue::matlab_returnType() const { | 
					
						
							|  |  |  |   return isPair ? "[first,second]" : "result"; | 
					
						
							| 
									
										
										
										
											2014-11-12 20:31:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  | void ReturnValue::wrap_result(const string& result, FileWriter& wrapperFile, | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  |     const TypeAttributesTable& typeAttributes) const { | 
					
						
							| 
									
										
										
										
											2011-12-07 11:05:37 +08:00
										 |  |  |   if (isPair) { | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |     // For a pair, store the returned pair so we do not evaluate the function twice
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |     wrapperFile.oss << "  " << return_type(true) << " pairResult = " << result | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  |         << ";\n"; | 
					
						
							| 
									
										
										
										
											2014-11-13 07:39:15 +08:00
										 |  |  |     type1.wrap_result("  out[0]", "pairResult.first", wrapperFile, | 
					
						
							|  |  |  |         typeAttributes); | 
					
						
							|  |  |  |     type2.wrap_result("  out[1]", "pairResult.second", wrapperFile, | 
					
						
							|  |  |  |         typeAttributes); | 
					
						
							| 
									
										
										
										
											2012-11-28 03:03:16 +08:00
										 |  |  |   } else { // Not a pair
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |     type1.wrap_result("  out[0]", result, wrapperFile, typeAttributes); | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  | void ReturnValue::wrapTypeUnwrap(FileWriter& wrapperFile) const { | 
					
						
							|  |  |  |   type1.wrapTypeUnwrap(wrapperFile); | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  |   if (isPair) | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |     type2.wrapTypeUnwrap(wrapperFile); | 
					
						
							| 
									
										
										
										
											2012-07-24 02:24:39 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-24 02:24:39 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  | void ReturnValue::emit_matlab(FileWriter& proxyFile) const { | 
					
						
							| 
									
										
										
										
											2014-05-26 02:52:49 +08:00
										 |  |  |   string output; | 
					
						
							|  |  |  |   if (isPair) | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |     proxyFile.oss << "[ varargout{1} varargout{2} ] = "; | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  |   else if (type1.category != ReturnType::VOID) | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |     proxyFile.oss << "varargout{1} = "; | 
					
						
							| 
									
										
										
										
											2014-05-26 02:52:49 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-12 21:37:08 +08:00
										 |  |  | /* ************************************************************************* */ | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | 
 |