diff --git a/gtsam.h b/gtsam.h index 05a41afc3..f32b12131 100644 --- a/gtsam.h +++ b/gtsam.h @@ -46,11 +46,9 @@ * - 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 * Includes in C++ wrappers - * - By default, the include will be <[classname].h> - * - All namespaces must have angle brackets: - * - To override, add a full include statement just before the class statement - * - An override include can be added for a namespace by placing it just before the namespace statement - * - Both classes and namespace accept exactly one namespace + * - All includes will be collected and added in a single file + * - All namespaces must have angle brackets: + * - No default includes will be added * Using classes defined in other modules * - If you are using a class 'OtherClass' not wrapped in this definition file, add "class OtherClass;" to avoid a dependency error * Virtual inheritance @@ -98,6 +96,7 @@ virtual class Value { size_t dim() const; }; +#include virtual class LieVector : gtsam::Value { // Standard constructors LieVector(); @@ -126,6 +125,7 @@ virtual class LieVector : gtsam::Value { static Vector Logmap(const gtsam::LieVector& p); }; +#include virtual class LieMatrix : gtsam::Value { // Standard constructors LieMatrix(); @@ -472,6 +472,7 @@ virtual class Cal3_S2 : gtsam::Value { Matrix matrix_inverse() const; }; +#include virtual class Cal3DS2 : gtsam::Value { // Standard Constructors Cal3DS2(); @@ -715,6 +716,7 @@ class SymbolicFactorGraph { //FastSet keys() const; }; +#include class SymbolicSequentialSolver { // Standard Constructors and Named Constructors SymbolicSequentialSolver(const gtsam::SymbolicFactorGraph& factorGraph); @@ -728,6 +730,7 @@ class SymbolicSequentialSolver { gtsam::SymbolicBayesNet* eliminate() const; }; +#include class SymbolicMultifrontalSolver { // Standard Constructors and Named Constructors SymbolicMultifrontalSolver(const gtsam::SymbolicFactorGraph& factorGraph); @@ -776,7 +779,6 @@ namespace noiseModel { virtual class Base { }; -#include virtual class Gaussian : gtsam::noiseModel::Base { static gtsam::noiseModel::Gaussian* SqrtInformation(Matrix R); static gtsam::noiseModel::Gaussian* Covariance(Matrix R); @@ -784,7 +786,6 @@ virtual class Gaussian : gtsam::noiseModel::Base { void print(string s) const; }; -#include virtual class Diagonal : gtsam::noiseModel::Gaussian { static gtsam::noiseModel::Diagonal* Sigmas(Vector sigmas); static gtsam::noiseModel::Diagonal* Variances(Vector variances); @@ -793,7 +794,6 @@ virtual class Diagonal : gtsam::noiseModel::Gaussian { void print(string s) const; }; -#include virtual class Isotropic : gtsam::noiseModel::Diagonal { static gtsam::noiseModel::Isotropic* Sigma(size_t dim, double sigma); static gtsam::noiseModel::Isotropic* Variance(size_t dim, double varianace); @@ -801,14 +801,13 @@ virtual class Isotropic : gtsam::noiseModel::Diagonal { void print(string s) const; }; -#include virtual class Unit : gtsam::noiseModel::Isotropic { static gtsam::noiseModel::Unit* Create(size_t dim); void print(string s) const; }; }///\namespace noiseModel - +#include class Sampler { Sampler(gtsam::noiseModel::Diagonal* model, int seed); Sampler(Vector sigmas, int seed); @@ -948,6 +947,7 @@ class GaussianISAM { gtsam::GaussianBayesNet* jointBayesNet(size_t key1, size_t key2) const; }; +#include class GaussianSequentialSolver { GaussianSequentialSolver(const gtsam::GaussianFactorGraph& graph, bool useQR); @@ -957,6 +957,7 @@ class GaussianSequentialSolver { Matrix marginalCovariance(size_t j) const; }; +#include class KalmanFilter { KalmanFilter(size_t n); // gtsam::GaussianDensity* init(Vector x0, const gtsam::SharedDiagonal& P0); @@ -979,6 +980,7 @@ class KalmanFilter { // nonlinear //************************************************************************* +#include class Symbol { Symbol(char c, size_t j); Symbol(size_t k); @@ -988,6 +990,7 @@ class Symbol { char chr() const; }; +#include class Ordering { // Standard Constructors and Named Constructors Ordering(); @@ -1007,7 +1010,6 @@ class Ordering { gtsam::InvertedOrdering invert() const; }; -#include class InvertedOrdering { InvertedOrdering(); @@ -1203,7 +1205,7 @@ virtual class BearingFactor : gtsam::NonlinearFactor { typedef gtsam::BearingFactor BearingFactor2D; -#include +#include template virtual class GenericProjectionFactor : gtsam::NonlinearFactor { GenericProjectionFactor(const gtsam::Point2& measured, const gtsam::noiseModel::Base* noiseModel, diff --git a/gtsam/CMakeLists.txt b/gtsam/CMakeLists.txt index 66870a09c..39ae67507 100644 --- a/gtsam/CMakeLists.txt +++ b/gtsam/CMakeLists.txt @@ -119,14 +119,13 @@ if (GTSAM_INSTALL_MATLAB_TOOLBOX) # Set up codegen include(GtsamMatlabWrap) - # TODO: generate these includes programmatically # Choose include flags depending on build process set(MEX_INCLUDE_ROOT ${GTSAM_SOURCE_ROOT_DIR}) set(MEX_LIB_ROOT ${CMAKE_BINARY_DIR}) set(GTSAM_LIB_DIR ${MEX_LIB_ROOT}/gtsam) # Generate, build and install toolbox - set(mexFlags ${GTSAM_BUILD_MEX_BINARY_FLAGS} -I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam -I${MEX_INCLUDE_ROOT}/gtsam/base -I${MEX_INCLUDE_ROOT}/gtsam/geometry -I${MEX_INCLUDE_ROOT}/gtsam/linear -I${MEX_INCLUDE_ROOT}/gtsam/discrete -I${MEX_INCLUDE_ROOT}/gtsam/inference -I${MEX_INCLUDE_ROOT}/gtsam/nonlinear -I${MEX_INCLUDE_ROOT}/gtsam/slam) + set(mexFlags ${GTSAM_BUILD_MEX_BINARY_FLAGS} -I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT}) # Macro to handle details of setting up targets # FIXME: issue with dependency between wrap_gtsam and wrap_gtsam_build, only shows up on CMake 2.8.3 diff --git a/gtsam_unstable/CMakeLists.txt b/gtsam_unstable/CMakeLists.txt index 09fb124a9..64311cdca 100644 --- a/gtsam_unstable/CMakeLists.txt +++ b/gtsam_unstable/CMakeLists.txt @@ -89,7 +89,7 @@ if (GTSAM_INSTALL_MATLAB_TOOLBOX) set(GTSAM_UNSTABLE_LIB_DIR ${MEX_LIB_ROOT}/gtsam_unstable) # Generate, build and install toolbox - set(mexFlags -I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT} -I${MEX_INCLUDE_ROOT}/gtsam_unstable -I${MEX_INCLUDE_ROOT}/gtsam_unstable/dynamics -I${MEX_INCLUDE_ROOT}/gtsam_unstable/discrete) + set(mexFlags -I${Boost_INCLUDE_DIR} -I${MEX_INCLUDE_ROOT}) # Macro to handle details of setting up targets wrap_library(gtsam_unstable "${mexFlags}" "./" gtsam) diff --git a/gtsam_unstable/gtsam_unstable.h b/gtsam_unstable/gtsam_unstable.h index eebb53fbf..c77c71e22 100644 --- a/gtsam_unstable/gtsam_unstable.h +++ b/gtsam_unstable/gtsam_unstable.h @@ -139,13 +139,12 @@ virtual class FullIMUFactor : gtsam::NonlinearFactor { }; -#include +#include virtual class DHeightPrior : gtsam::NonlinearFactor { DHeightPrior(size_t key, double height, const gtsam::noiseModel::Base* model); }; -#include virtual class DRollPrior : gtsam::NonlinearFactor { /** allows for explicit roll parameterization - uses canonical coordinate */ DRollPrior(size_t key, double wx, const gtsam::noiseModel::Base* model); @@ -154,13 +153,11 @@ virtual class DRollPrior : gtsam::NonlinearFactor { }; -#include virtual class VelocityPrior : gtsam::NonlinearFactor { VelocityPrior(size_t key, Vector vel, const gtsam::noiseModel::Base* model); }; -#include virtual class DGroundConstraint : gtsam::NonlinearFactor { // Primary constructor allows for variable height of the "floor" DGroundConstraint(size_t key, double height, const gtsam::noiseModel::Base* model); @@ -182,7 +179,6 @@ class Values { gtsam::PoseRTV pose(size_t key) const; }; -#include class Graph { Graph(); void print(string s) const; diff --git a/wrap/Class.cpp b/wrap/Class.cpp index 2cb36386a..5f7d7aa6e 100644 --- a/wrap/Class.cpp +++ b/wrap/Class.cpp @@ -268,12 +268,6 @@ Class expandClassTemplate(const Class& cls, const string& templateArg, const vec inst.static_methods = expandMethodTemplate(cls.static_methods, templateArg, instName); inst.namespaces = cls.namespaces; inst.using_namespaces = cls.using_namespaces; - bool allIncludesEmpty = true; - BOOST_FOREACH(const string& inc, cls.includes) { if(!inc.empty()) { allIncludesEmpty = false; break; } } - if(allIncludesEmpty) - inst.includes.push_back(cls.name + ".h"); - else - inst.includes = cls.includes; inst.constructor = cls.constructor; inst.constructor.args_list = expandArgumentListsTemplate(cls.constructor.args_list, templateArg, instName); inst.constructor.name = inst.name; diff --git a/wrap/Class.h b/wrap/Class.h index beee2c29f..9a6ca12c7 100644 --- a/wrap/Class.h +++ b/wrap/Class.h @@ -40,7 +40,7 @@ struct Class { // Then the instance variables are set directly by the Module constructor std::string name; ///< Class name - std::vector templateArgs; ///< Template arguments + std::vector 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 std::vector qualifiedParent; ///< The *single* parent - the last string is the parent class name, preceededing elements are a namespace stack @@ -48,7 +48,6 @@ struct Class { StaticMethods static_methods; ///< Static methods std::vector namespaces; ///< Stack of namespaces std::vector using_namespaces;///< default namespaces - std::vector includes; ///< header include overrides Constructor constructor; ///< Class constructors Deconstructor deconstructor; ///< Deconstructor to deallocate C++ object bool verbose_; ///< verbose flag diff --git a/wrap/Module.cpp b/wrap/Module.cpp index e35794440..5776edc0e 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -252,12 +252,9 @@ Module::Module(const string& interfacePath, Rule functions_p = constructor_p | method_p | static_method_p; - Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[assign_a(include_path)] >> ch_p('>'); - Rule class_p = (str_p("")[assign_a(cls,cls0)]) - >> (*(include_p[push_back_a(cls.includes, include_path)][assign_a(include_path, null_str)]) - >> !(templateInstantiations_p | templateList_p) + >> (!(templateInstantiations_p | templateList_p) >> !(str_p("virtual")[assign_a(cls.isVirtual, true)]) >> str_p("class") >> className_p[assign_a(cls.name)] @@ -277,12 +274,13 @@ Module::Module(const string& interfacePath, [clear_a(templateArgument)] [clear_a(templateInstantiations)]; + Rule include_p = str_p("#include") >> ch_p('<') >> (*(anychar_p - '>'))[push_back_a(includes)] >> ch_p('>'); + Rule namespace_def_p = - (*(include_p[push_back_a(includes, include_path)][assign_a(include_path, null_str)]) - >> str_p("namespace") + (str_p("namespace") >> namespace_name_p[push_back_a(namespaces)] >> ch_p('{') - >> *(class_p | templateSingleInstantiation_p | namespace_def_p | comments_p) + >> *(include_p | class_p | templateSingleInstantiation_p | namespace_def_p | comments_p) >> str_p("}///\\namespace") // end namespace, avoid confusion with classes >> !namespace_name_p) [pop_a(namespaces)]; @@ -299,7 +297,7 @@ Module::Module(const string& interfacePath, [push_back_a(forward_declarations, fwDec)] [assign_a(fwDec, fwDec0)]; - Rule module_content_p = comments_p | using_namespace_p | class_p | templateSingleInstantiation_p | forward_declaration_p | namespace_def_p ; + Rule module_content_p = comments_p | using_namespace_p | include_p | class_p | templateSingleInstantiation_p | forward_declaration_p | namespace_def_p ; Rule module_p = *module_content_p >> !end_p; @@ -375,24 +373,7 @@ void verifyReturnTypes(const vector& validtypes, const map& vt void Module::generateIncludes(FileWriter& file) const { // collect includes - vector all_includes; - BOOST_FOREACH(const Class& cls, classes) { - bool added_include = false; - BOOST_FOREACH(const string& s, cls.includes) { - if (!s.empty()) { - all_includes.push_back(s); - added_include = true; - } - } - if (!added_include) // add default include - all_includes.push_back(cls.name + ".h"); - } - - // Add namespace includes - BOOST_FOREACH(const string& s, includes) { - if(!s.empty()) - all_includes.push_back(s); - } + vector all_includes(includes); // sort and remove duplicates sort(all_includes.begin(), all_includes.end()); diff --git a/wrap/Module.h b/wrap/Module.h index c23b4e457..ce1a87969 100644 --- a/wrap/Module.h +++ b/wrap/Module.h @@ -39,7 +39,7 @@ struct Module { bool verbose; ///< verbose flag // std::vector using_namespaces; ///< all default namespaces std::vector forward_declarations; - std::vector includes; ///< header include overrides + std::vector includes; ///< Include statements /// constructor that parses interface file Module(const std::string& interfacePath, diff --git a/wrap/tests/expected/geometry_wrapper.cpp b/wrap/tests/expected/geometry_wrapper.cpp index ade907701..99f261f4f 100644 --- a/wrap/tests/expected/geometry_wrapper.cpp +++ b/wrap/tests/expected/geometry_wrapper.cpp @@ -3,8 +3,6 @@ #include #include -#include -#include #include diff --git a/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp b/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp index fe55075af..679416db5 100644 --- a/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp +++ b/wrap/tests/expected_namespaces/testNamespaces_wrapper.cpp @@ -3,10 +3,6 @@ #include #include -#include -#include -#include -#include #include #include #include diff --git a/wrap/tests/geometry.h b/wrap/tests/geometry.h index a287c44e6..5dfe07b8d 100644 --- a/wrap/tests/geometry.h +++ b/wrap/tests/geometry.h @@ -35,7 +35,9 @@ class Point3 { * A multi-line comment! */ +// An include! Can go anywhere outside of a class, in any order #include + class Test { /* a comment! */ diff --git a/wrap/tests/testWrap.cpp b/wrap/tests/testWrap.cpp index 41af0af7d..4aa5b6f58 100644 --- a/wrap/tests/testWrap.cpp +++ b/wrap/tests/testWrap.cpp @@ -71,7 +71,7 @@ TEST_UNSAFE( wrap, check_exception ) { } /* ************************************************************************* */ -TEST( wrap, parse ) { +TEST( wrap, parse_geometry ) { string markup_header_path = topdir + "/wrap/tests"; Module module(markup_header_path.c_str(), "geometry",enable_verbose); EXPECT_LONGS_EQUAL(3, module.classes.size()); @@ -84,6 +84,10 @@ TEST( wrap, parse ) { EXPECT(assert_equal("VectorNotEigen", module.forward_declarations[0].name)); EXPECT(assert_equal("ns::OtherClass", module.forward_declarations[1].name)); + // includes + strvec exp_includes; exp_includes += "folder/path/to/Test.h"; + EXPECT(assert_equal(exp_includes, module.includes)); + // check first class, Point2 { Class cls = module.classes.at(0); @@ -136,8 +140,6 @@ TEST( wrap, parse ) { 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)); // function to parse: pair return_pair (Vector v, Matrix A) const; CHECK(testCls.methods.find("return_pair") != testCls.methods.end()); @@ -158,8 +160,11 @@ TEST( wrap, parse_namespaces ) { { strvec module_exp_includes; module_exp_includes += "path/to/ns1.h"; + module_exp_includes += "path/to/ns1/ClassB.h"; module_exp_includes += "path/to/ns2.h"; + module_exp_includes += "path/to/ns2/ClassA.h"; module_exp_includes += "path/to/ns3.h"; + EXPECT(assert_equal(module_exp_includes, module.includes)); } { @@ -167,8 +172,6 @@ TEST( wrap, parse_namespaces ) { EXPECT(assert_equal("ClassA", cls.name)); strvec exp_namespaces; exp_namespaces += "ns1"; EXPECT(assert_equal(exp_namespaces, cls.namespaces)); - strvec exp_includes; exp_includes; - EXPECT(assert_equal(exp_includes, cls.includes)); } { @@ -176,8 +179,6 @@ TEST( wrap, parse_namespaces ) { EXPECT(assert_equal("ClassB", cls.name)); strvec exp_namespaces; exp_namespaces += "ns1"; EXPECT(assert_equal(exp_namespaces, cls.namespaces)); - strvec exp_includes; exp_includes += "path/to/ns1/ClassB.h"; - EXPECT(assert_equal(exp_includes, cls.includes)); } { @@ -185,8 +186,6 @@ TEST( wrap, parse_namespaces ) { EXPECT(assert_equal("ClassA", cls.name)); strvec exp_namespaces; exp_namespaces += "ns2"; EXPECT(assert_equal(exp_namespaces, cls.namespaces)); - strvec exp_includes; exp_includes += "path/to/ns2/ClassA.h"; - EXPECT(assert_equal(exp_includes, cls.includes)); } { @@ -194,8 +193,6 @@ TEST( wrap, parse_namespaces ) { EXPECT(assert_equal("ClassB", cls.name)); strvec exp_namespaces; exp_namespaces += "ns2", "ns3"; EXPECT(assert_equal(exp_namespaces, cls.namespaces)); - strvec exp_includes; - EXPECT(assert_equal(exp_includes, cls.includes)); } { @@ -203,8 +200,6 @@ TEST( wrap, parse_namespaces ) { EXPECT(assert_equal("ClassC", cls.name)); strvec exp_namespaces; exp_namespaces += "ns2"; EXPECT(assert_equal(exp_namespaces, cls.namespaces)); - strvec exp_includes; - EXPECT(assert_equal(exp_includes, cls.includes)); } { @@ -212,8 +207,6 @@ TEST( wrap, parse_namespaces ) { EXPECT(assert_equal("ClassD", cls.name)); strvec exp_namespaces; EXPECT(assert_equal(exp_namespaces, cls.namespaces)); - strvec exp_includes; - EXPECT(assert_equal(exp_includes, cls.includes)); } } @@ -243,7 +236,7 @@ TEST( wrap, matlab_code_namespaces ) { } /* ************************************************************************* */ -TEST( wrap, matlab_code ) { +TEST( wrap, matlab_code_geometry ) { // Parse into class object string header_path = topdir + "/wrap/tests"; Module module(header_path,"geometry",enable_verbose);