gtsam/wrap/Constructor.h

100 lines
2.8 KiB
C
Raw Normal View History

/* ----------------------------------------------------------------------------
2019-02-11 22:39:48 +08:00
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
* Atlanta, Georgia 30332-0415
* All Rights Reserved
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
* See LICENSE for the license information
* -------------------------------------------------------------------------- */
/**
* @file Constructor.h
* @brief class describing a constructor + code generation
* @author Frank Dellaert
2012-07-13 06:28:28 +08:00
* @author Richard Roberts
**/
#pragma once
#include "OverloadedFunction.h"
#include <boost/optional.hpp>
#include <string>
2011-12-09 23:44:35 +08:00
#include <vector>
namespace wrap {
// Forward declaration
class Class;
// Constructor class
struct Constructor: public OverloadedFunction {
2014-11-15 00:47:25 +08:00
typedef const std::string& Str;
/// Constructor creates an empty class
Constructor(bool verbose = false) {
verbose_ = verbose;
}
Constructor expandTemplate(const TemplateSubstitution& ts) const {
Constructor inst = *this;
inst.argLists_ = expandArgumentListsTemplate(ts);
inst.name_ = ts.expandedClassName();
return inst;
}
/// return true if the default constructor exists
bool hasDefaultConstructor() const;
// MATLAB code generation
// toolboxPath is main toolbox directory, e.g., ../matlab
// classFile is class proxy file, e.g., ../matlab/@Point2/Point2.m
/// wrapper name
2014-11-15 00:47:25 +08:00
std::string matlab_wrapper_name(Str className) const;
void comment_fragment(FileWriter& proxyFile) const {
if (nrOverloads() > 0)
proxyFile.oss << "%\n%-------Constructors-------\n";
for (size_t i = 0; i < nrOverloads(); i++) {
proxyFile.oss << "%";
argumentList(i).emit_prototype(proxyFile, name_);
proxyFile.oss << "\n";
}
}
/**
* Create fragment to select constructor in proxy class, e.g.,
* if nargin == 2, obj.self = new_Pose3_RP(varargin{1},varargin{2}); end
*/
2014-11-15 00:47:25 +08:00
void proxy_fragment(FileWriter& file, Str wrapperName, bool hasParent,
const int id, const ArgumentList args) const;
/// cpp wrapper
2014-11-15 00:47:25 +08:00
std::string wrapper_fragment(FileWriter& file, Str cppClassName,
Str matlabUniqueName, boost::optional<std::string> cppBaseClassName, int id,
2014-05-26 01:26:14 +08:00
const ArgumentList& al) const;
/// constructor function
2014-11-15 00:47:25 +08:00
void generate_construct(FileWriter& file, Str cppClassName,
2014-05-26 01:26:14 +08:00
std::vector<ArgumentList>& args_list) const;
2014-11-15 00:47:25 +08:00
// emit python wrapper
void python_wrapper(FileWriter& wrapperFile, Str className) const;
2016-09-09 01:33:32 +08:00
// emit cython wrapper
void emit_cython_pxd(FileWriter& pxdFile, const Class& cls) const;
void emit_cython_pyx(FileWriter& pyxFile, const Class& cls) const;
2016-09-09 01:33:32 +08:00
friend std::ostream& operator<<(std::ostream& os, const Constructor& m) {
for (size_t i = 0; i < m.nrOverloads(); i++)
os << m.name_ << m.argLists_[i];
return os;
}
2014-05-26 01:26:14 +08:00
};
2012-06-27 02:52:27 +08:00
} // \namespace wrap