handle Key by adding noninstantiating normal typedef rule. Fix copy constructor in template classes: using This.

release/4.3a0
Duy-Nguyen Ta 2016-09-12 18:17:47 -04:00
parent 06ab94766c
commit 6044bffd8a
5 changed files with 79 additions and 21 deletions

View File

@ -139,10 +139,15 @@ void Constructor::emit_cython_pxd(FileWriter& pxdFile, Str className) const {
for (size_t i = 0; i < nrOverloads(); i++) {
ArgumentList args = argumentList(i);
// ignore copy constructor, it's generated by default above
// ignore copy constructor, it's generated above by default
if (args.size() == 1 && args[0].is_const && args[0].is_ref &&
!args[0].is_ptr && args[0].type.cythonClass() == className)
continue;
!args[0].is_ptr) {
cout << args[0].type.cythonClass() << " vs " << className << endl;
if (args[0].type.cythonClass() == className ||
args[0].type.cythonClass() == "This")
continue;
}
// generate the constructor
pxdFile.oss << "\t\t" << className << "(";
args.emit_cython_pxd(pxdFile, className);

View File

@ -64,6 +64,13 @@ static void handle_possible_template(vector<Class>& classes,
}
}
static void push_typedef_pair(vector<TypedefPair>& typedefs,
const Qualified& oldType,
const Qualified& newType,
const string& includeFile) {
typedefs.push_back(TypedefPair(oldType, newType, includeFile));
}
/* ************************************************************************* */
Module::Module(const std::string& moduleName, bool enable_verbose)
: name(moduleName), verbose(enable_verbose)
@ -130,7 +137,17 @@ void Module::parseMarkup(const std::string& data) {
[assign_a(singleInstantiation.namespaces_, namespaces)]
[push_back_a(templateInstantiationTypedefs, singleInstantiation)]
[assign_a(singleInstantiation, singleInstantiation0)];
Qualified oldType, newType;
TypeGrammar typedefOldClass_g(oldType), typedefNewClass_g(newType);
Rule typedef_p =
(str_p("typedef") >> typedefOldClass_g >> typedefNewClass_g >>
';')
[assign_a(oldType.namespaces_, namespaces)]
[assign_a(newType.namespaces_, namespaces)]
[bl::bind(&push_typedef_pair, bl::var(typedefs), bl::var(oldType),
bl::var(newType), bl::var(currentInclude))];
// Create grammar for global functions
GlobalFunctionGrammar global_function_g(global_functions,namespaces);
@ -148,7 +165,7 @@ void Module::parseMarkup(const std::string& data) {
(str_p("namespace")
>> basic.namespace_p[push_back_a(namespaces)]
>> ch_p('{')
>> *(include_p | class_p | templateSingleInstantiation_p | global_function_g | namespace_def_p | basic.comments_p)
>> *(include_p | class_p | templateSingleInstantiation_p | typedef_p | global_function_g | namespace_def_p | basic.comments_p)
>> ch_p('}'))
[pop_a(namespaces)];
@ -323,11 +340,15 @@ void Module::emit_cython_pxd(FileWriter& pxdFile) const {
"\t\tT* get()\n"
"\t\tT& operator*()\n\n";
for(const TypedefPair& types: typedefs)
types.emit_cython_pxd(pxdFile);
//... wrap all classes
for(const Class& cls: uninstantiatedClasses)
cls.emit_cython_pxd(pxdFile, uninstantiatedClasses);
//... ctypedef for template instantiations
// TODO: put them in the correct place!
// TODO: put them in the correct place!!!
for(const Class& cls: expandedClasses) {
if (cls.templateClass) {
pxdFile.oss << "ctypedef " << cls.templateClass->cythonClass() << "[";

View File

@ -22,6 +22,7 @@
#include "GlobalFunction.h"
#include "TemplateInstantiationTypedef.h"
#include "ForwardDeclaration.h"
#include "TypedefPair.h"
#include <string>
#include <vector>
@ -43,6 +44,7 @@ struct Module {
std::vector<ForwardDeclaration> forward_declarations;
std::vector<std::string> includes; ///< Include statements
GlobalFunctions global_functions;
std::vector<TypedefPair> typedefs;
// After parsing:
std::vector<Class> expandedClasses;

22
wrap/TypedefPair.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include "Qualified.h"
namespace wrap {
struct TypedefPair {
Qualified oldType, newType;
std::string includeFile;
TypedefPair() {}
TypedefPair(const Qualified& oldType, const Qualified& newType,
const std::string& includeFile)
: oldType(oldType), newType(newType), includeFile(includeFile) {}
void emit_cython_pxd(FileWriter& file) const {
file.oss << "cdef extern from \"" << includeFile << "\" namespace \""
<< oldType.qualifiedNamespaces("::") << "\":\n";
file.oss << "\tctypedef " << oldType.cythonClass() << " "
<< newType.cythonClass() << "\n";
}
};
}

View File

@ -1,16 +1,23 @@
namespace gtsam {
#include <gtsam/inference/Key.h>
typedef size_t Key;
#include <gtsam/base/FastVector.h>
template<T> class FastVector{};
typedef gtsam::FastVector<size_t> KeyVector;
template<T> class FastVector {
FastVector();
FastVector(const This& f);
};
typedef gtsam::FastVector<gtsam::Key> KeyVector;
#include <gtsam/base/FastList.h>
template<T> class FastList{};
typedef gtsam::FastList<size_t> KeyList;
typedef gtsam::FastList<gtsam::Key> KeyList;
#include <gtsam/base/FastSet.h>
template<T> class FastSet{};
typedef gtsam::FastSet<size_t> KeySet;
typedef gtsam::FastSet<gtsam::Key> KeySet;
#include <gtsam/base/FastMap.h>
template<K,V> class FastMap{};
@ -687,6 +694,7 @@ template<CALIBRATION>
class PinholeCamera {
// Standard Constructors and Named Constructors
PinholeCamera();
PinholeCamera(const This& cam);
PinholeCamera(const gtsam::Pose3& pose);
PinholeCamera(const gtsam::Pose3& pose, const CALIBRATION& K);
static This Level(const CALIBRATION& K, const gtsam::Pose2& pose, double height);
@ -843,13 +851,13 @@ virtual class SymbolicFactor {
SymbolicFactor(size_t j1, size_t j2, size_t j3, size_t j4);
SymbolicFactor(size_t j1, size_t j2, size_t j3, size_t j4, size_t j5);
SymbolicFactor(size_t j1, size_t j2, size_t j3, size_t j4, size_t j5, size_t j6);
// static gtsam::SymbolicFactor FromKeys(const gtsam::KeyVector& js);
static gtsam::SymbolicFactor FromKeys(const gtsam::KeyVector& js);
// From Factor
size_t size() const;
void print(string s) const;
bool equals(const gtsam::SymbolicFactor& other, double tol) const;
// gtsam::KeyVector keys();
gtsam::KeyVector keys();
};
#include <gtsam/symbolic/SymbolicFactorGraph.h>
@ -884,19 +892,19 @@ virtual class SymbolicFactorGraph {
gtsam::SymbolicBayesTree* eliminateMultifrontal(const gtsam::Ordering& ordering);
pair<gtsam::SymbolicBayesNet*, gtsam::SymbolicFactorGraph*> eliminatePartialSequential(
const gtsam::Ordering& ordering);
// pair<gtsam::SymbolicBayesNet*, gtsam::SymbolicFactorGraph*> eliminatePartialSequential(
// const gtsam::KeyVector& keys);
pair<gtsam::SymbolicBayesNet*, gtsam::SymbolicFactorGraph*> eliminatePartialSequential(
const gtsam::KeyVector& keys);
pair<gtsam::SymbolicBayesTree*, gtsam::SymbolicFactorGraph*> eliminatePartialMultifrontal(
const gtsam::Ordering& ordering);
// pair<gtsam::SymbolicBayesTree*, gtsam::SymbolicFactorGraph*> eliminatePartialMultifrontal(
// const gtsam::KeyVector& keys);
pair<gtsam::SymbolicBayesTree*, gtsam::SymbolicFactorGraph*> eliminatePartialMultifrontal(
const gtsam::KeyVector& keys);
gtsam::SymbolicBayesNet* marginalMultifrontalBayesNet(const gtsam::Ordering& variables);
// gtsam::SymbolicBayesNet* marginalMultifrontalBayesNet(const gtsam::KeyVector& variables);
gtsam::SymbolicBayesNet* marginalMultifrontalBayesNet(const gtsam::KeyVector& variables);
gtsam::SymbolicBayesNet* marginalMultifrontalBayesNet(const gtsam::Ordering& variables,
const gtsam::Ordering& marginalizedVariableOrdering);
// gtsam::SymbolicBayesNet* marginalMultifrontalBayesNet(const gtsam::KeyVector& variables,
// const gtsam::Ordering& marginalizedVariableOrdering);
// gtsam::SymbolicFactorGraph* marginal(const gtsam::KeyVector& variables);
gtsam::SymbolicBayesNet* marginalMultifrontalBayesNet(const gtsam::KeyVector& variables,
const gtsam::Ordering& marginalizedVariableOrdering);
gtsam::SymbolicFactorGraph* marginal(const gtsam::KeyVector& variables);
};
#include <gtsam/symbolic/SymbolicConditional.h>
@ -908,7 +916,7 @@ virtual class SymbolicConditional : gtsam::SymbolicFactor {
SymbolicConditional(size_t key, size_t parent);
SymbolicConditional(size_t key, size_t parent1, size_t parent2);
SymbolicConditional(size_t key, size_t parent1, size_t parent2, size_t parent3);
// static gtsam::SymbolicConditional FromKeys(const gtsam::KeyVector& keys, size_t nrFrontals);
static gtsam::SymbolicConditional FromKeys(const gtsam::KeyVector& keys, size_t nrFrontals);
// Testable
void print(string s) const;