gtsam/wrap/ReturnValue.h

90 lines
1.9 KiB
C
Raw Normal View History

/**
* @file ReturnValue.h
*
* @brief Encapsulates a return value from a method
*
* @date Dec 1, 2011
* @author Alex Cunningham
2012-07-13 06:28:28 +08:00
* @author Richard Roberts
*/
2014-11-12 21:37:08 +08:00
#include "Qualified.h"
#include "FileWriter.h"
2012-07-13 06:28:28 +08:00
#include "TypeAttributesTable.h"
2014-11-12 21:37:08 +08:00
#include "utilities.h"
2014-05-26 01:29:06 +08:00
#pragma once
namespace wrap {
2014-05-26 02:40:39 +08:00
/**
* Encapsulates return value of a method or function
*/
struct ReturnType: Qualified {
2014-11-12 20:31:46 +08:00
2014-05-26 02:40:39 +08:00
/// the different supported return value categories
typedef enum {
2014-05-26 01:29:06 +08:00
CLASS = 1, EIGEN = 2, BASIS = 3, VOID = 4
} return_category;
2014-11-12 20:31:46 +08:00
bool isPtr;
return_category category;
2014-11-12 21:37:08 +08:00
ReturnType() :
isPtr(false), category(CLASS) {
2014-11-12 21:37:08 +08:00
}
ReturnType(const Qualified& q) :
Qualified(q), isPtr(false), category(CLASS) {
2014-11-12 21:37:08 +08:00
}
/// Check if this type is in a set of valid types
template<class TYPES>
2014-11-12 21:37:08 +08:00
void verify(TYPES validtypes, const std::string& s) const {
std::string key = qualifiedName("::");
if (find(validtypes.begin(), validtypes.end(), key) == validtypes.end())
throw DependencyMissing(key, s);
}
private:
friend struct ReturnValue;
std::string str(bool add_ptr) const;
/// Example: out[1] = wrap_shared_ptr(pairResult.second,"Test", false);
void wrap_result(const std::string& out, const std::string& result,
FileWriter& file, const TypeAttributesTable& typeAttributes) const;
/// Creates typedef
void wrapTypeUnwrap(FileWriter& wrapperFile) const;
2014-11-12 20:31:46 +08:00
};
/**
* Encapsulates return value of a method or function, possibly a pair
*/
struct ReturnValue {
bool isPair;
ReturnType type1, type2;
2014-05-26 02:40:39 +08:00
/// Constructor
ReturnValue() :
isPair(false) {
2014-05-26 02:40:39 +08:00
}
2014-11-12 21:37:08 +08:00
std::string return_type(bool add_ptr) const;
std::string matlab_returnType() const;
2014-05-26 01:29:06 +08:00
void wrap_result(const std::string& result, FileWriter& file,
const TypeAttributesTable& typeAttributes) const;
void wrapTypeUnwrap(FileWriter& wrapperFile) const;
2012-07-24 02:24:39 +08:00
void emit_matlab(FileWriter& file) const;
};
} // \namespace wrap