Added better support for "using namespace x" to wrap - only applies to classes *after* it is called
parent
f2c7e891c4
commit
f8a03ddbca
3
gtsam.h
3
gtsam.h
|
@ -32,6 +32,9 @@
|
|||
* Namespace usage
|
||||
* - Namespaces can be specified for classes in arguments and return values
|
||||
* - In each case, the namespace must be fully specified, e.g., "namespace1::namespace2::ClassName"
|
||||
* Using namespace
|
||||
* - To use a namespace (e.g., generate a "using namespace x" line in cpp files), add "using namespace x;"
|
||||
* - This declaration applies to all classes *after* the declaration, regardless of brackets
|
||||
* Methods must start with a lowercase letter
|
||||
* Static methods must start with a letter (upper or lowercase) and use the "static" keyword
|
||||
* Includes in C++ wrappers
|
||||
|
|
|
@ -61,7 +61,7 @@ void Class::matlab_proxy(const string& classFile) const {
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::matlab_constructors(const string& toolboxPath, const vector<string>& using_namespaces) const {
|
||||
void Class::matlab_constructors(const string& toolboxPath) const {
|
||||
BOOST_FOREACH(Constructor c, constructors) {
|
||||
c.matlab_mfile (toolboxPath, qualifiedName());
|
||||
c.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), using_namespaces, includes);
|
||||
|
@ -69,12 +69,12 @@ void Class::matlab_constructors(const string& toolboxPath, const vector<string>&
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::matlab_deconstructor(const string& toolboxPath, const vector<string>& using_namespaces) const {
|
||||
void Class::matlab_deconstructor(const string& toolboxPath) const {
|
||||
d.matlab_mfile (toolboxPath, qualifiedName());
|
||||
d.matlab_wrapper(toolboxPath, qualifiedName("::"), qualifiedName(), using_namespaces, includes);
|
||||
}
|
||||
/* ************************************************************************* */
|
||||
void Class::matlab_methods(const string& classPath, const vector<string>& using_namespaces) const {
|
||||
void Class::matlab_methods(const string& classPath) const {
|
||||
string matlabName = qualifiedName(), cppName = qualifiedName("::");
|
||||
BOOST_FOREACH(Method m, methods) {
|
||||
m.matlab_mfile (classPath);
|
||||
|
@ -83,7 +83,7 @@ void Class::matlab_methods(const string& classPath, const vector<string>& using_
|
|||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void Class::matlab_static_methods(const string& toolboxPath, const vector<string>& using_namespaces) const {
|
||||
void Class::matlab_static_methods(const string& toolboxPath) const {
|
||||
string matlabName = qualifiedName(), cppName = qualifiedName("::");
|
||||
BOOST_FOREACH(const StaticMethod& m, static_methods) {
|
||||
m.matlab_mfile (toolboxPath, qualifiedName());
|
||||
|
|
13
wrap/Class.h
13
wrap/Class.h
|
@ -37,20 +37,17 @@ struct Class {
|
|||
std::vector<Method> methods; ///< Class methods
|
||||
std::vector<StaticMethod> static_methods; ///< Static methods
|
||||
std::vector<std::string> namespaces; ///< Stack of namespaces
|
||||
std::vector<std::string> using_namespaces; ///< default namespaces
|
||||
std::vector<std::string> includes; ///< header include overrides
|
||||
Deconstructor d;
|
||||
bool verbose_; ///< verbose flag
|
||||
|
||||
// And finally MATLAB code is emitted, methods below called by Module::matlab_code
|
||||
void matlab_proxy(const std::string& classFile) const; ///< emit proxy class
|
||||
void matlab_constructors(const std::string& toolboxPath,
|
||||
const std::vector<std::string>& using_namespaces) const; ///< emit constructor wrappers
|
||||
void matlab_deconstructor(const std::string& toolboxPath,
|
||||
const std::vector<std::string>& using_namespaces) const;
|
||||
void matlab_methods(const std::string& classPath,
|
||||
const std::vector<std::string>& using_namespaces) const; ///< emit method wrappers
|
||||
void matlab_static_methods(const std::string& classPath,
|
||||
const std::vector<std::string>& using_namespaces) const; ///< emit static method wrappers
|
||||
void matlab_constructors(const std::string& toolboxPath) const; ///< emit constructor wrappers
|
||||
void matlab_deconstructor(const std::string& toolboxPath) const;
|
||||
void matlab_methods(const std::string& classPath) const; ///< emit method wrappers
|
||||
void matlab_static_methods(const std::string& classPath) const; ///< emit static method wrappers
|
||||
void matlab_make_fragment(FileWriter& file,
|
||||
const std::string& toolboxPath,
|
||||
const std::string& mexFlags) const; ///< emit make fragment for global make script
|
||||
|
|
|
@ -57,7 +57,8 @@ Module::Module(const string& interfacePath,
|
|||
Class cls0(enable_verbose),cls(enable_verbose);
|
||||
vector<string> namespaces, /// current namespace tag
|
||||
namespace_includes, /// current set of includes
|
||||
namespaces_return; /// namespace for current return type
|
||||
namespaces_return, /// namespace for current return type
|
||||
using_namespace_current; /// All namespaces from "using" declarations
|
||||
string include_path = "";
|
||||
string class_name = "";
|
||||
const string null_str = "";
|
||||
|
@ -182,6 +183,7 @@ Module::Module(const string& interfacePath,
|
|||
>> *(functions_p | comments_p)
|
||||
>> str_p("};"))
|
||||
[assign_a(cls.namespaces, namespaces)]
|
||||
[assign_a(cls.using_namespaces, using_namespace_current)]
|
||||
[append_a(cls.includes, namespace_includes)]
|
||||
[assign_a(deconstructor.name,cls.name)]
|
||||
[assign_a(cls.d, deconstructor)]
|
||||
|
@ -202,7 +204,7 @@ Module::Module(const string& interfacePath,
|
|||
|
||||
Rule using_namespace_p =
|
||||
str_p("using") >> str_p("namespace")
|
||||
>> namespace_name_p[push_back_a(using_namespaces)] >> ch_p(';');
|
||||
>> namespace_name_p[push_back_a(using_namespace_current)] >> ch_p(';');
|
||||
|
||||
Rule forward_declaration_p =
|
||||
str_p("class") >>
|
||||
|
@ -342,12 +344,12 @@ void Module::matlab_code(const string& toolboxPath,
|
|||
verifyReturnTypes<Method>(validTypes, cls.methods);
|
||||
|
||||
// create constructor and method wrappers
|
||||
cls.matlab_constructors(toolboxPath,using_namespaces);
|
||||
cls.matlab_static_methods(toolboxPath,using_namespaces);
|
||||
cls.matlab_methods(classPath,using_namespaces);
|
||||
cls.matlab_constructors(toolboxPath);
|
||||
cls.matlab_static_methods(toolboxPath);
|
||||
cls.matlab_methods(classPath);
|
||||
|
||||
// create deconstructor
|
||||
cls.matlab_deconstructor(toolboxPath,using_namespaces);
|
||||
cls.matlab_deconstructor(toolboxPath);
|
||||
|
||||
// add lines to make m-file
|
||||
makeModuleMfile.oss << "%% " << cls.qualifiedName() << endl;
|
||||
|
|
|
@ -31,7 +31,7 @@ struct Module {
|
|||
std::string name; ///< module name
|
||||
std::vector<Class> classes; ///< list of classes
|
||||
bool verbose; ///< verbose flag
|
||||
std::vector<std::string> using_namespaces; ///< all default namespaces
|
||||
// std::vector<std::string> using_namespaces; ///< all default namespaces
|
||||
std::vector<std::string> forward_declarations;
|
||||
|
||||
/// constructor that parses interface file
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("argChar",nargout,nargin-1,1);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("argUChar",nargout,nargin-1,1);
|
||||
shared_ptr<Point2> self = unwrap_shared_ptr< Point2 >(in[0],"Point2");
|
||||
unsigned char a = unwrap< unsigned char >(in[1]);
|
||||
self->argUChar(a);
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
automatically generated by wrap
|
||||
function result = argUChar(obj,a)
|
||||
% usage: obj.argUChar(a)
|
||||
error('need to compile argUChar.cpp');
|
||||
end
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("dim",nargout,nargin-1,0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("returnChar",nargout,nargin-1,0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("vectorConfusion",nargout,nargin-1,0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("x",nargout,nargin-1,0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("y",nargout,nargin-1,0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("delete_Point2",nargout,nargin,1);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("new_Point2_",nargout,nargin,0);
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// automatically generated by wrap
|
||||
#include <wrap/matlab.h>
|
||||
#include <Point2.h>
|
||||
using namespace geometry;
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("new_Point2_dd",nargout,nargin,2);
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
// comments!
|
||||
|
||||
// set the default namespace
|
||||
// location of namespace isn't significant
|
||||
using namespace geometry;
|
||||
|
||||
class VectorNotEigen;
|
||||
class ns::OtherClass;
|
||||
|
||||
|
@ -19,6 +15,9 @@ class Point2 {
|
|||
VectorNotEigen vectorConfusion();
|
||||
};
|
||||
|
||||
// flag a namespace as in use - only applies *after* the declaration
|
||||
using namespace geometry;
|
||||
|
||||
class Point3 {
|
||||
Point3(double x, double y, double z);
|
||||
double norm() const;
|
||||
|
|
|
@ -72,8 +72,7 @@ TEST( wrap, parse ) {
|
|||
EXPECT_LONGS_EQUAL(3, module.classes.size());
|
||||
|
||||
// check using declarations
|
||||
strvec exp_using; exp_using += "geometry";
|
||||
EXPECT(assert_equal(exp_using, module.using_namespaces));
|
||||
strvec exp_using1, exp_using2; exp_using2 += "geometry";
|
||||
|
||||
// forward declarations
|
||||
strvec exp_forward; exp_forward += "VectorNotEigen", "ns::OtherClass";
|
||||
|
@ -87,6 +86,7 @@ TEST( wrap, parse ) {
|
|||
EXPECT_LONGS_EQUAL(7, cls.methods.size());
|
||||
EXPECT_LONGS_EQUAL(0, cls.static_methods.size());
|
||||
EXPECT_LONGS_EQUAL(0, cls.namespaces.size());
|
||||
EXPECT(assert_equal(exp_using1, cls.using_namespaces));
|
||||
}
|
||||
|
||||
// check second class, Point3
|
||||
|
@ -97,6 +97,7 @@ TEST( wrap, parse ) {
|
|||
EXPECT_LONGS_EQUAL(1, cls.methods.size());
|
||||
EXPECT_LONGS_EQUAL(2, cls.static_methods.size());
|
||||
EXPECT_LONGS_EQUAL(0, cls.namespaces.size());
|
||||
EXPECT(assert_equal(exp_using2, cls.using_namespaces));
|
||||
|
||||
// first constructor takes 3 doubles
|
||||
Constructor c1 = cls.constructors.front();
|
||||
|
@ -125,6 +126,7 @@ TEST( wrap, parse ) {
|
|||
EXPECT_LONGS_EQUAL(19, testCls.methods.size());
|
||||
EXPECT_LONGS_EQUAL( 0, testCls.static_methods.size());
|
||||
EXPECT_LONGS_EQUAL( 0, testCls.namespaces.size());
|
||||
EXPECT(assert_equal(exp_using2, testCls.using_namespaces));
|
||||
strvec exp_includes; exp_includes += "folder/path/to/Test.h";
|
||||
EXPECT(assert_equal(exp_includes, testCls.includes));
|
||||
|
||||
|
|
Loading…
Reference in New Issue