Documentation

release/4.3a0
Frank Dellaert 2011-10-14 04:43:06 +00:00
parent cd2c687b54
commit 5fd71a33eb
7 changed files with 111 additions and 85 deletions

View File

@ -20,32 +20,33 @@
#include <string> #include <string>
#include <list> #include <list>
// Argument class /// Argument class
struct Argument { struct Argument {
bool is_const, is_ref, is_ptr; bool is_const, is_ref, is_ptr;
std::string type; std::string type;
std::string name; std::string name;
Argument() : is_const(false), is_ref(false), is_ptr(false) {} Argument() :
is_const(false), is_ref(false), is_ptr(false) {
}
// MATLAB code generation: /// MATLAB code generation, MATLAB to C++
void matlab_unwrap(std::ofstream& ofs, void matlab_unwrap(std::ofstream& ofs, const std::string& matlabName);
const std::string& matlabName); // MATLAB to C++
}; };
// Argument list /// Argument list
struct ArgumentList : public std::list<Argument> { struct ArgumentList: public std::list<Argument> {
std::list<Argument> args; std::list<Argument> args;
std::string types (); std::string types();
std::string signature(); std::string signature();
std::string names (); std::string names();
// MATLAB code generation: // MATLAB code generation:
/** /**
* emit code to unwrap arguments * emit code to unwrap arguments
* @param ofs output stream * @param ofs output stream
* @param start initial index for input array, set to 1 for method * @param start initial index for input array, set to 1 for method
*/ */
void matlab_unwrap(std::ofstream& ofs, int start=0); // MATLAB to C++ void matlab_unwrap(std::ofstream& ofs, int start = 0); // MATLAB to C++
}; };

View File

@ -23,23 +23,25 @@
#include "Constructor.h" #include "Constructor.h"
#include "Method.h" #include "Method.h"
// Class has name, constructors, methods /// Class has name, constructors, methods
struct Class { struct Class {
std::string name; /// Constructor creates an empty class
std::list<Constructor> constructors;
std::list<Method> methods;
bool verbose_;
Class(bool verbose=true) : verbose_(verbose) {} Class(bool verbose=true) : verbose_(verbose) {}
// MATLAB code generation: // Then the instance variables are set directly by the Module constructor
void matlab_proxy(const std::string& classFile); // proxy class std::string name; ///< Class name
void matlab_constructors(const std::string& toolboxPath, std::list<Constructor> constructors; ///< Class constructors
const std::string& nameSpace); // constructor wrappers std::list<Method> methods; ///< Class methods
void matlab_methods(const std::string& classPath, bool verbose_; ///< verbose flag
const std::string& nameSpace); // method wrappers
void matlab_make_fragment(std::ofstream& ofs, // And finally MATLAB code is emitted, methods below called by Module::matlab_code
const std::string& toolboxPath, void matlab_proxy(const std::string& classFile); ///< emit proxy class
const std::string& mexFlags); // make fragment 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
}; };

View File

@ -24,20 +24,32 @@
// Constructor class // Constructor class
struct Constructor { 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 // Then the instance variables are set directly by the Module constructor
// toolboxPath is main toolbox directory, e.g., ../matlab ArgumentList args;
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m bool verbose_;
std::string matlab_wrapper_name(const std::string& className); // wrapper name // MATLAB code generation
void matlab_proxy_fragment(std::ofstream& ofs, const std::string& className); // proxy class fragment // toolboxPath is main toolbox directory, e.g., ../matlab
void matlab_mfile (const std::string& toolboxPath, const std::string& className); // m-file // classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
void matlab_wrapper(const std::string& toolboxPath,
const std::string& className, /// wrapper name
const std::string& nameSpace); // wrapper 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);
}; };

View File

@ -24,23 +24,30 @@
/// Method class /// Method class
struct Method { 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}; // Then the instance variables are set directly by the Module constructor
std::string return_type(bool add_ptr, pairing p); bool is_const;
ArgumentList args;
std::string returns, returns2, name;
bool returns_ptr, returns_ptr2, returns_pair;
bool verbose_;
// MATLAB code generation enum pairing {
// classPath is class directory, e.g., ../matlab/@Point2 arg1, arg2, pair
};
std::string return_type(bool add_ptr, pairing p);
void matlab_mfile (const std::string& classPath); // m-file // MATLAB code generation
void matlab_wrapper(const std::string& classPath, // classPath is class directory, e.g., ../matlab/@Point2
const std::string& className,
const std::string& nameSpace); // wrapper 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
}; };

View File

@ -14,15 +14,15 @@
* @author Frank Dellaert * @author Frank Dellaert
**/ **/
#include <iostream> #include "Module.h"
#include <fstream> #include "utilities.h"
//#define BOOST_SPIRIT_DEBUG //#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/classic_core.hpp> #include <boost/spirit/include/classic_core.hpp>
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include "Module.h" #include <iostream>
#include "utilities.h" #include <fstream>
using namespace std; using namespace std;
using namespace BOOST_SPIRIT_CLASSIC_NS; using namespace BOOST_SPIRIT_CLASSIC_NS;

View File

@ -22,22 +22,20 @@
#include "Class.h" #include "Class.h"
// A module has classes /**
* A module just has a name and a list of classes
*/
struct Module { struct Module {
std::string name; std::string name; ///< module name
std::list<Class> classes; std::list<Class> classes; ///< list of classes
bool verbose_; bool verbose_; ///< verbose flag
/** /// constructor that parses interface file
* constructor that parses interface file
*/
Module(const std::string& interfacePath, Module(const std::string& interfacePath,
const std::string& moduleName, const std::string& moduleName,
bool verbose=true); bool verbose=true);
/** /// MATLAB code generation:
* MATLAB code generation:
*/
void matlab_code(const std::string& path, void matlab_code(const std::string& path,
const std::string& nameSpace, const std::string& nameSpace,
const std::string& mexFlags); const std::string& mexFlags);

View File

@ -22,9 +22,13 @@
using namespace std; 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, void generate_matlab_toolbox(const string& interfacePath,
const string& moduleName, const string& moduleName,
@ -32,15 +36,18 @@ void generate_matlab_toolbox(const string& interfacePath,
const string& nameSpace, const string& nameSpace,
const string& mexFlags) const string& mexFlags)
{ {
// Parse into class object // Parse interface file into class object
Module module(interfacePath, moduleName, false); // 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); 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[]) { int main(int argc, const char* argv[]) {
if (argc<5 || argc>6) { if (argc<5 || argc>6) {
cerr << "wrap parses an interface file and produces a MATLAB toolbox" << endl; cerr << "wrap parses an interface file and produces a MATLAB toolbox" << endl;
@ -53,6 +60,5 @@ int main(int argc, const char* argv[]) {
} }
else else
generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4],argc==5 ? " " : argv[5]); generate_matlab_toolbox(argv[1],argv[2],argv[3],argv[4],argc==5 ? " " : argv[5]);
return 0;
} }
/* ************************************************************************* */