diff --git a/wrap/Argument.h b/wrap/Argument.h index bf4a5a9a7..2248e1790 100644 --- a/wrap/Argument.h +++ b/wrap/Argument.h @@ -20,32 +20,33 @@ #include #include -// Argument class +/// Argument class struct Argument { - bool is_const, is_ref, is_ptr; - std::string type; - std::string name; -Argument() : is_const(false), is_ref(false), is_ptr(false) {} + bool is_const, is_ref, is_ptr; + std::string type; + std::string name; + Argument() : + is_const(false), is_ref(false), is_ptr(false) { + } - // MATLAB code generation: - void matlab_unwrap(std::ofstream& ofs, - const std::string& matlabName); // MATLAB to C++ + /// MATLAB code generation, MATLAB to C++ + void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName); }; -// Argument list -struct ArgumentList : public std::list { - std::list args; - std::string types (); - std::string signature(); - std::string names (); +/// Argument list +struct ArgumentList: public std::list { + std::list args; + std::string types(); + std::string signature(); + std::string names(); - // MATLAB code generation: + // MATLAB code generation: - /** - * emit code to unwrap arguments - * @param ofs output stream - * @param start initial index for input array, set to 1 for method - */ - void matlab_unwrap(std::ofstream& ofs, int start=0); // MATLAB to C++ + /** + * emit code to unwrap arguments + * @param ofs output stream + * @param start initial index for input array, set to 1 for method + */ + void matlab_unwrap(std::ofstream& ofs, int start = 0); // MATLAB to C++ }; diff --git a/wrap/Class.h b/wrap/Class.h index dd91e99ab..ca85b06b1 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -23,23 +23,25 @@ #include "Constructor.h" #include "Method.h" -// Class has name, constructors, methods +/// Class has name, constructors, methods struct Class { - std::string name; - std::list constructors; - std::list methods; - bool verbose_; - + /// Constructor creates an empty class Class(bool verbose=true) : verbose_(verbose) {} - // MATLAB code generation: - void matlab_proxy(const std::string& classFile); // proxy class - void matlab_constructors(const std::string& toolboxPath, - const std::string& nameSpace); // constructor wrappers - void matlab_methods(const std::string& classPath, - const std::string& nameSpace); // method wrappers - void matlab_make_fragment(std::ofstream& ofs, - const std::string& toolboxPath, - const std::string& mexFlags); // make fragment + // Then the instance variables are set directly by the Module constructor + std::string name; ///< Class name + std::list constructors; ///< Class constructors + std::list methods; ///< Class methods + bool verbose_; ///< verbose flag + + // And finally MATLAB code is emitted, methods below called by Module::matlab_code + void matlab_proxy(const std::string& classFile); ///< emit proxy class + void matlab_constructors(const std::string& toolboxPath, + const std::string& nameSpace); ///< emit constructor wrappers + void matlab_methods(const std::string& classPath, + const std::string& nameSpace); ///< emit method wrappers + void matlab_make_fragment(std::ofstream& ofs, + const std::string& toolboxPath, + const std::string& mexFlags); ///< emit make fragment for global make script }; diff --git a/wrap/Constructor.h b/wrap/Constructor.h index d88cc64da..340ac0fd2 100644 --- a/wrap/Constructor.h +++ b/wrap/Constructor.h @@ -24,20 +24,32 @@ // Constructor class struct Constructor { - ArgumentList args; - bool verbose_; - Constructor(bool verbose=true) : verbose_(verbose) {} + /// Constructor creates an empty class + Constructor(bool verbose = true) : + verbose_(verbose) { + } - // MATLAB code generation - // toolboxPath is main toolbox directory, e.g., ../matlab - // classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m + // Then the instance variables are set directly by the Module constructor + ArgumentList args; + bool verbose_; - std::string matlab_wrapper_name(const std::string& className); // wrapper name - void matlab_proxy_fragment(std::ofstream& ofs, const std::string& className); // proxy class fragment - void matlab_mfile (const std::string& toolboxPath, const std::string& className); // m-file - void matlab_wrapper(const std::string& toolboxPath, - const std::string& className, - const std::string& nameSpace); // wrapper + // MATLAB code generation + // toolboxPath is main toolbox directory, e.g., ../matlab + // classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m + + /// wrapper name + std::string matlab_wrapper_name(const std::string& className); + + /// proxy class fragment + void matlab_proxy_fragment(std::ofstream& ofs, const std::string& className); + + /// m-file + void matlab_mfile(const std::string& toolboxPath, + const std::string& className); + + /// wrapper + void matlab_wrapper(const std::string& toolboxPath, + const std::string& className, const std::string& nameSpace); }; diff --git a/wrap/Method.h b/wrap/Method.h index 4d8cc0d00..1fe32bfeb 100644 --- a/wrap/Method.h +++ b/wrap/Method.h @@ -24,23 +24,30 @@ /// Method class struct Method { - bool is_const; - ArgumentList args; - std::string returns, returns2, name; - bool returns_ptr, returns_ptr2, returns_pair; - bool verbose_; - Method(bool verbose=true) : returns_ptr(false), returns_ptr2(false), returns_pair(false), verbose_(verbose) {} + /// Constructor creates empty object + Method(bool verbose = true) : + returns_ptr(false), returns_ptr2(false), returns_pair(false), verbose_( + verbose) { + } - enum pairing {arg1, arg2, pair}; - std::string return_type(bool add_ptr, pairing p); + // Then the instance variables are set directly by the Module constructor + bool is_const; + ArgumentList args; + std::string returns, returns2, name; + bool returns_ptr, returns_ptr2, returns_pair; + bool verbose_; - // MATLAB code generation - // classPath is class directory, e.g., ../matlab/@Point2 + enum pairing { + arg1, arg2, pair + }; + std::string return_type(bool add_ptr, pairing p); - void matlab_mfile (const std::string& classPath); // m-file - void matlab_wrapper(const std::string& classPath, - const std::string& className, - const std::string& nameSpace); // wrapper + // MATLAB code generation + // classPath is class directory, e.g., ../matlab/@Point2 + + void matlab_mfile(const std::string& classPath); ///< m-file + void matlab_wrapper(const std::string& classPath, + const std::string& className, const std::string& nameSpace); ///< wrapper }; diff --git a/wrap/Module.cpp b/wrap/Module.cpp index d7a7709f0..82ff3f0ca 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -14,15 +14,15 @@ * @author Frank Dellaert **/ -#include -#include +#include "Module.h" +#include "utilities.h" //#define BOOST_SPIRIT_DEBUG #include #include -#include "Module.h" -#include "utilities.h" +#include +#include using namespace std; using namespace BOOST_SPIRIT_CLASSIC_NS; diff --git a/wrap/Module.h b/wrap/Module.h index 54c148bb0..0227e86d9 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -22,22 +22,20 @@ #include "Class.h" -// A module has classes +/** + * A module just has a name and a list of classes + */ struct Module { - std::string name; - std::list classes; - bool verbose_; + std::string name; ///< module name + std::list classes; ///< list of classes + bool verbose_; ///< verbose flag - /** - * constructor that parses interface file - */ + /// constructor that parses interface file Module(const std::string& interfacePath, const std::string& moduleName, bool verbose=true); - /** - * MATLAB code generation: - */ + /// MATLAB code generation: void matlab_code(const std::string& path, const std::string& nameSpace, const std::string& mexFlags); diff --git a/wrap/wrap.cpp b/wrap/wrap.cpp index c7fc71722..d18664cda 100644 --- a/wrap/wrap.cpp +++ b/wrap/wrap.cpp @@ -22,9 +22,13 @@ using namespace std; -/* ************************************************************************* */ /** - * main function to wrap a module + * Top-level function to wrap a module + * @param interfacePath path to where interface file lives, e.g., borg/gtsam + * @param moduleName name of the module to be generated e.g. gtsam + * @param toolboxPath path where the toolbox should be generated, e.g. borg/gtsam/build + * @param nameSpace e.g. gtsam + * @param mexFlags extra arguments for mex script, i.e., include flags etc... */ void generate_matlab_toolbox(const string& interfacePath, const string& moduleName, @@ -32,15 +36,18 @@ void generate_matlab_toolbox(const string& interfacePath, const string& nameSpace, const string& mexFlags) { - // Parse into class object - Module module(interfacePath, moduleName, false); + // Parse interface file into class object + // This recursively creates Class objects, Method objects, etc... + Module module(interfacePath, moduleName, true); - // emit MATLAB code + // Then emit MATLAB code module.matlab_code(toolboxPath,nameSpace,mexFlags); } -/* ************************************************************************* */ - +/** + * main parses arguments and calls generate_matlab_toolbox above + * Typyically called from "make all" using appropriate arguments + */ int main(int argc, const char* argv[]) { if (argc<5 || argc>6) { cerr << "wrap parses an interface file and produces a MATLAB toolbox" << endl; @@ -53,6 +60,5 @@ int main(int argc, const char* argv[]) { } else generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4],argc==5 ? " " : argv[5]); + return 0; } - -/* ************************************************************************* */