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 <list>
// 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<Argument> {
std::list<Argument> args;
std::string types ();
std::string signature();
std::string names ();
/// Argument list
struct ArgumentList: public std::list<Argument> {
std::list<Argument> 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++
};

View File

@ -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<Constructor> constructors;
std::list<Method> 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<Constructor> constructors; ///< Class constructors
std::list<Method> 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
};

View File

@ -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);
};

View File

@ -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
};

View File

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

View File

@ -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<Class> classes;
bool verbose_;
std::string name; ///< module name
std::list<Class> 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);

View File

@ -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;
}
/* ************************************************************************* */