Added missing files from last commit - code cleanup and comments
parent
ce12f3d255
commit
7f63d23565
|
@ -0,0 +1,32 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* 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 Class.h
|
||||
* @brief describe the C++ class that is being wrapped
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace wrap {
|
||||
|
||||
struct ForwardDeclaration {
|
||||
std::string name;
|
||||
bool isVirtual;
|
||||
ForwardDeclaration() : isVirtual(false) {}
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* 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 Class.cpp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include "TemplateInstantiationTypedef.h"
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace wrap {
|
||||
|
||||
Class TemplateInstantiationTypedef::findAndExpand(const vector<Class>& classes) const {
|
||||
// Find matching class
|
||||
std::vector<Class>::const_iterator clsIt = classes.end();
|
||||
for(std::vector<Class>::const_iterator it = classes.begin(); it != classes.end(); ++it) {
|
||||
if(it->name == className && it->namespaces == classNamespaces && it->templateArgs.size() == typeList.size()) {
|
||||
clsIt = it;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(clsIt == classes.end())
|
||||
throw DependencyMissing(wrap::qualifiedName("::", classNamespaces, className),
|
||||
"instantiation into typedef name " + wrap::qualifiedName("::", namespaces, name) +
|
||||
". Ensure that the typedef provides the correct number of template arguments.");
|
||||
|
||||
// Instantiate it
|
||||
Class classInst = *clsIt;
|
||||
for(size_t i = 0; i < typeList.size(); ++i)
|
||||
classInst = classInst.expandTemplate(classInst.templateArgs[i], typeList[i]);
|
||||
|
||||
// Fix class properties
|
||||
classInst.name = name;
|
||||
classInst.templateArgs.clear();
|
||||
classInst.typedefName = clsIt->qualifiedName("::") + "<";
|
||||
if(typeList.size() > 0)
|
||||
classInst.typedefName += wrap::qualifiedName("::", typeList[0]);
|
||||
for(size_t i = 1; i < typeList.size(); ++i)
|
||||
classInst.typedefName += (", " + wrap::qualifiedName("::", typeList[i]));
|
||||
classInst.typedefName += ">";
|
||||
classInst.namespaces = namespaces;
|
||||
|
||||
return classInst;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* 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 Class.h
|
||||
* @brief describe the C++ class that is being wrapped
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "Class.h"
|
||||
|
||||
namespace wrap {
|
||||
|
||||
struct TemplateInstantiationTypedef {
|
||||
std::vector<std::string> classNamespaces;
|
||||
std::string className;
|
||||
std::vector<std::string> namespaces;
|
||||
std::string name;
|
||||
std::vector<std::vector<std::string> > typeList;
|
||||
|
||||
Class findAndExpand(const std::vector<Class>& classes) const;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* 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 Class.cpp
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include "TypeAttributesTable.h"
|
||||
#include "Class.h"
|
||||
#include "utilities.h"
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace wrap {
|
||||
|
||||
/* ************************************************************************* */
|
||||
void TypeAttributesTable::addClasses(const vector<Class>& classes) {
|
||||
BOOST_FOREACH(const Class& cls, classes) {
|
||||
if(!insert(make_pair(cls.qualifiedName("::"), TypeAttributes(cls.isVirtual))).second)
|
||||
throw DuplicateDefinition("class " + cls.qualifiedName("::"));
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void TypeAttributesTable::addForwardDeclarations(const vector<ForwardDeclaration>& forwardDecls) {
|
||||
BOOST_FOREACH(const ForwardDeclaration& fwDec, forwardDecls) {
|
||||
if(!insert(make_pair(fwDec.name, TypeAttributes(fwDec.isVirtual))).second)
|
||||
throw DuplicateDefinition("class " + fwDec.name);
|
||||
}
|
||||
}
|
||||
|
||||
/* ************************************************************************* */
|
||||
void TypeAttributesTable::checkValidity(const vector<Class>& classes) const {
|
||||
BOOST_FOREACH(const Class& cls, classes) {
|
||||
// Check that class is virtual if it has a parent
|
||||
if(!cls.qualifiedParent.empty() && !cls.isVirtual)
|
||||
throw AttributeError(cls.qualifiedName("::"), "Has a base class so needs to be declared virtual, change to 'virtual class "+cls.name+" ...'");
|
||||
// Check that parent is virtual as well
|
||||
if(!cls.qualifiedParent.empty() && !at(wrap::qualifiedName("::", cls.qualifiedParent)).isVirtual)
|
||||
throw AttributeError(wrap::qualifiedName("::", cls.qualifiedParent),
|
||||
"Is the base class of " + cls.qualifiedName("::") + ", so needs to be declared virtual");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* 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 Class.h
|
||||
* @brief describe the C++ class that is being wrapped
|
||||
* @author Frank Dellaert
|
||||
* @author Andrew Melim
|
||||
* @author Richard Roberts
|
||||
**/
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "ForwardDeclaration.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace wrap {
|
||||
|
||||
// Forward declarations
|
||||
struct Class;
|
||||
|
||||
/** Attributes about valid classes, both for classes defined in this module and
|
||||
* also those forward-declared from others. At the moment this only contains
|
||||
* whether the class is virtual, which is used to know how to copy the class,
|
||||
* and whether to try to convert it to a more derived type upon returning it.
|
||||
*/
|
||||
struct TypeAttributes {
|
||||
bool isVirtual;
|
||||
TypeAttributes() : isVirtual(false) {}
|
||||
TypeAttributes(bool isVirtual) : isVirtual(isVirtual) {}
|
||||
};
|
||||
|
||||
/** Map of type names to attributes. */
|
||||
class TypeAttributesTable : public std::map<std::string, TypeAttributes> {
|
||||
public:
|
||||
TypeAttributesTable() {}
|
||||
|
||||
void addClasses(const std::vector<Class>& classes);
|
||||
void addForwardDeclarations(const std::vector<ForwardDeclaration>& forwardDecls);
|
||||
|
||||
void checkValidity(const std::vector<Class>& classes) const;
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue