| 
									
										
										
										
											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 Class.h | 
					
						
							|  |  |  |  * @brief describe the C++ class that is being wrapped | 
					
						
							|  |  |  |  * @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
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "Constructor.h"
 | 
					
						
							| 
									
										
										
										
											2012-03-30 13:34:23 +08:00
										 |  |  | #include "Deconstructor.h"
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | #include "Method.h"
 | 
					
						
							| 
									
										
										
										
											2011-12-02 10:32:18 +08:00
										 |  |  | #include "StaticMethod.h"
 | 
					
						
							| 
									
										
										
										
											2012-07-13 06:28:28 +08:00
										 |  |  | #include "TypeAttributesTable.h"
 | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  | #include <boost/foreach.hpp>
 | 
					
						
							|  |  |  | #include <boost/range/adaptor/map.hpp>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <string>
 | 
					
						
							|  |  |  | #include <map>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | namespace wrap { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  | /// Class has name, constructors, methods
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  | class Class: public Qualified { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   typedef std::map<std::string, Method> Methods; | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |   Methods methods; ///< Class methods
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |   typedef const std::string& Str; | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   typedef std::map<std::string, StaticMethod> StaticMethods; | 
					
						
							| 
									
										
										
										
											2012-07-05 22:05:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |   // Then the instance variables are set directly by the Module constructor
 | 
					
						
							|  |  |  |   std::vector<std::string> templateArgs; ///< Template arguments
 | 
					
						
							|  |  |  |   std::string typedefName; ///< The name to typedef *from*, if this class is actually a typedef, i.e. typedef [typedefName] [name]
 | 
					
						
							|  |  |  |   bool isVirtual; ///< Whether the class is part of a virtual inheritance chain
 | 
					
						
							|  |  |  |   bool isSerializable; ///< Whether we can use boost.serialization to serialize the class - creates exports
 | 
					
						
							|  |  |  |   bool hasSerialization; ///< Whether we should create the serialization functions
 | 
					
						
							|  |  |  |   Qualified qualifiedParent; ///< The *single* parent
 | 
					
						
							|  |  |  |   StaticMethods static_methods; ///< Static methods
 | 
					
						
							|  |  |  |   Constructor constructor; ///< Class constructors
 | 
					
						
							|  |  |  |   Deconstructor deconstructor; ///< Deconstructor to deallocate C++ object
 | 
					
						
							|  |  |  |   bool verbose_; ///< verbose flag
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  |   /// Constructor creates an empty class
 | 
					
						
							| 
									
										
										
										
											2014-11-13 01:04:38 +08:00
										 |  |  |   Class(bool verbose = true) : | 
					
						
							|  |  |  |       isVirtual(false), isSerializable(false), hasSerialization(false), deconstructor( | 
					
						
							|  |  |  |           verbose), verbose_(verbose) { | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |   size_t nrMethods() const { | 
					
						
							|  |  |  |     return methods.size(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   Method& method(Str name) { | 
					
						
							|  |  |  |     return methods.at(name); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   bool exists(Str name) const { | 
					
						
							|  |  |  |     return methods.find(name) != methods.end(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2011-10-14 12:43:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   // And finally MATLAB code is emitted, methods below called by Module::matlab_code
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |   void matlab_proxy(Str toolboxPath, Str wrapperName, | 
					
						
							|  |  |  |       const TypeAttributesTable& typeAttributes, FileWriter& wrapperFile, | 
					
						
							|  |  |  |       std::vector<std::string>& functionNames) const; ///< emit proxy class
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:28:05 +08:00
										 |  |  |   Class expandTemplate(const TemplateSubstitution& ts) const; | 
					
						
							| 
									
										
										
										
											2013-06-20 01:49:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |   std::vector<Class> expandTemplate(Str templateArg, | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |       const std::vector<Qualified>& instantiations) const; | 
					
						
							| 
									
										
										
										
											2012-07-12 05:43:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |   /// Add potentially overloaded, potentially templated method
 | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |   void addMethod(bool verbose, bool is_const, Str methodName, | 
					
						
							|  |  |  |       const ArgumentList& argumentList, const ReturnValue& returnValue, | 
					
						
							|  |  |  |       Str templateArgName, const std::vector<Qualified>& templateArgValues); | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   /// Post-process classes for serialization markers
 | 
					
						
							|  |  |  |   void erase_serialization(); // non-const !
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// verify all of the function arguments
 | 
					
						
							|  |  |  |   void verifyAll(std::vector<std::string>& functionNames, | 
					
						
							|  |  |  |       bool& hasSerialiable) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void appendInheritedMethods(const Class& cls, | 
					
						
							|  |  |  |       const std::vector<Class>& classes); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /// The typedef line for this class, if this class is a typedef, otherwise returns an empty string.
 | 
					
						
							| 
									
										
										
										
											2012-10-02 22:40:07 +08:00
										 |  |  |   std::string getTypedef() const; | 
					
						
							| 
									
										
										
										
											2012-07-12 05:43:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |   /// Returns the string for an export flag
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:03 +08:00
										 |  |  |   std::string getSerializationExport() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |   /// Creates a member function that performs serialization
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:00 +08:00
										 |  |  |   void serialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |       Str wrapperName, std::vector<std::string>& functionNames) const; | 
					
						
							| 
									
										
										
										
											2012-08-26 23:46:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |   /// Creates a static member function that performs deserialization
 | 
					
						
							| 
									
										
										
										
											2013-06-20 01:50:00 +08:00
										 |  |  |   void deserialization_fragments(FileWriter& proxyFile, FileWriter& wrapperFile, | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |       Str wrapperName, std::vector<std::string>& functionNames) const; | 
					
						
							| 
									
										
										
										
											2013-06-20 01:49:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  |   friend std::ostream& operator<<(std::ostream& os, const Class& cls) { | 
					
						
							| 
									
										
										
										
											2014-11-14 04:34:59 +08:00
										 |  |  |     os << "class " << cls.name << "{\n"; | 
					
						
							|  |  |  |     os << cls.constructor << ";\n"; | 
					
						
							|  |  |  |     BOOST_FOREACH(const StaticMethod& m, cls.static_methods | boost::adaptors::map_values) | 
					
						
							|  |  |  |       os << m << ";\n"; | 
					
						
							| 
									
										
										
										
											2014-11-14 04:11:29 +08:00
										 |  |  |     BOOST_FOREACH(const Method& m, cls.methods | boost::adaptors::map_values) | 
					
						
							|  |  |  |       os << m << ";\n"; | 
					
						
							|  |  |  |     os << "};" << std::endl; | 
					
						
							|  |  |  |     return os; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-07-05 22:04:57 +08:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   void pointer_constructor_fragments(FileWriter& proxyFile, | 
					
						
							| 
									
										
										
										
											2014-11-14 00:34:33 +08:00
										 |  |  |       FileWriter& wrapperFile, Str wrapperName, | 
					
						
							| 
									
										
										
										
											2014-11-13 06:22:59 +08:00
										 |  |  |       std::vector<std::string>& functionNames) const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   void comment_fragment(FileWriter& proxyFile) const; | 
					
						
							| 
									
										
										
										
											2011-10-14 02:41:56 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 00:43:15 +08:00
										 |  |  | } // \namespace wrap
 | 
					
						
							|  |  |  | 
 |