| 
									
										
										
										
											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 Argument.h | 
					
						
							|  |  |  |  * @brief arguments to constructors and methods | 
					
						
							|  |  |  |  * @author Frank Dellaert | 
					
						
							| 
									
										
										
										
											2012-06-27 02:52:27 +08:00
										 |  |  |  * @author Andrew Melim | 
					
						
							| 
									
										
										
										
											2012-07-13 06:28:28 +08:00
										 |  |  |  * @author Richard Roberts | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  |  **/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  | #include "TemplateSubstitution.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-26 01:29:06 +08:00
										 |  |  | #include "FileWriter.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-26 02:35:07 +08:00
										 |  |  | #include "ReturnValue.h"
 | 
					
						
							| 
									
										
										
										
											2014-05-26 01:29:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  | /// Argument class
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | struct Argument { | 
					
						
							| 
									
										
										
										
											2014-11-12 09:49:23 +08:00
										 |  |  |   Qualified type; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   bool is_const, is_ref, is_ptr; | 
					
						
							|  |  |  |   std::string name; | 
					
						
							| 
									
										
										
										
											2012-01-10 13:06:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   Argument() : | 
					
						
							|  |  |  |       is_const(false), is_ref(false), is_ptr(false) { | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   Argument expandTemplate(const TemplateSubstitution& ts) const; | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /// return MATLAB class for use in isa(x,class)
 | 
					
						
							|  |  |  |   std::string matlabClass(const std::string& delim = "") const; | 
					
						
							| 
									
										
										
										
											2012-01-10 13:06:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 03:21:13 +08:00
										 |  |  |   /// Check if will be unwrapped using scalar login in wrap/matlab.h
 | 
					
						
							|  |  |  |   bool isScalar() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /// MATLAB code generation, MATLAB to C++
 | 
					
						
							|  |  |  |   void matlab_unwrap(FileWriter& file, const std::string& matlabName) const; | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   friend std::ostream& operator<<(std::ostream& os, const Argument& arg) { | 
					
						
							|  |  |  |     os << (arg.is_const ? "const " : "") << arg.type << (arg.is_ptr ? "*" : "") | 
					
						
							|  |  |  |         << (arg.is_ref ? "&" : ""); | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-10 13:06:46 +08:00
										 |  |  | /// Argument list is just a container with Arguments
 | 
					
						
							| 
									
										
										
										
											2011-12-09 04:51:15 +08:00
										 |  |  | struct ArgumentList: public std::vector<Argument> { | 
					
						
							| 
									
										
										
										
											2012-01-10 13:06:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /// create a comma-separated string listing all argument types (not used)
 | 
					
						
							|  |  |  |   std::string types() const; | 
					
						
							| 
									
										
										
										
											2012-01-10 13:06:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /// create a short "signature" string
 | 
					
						
							|  |  |  |   std::string signature() const; | 
					
						
							| 
									
										
										
										
											2012-01-10 13:06:46 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /// create a comma-separated string listing all argument names, used in m-files
 | 
					
						
							|  |  |  |   std::string names() const; | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 03:21:13 +08:00
										 |  |  |   /// Check if all arguments scalar
 | 
					
						
							|  |  |  |   bool allScalar() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   ArgumentList expandTemplate(const TemplateSubstitution& ts) const; | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   // MATLAB code generation:
 | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * emit code to unwrap arguments | 
					
						
							|  |  |  |    * @param file output stream | 
					
						
							|  |  |  |    * @param start initial index for input array, set to 1 for method | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void matlab_unwrap(FileWriter& file, int start = 0) const; // MATLAB to C++
 | 
					
						
							| 
									
										
										
										
											2012-06-27 02:52:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 01:01:36 +08:00
										 |  |  |   /**
 | 
					
						
							|  |  |  |    * emit MATLAB prototype | 
					
						
							|  |  |  |    * @param file output stream | 
					
						
							|  |  |  |    * @param name of method or function | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  |   void emit_prototype(FileWriter& file, const std::string& name) const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-26 02:35:07 +08:00
										 |  |  |   /**
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |    * emit emit MATLAB call to proxy | 
					
						
							|  |  |  |    * @param proxyFile output stream | 
					
						
							| 
									
										
										
										
											2014-05-26 02:35:07 +08:00
										 |  |  |    * @param returnVal the return value | 
					
						
							|  |  |  |    * @param wrapperName of method or function | 
					
						
							| 
									
										
										
										
											2014-05-26 02:59:20 +08:00
										 |  |  |    * @param staticMethod flag to emit "this" in call | 
					
						
							|  |  |  |    */ | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |   void emit_call(FileWriter& proxyFile, const ReturnValue& returnVal, | 
					
						
							| 
									
										
										
										
											2014-05-26 02:59:20 +08:00
										 |  |  |       const std::string& wrapperName, int id, bool staticMethod = false) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							| 
									
										
										
										
											2014-11-13 03:51:47 +08:00
										 |  |  |    * emit conditional MATLAB call to proxy (checking arguments first) | 
					
						
							|  |  |  |    * @param proxyFile output stream | 
					
						
							| 
									
										
										
										
											2014-05-26 02:59:20 +08:00
										 |  |  |    * @param returnVal the return value | 
					
						
							|  |  |  |    * @param wrapperName of method or function | 
					
						
							|  |  |  |    * @param staticMethod flag to emit "this" in call | 
					
						
							| 
									
										
										
										
											2014-05-26 02:35:07 +08:00
										 |  |  |    */ | 
					
						
							| 
									
										
										
										
											2014-11-13 19:52:41 +08:00
										 |  |  |   void emit_conditional_call(FileWriter& proxyFile, | 
					
						
							|  |  |  |       const ReturnValue& returnVal, const std::string& wrapperName, int id, | 
					
						
							|  |  |  |       bool staticMethod = false) const; | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   friend std::ostream& operator<<(std::ostream& os, | 
					
						
							|  |  |  |       const ArgumentList& argList) { | 
					
						
							|  |  |  |     os << "("; | 
					
						
							|  |  |  |     if (argList.size() > 0) | 
					
						
							|  |  |  |       os << argList.front(); | 
					
						
							|  |  |  |     if (argList.size() > 1) | 
					
						
							|  |  |  |       for (size_t i = 1; i < argList.size(); i++) | 
					
						
							|  |  |  |         os << ", " << argList[i]; | 
					
						
							|  |  |  |     os << ")"; | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | } // \namespace wrap
 | 
					
						
							|  |  |  | 
 |