-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from diegoferigo/WB3.0
WB-Toolbox 3.0
- Loading branch information
Showing
98 changed files
with
8,889 additions
and
11,821 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
cmake_policy(SET CMP0048 NEW) | ||
project(MxAnyType LANGUAGES CXX VERSION 0.1) | ||
cmake_minimum_required(VERSION 3.0.2) | ||
|
||
# Configure the project | ||
# ===================== | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
include(GNUInstallDirs) | ||
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) | ||
|
||
# Use a general prefix for the project | ||
set(VARS_PREFIX ${PROJECT_NAME}) | ||
# set(VARS_PREFIX "MxAnyType") | ||
|
||
# Build the library | ||
# ================= | ||
|
||
# Export the includes needed to who inherits this library | ||
# Set this up properly for handling either BUILD and INSTALL trees | ||
set(${VARS_PREFIX}_INCLUDE_BUILD ${CMAKE_CURRENT_SOURCE_DIR}/include) | ||
set(${VARS_PREFIX}_INCLUDE_INSTALL ${CMAKE_INSTALL_INCLUDEDIR}/${VARS_PREFIX}) | ||
|
||
# Add the target | ||
add_library(${VARS_PREFIX} STATIC ${CMAKE_CURRENT_SOURCE_DIR}/include/AnyType.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/include/MxAnyType.h | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/MxAnyType.cpp) | ||
|
||
|
||
# TODO: temporary, waiting the library becomes a shared | ||
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64") | ||
set_target_properties(${VARS_PREFIX} PROPERTIES COMPILE_FLAGS "-fPIC") | ||
endif() | ||
|
||
# Find Matlab resources | ||
find_package(Matlab REQUIRED MX_LIBRARY) | ||
target_include_directories(${VARS_PREFIX} SYSTEM PUBLIC "${Matlab_INCLUDE_DIRS}") | ||
|
||
# Setup the include directories | ||
# TODO why in the how to was INTERFACE? | ||
target_include_directories(${VARS_PREFIX} PUBLIC | ||
$<BUILD_INTERFACE:${${VARS_PREFIX}_INCLUDE_BUILD}> | ||
$<INSTALL_INTERFACE:${${VARS_PREFIX}_INCLUDE_INSTALL}>) | ||
|
||
# Assign some useful properties | ||
# set_target_properties(${VARS_PREFIX} PROPERTIES VERSION ${PROJECT_VERSION} | ||
# PUBLIC_HEADER MxAnyType.h) | ||
|
||
# Build tests | ||
# =========== | ||
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#ifndef ANYTYPE_H | ||
#define ANYTYPE_H | ||
|
||
#include <vector> | ||
#include <unordered_map> | ||
#include <memory> | ||
|
||
class AnyType; | ||
|
||
typedef std::shared_ptr<AnyType> AnyTypeSPtr; | ||
typedef std::vector<AnyTypeSPtr> AnyCell; | ||
typedef std::unordered_map<std::string, AnyTypeSPtr> AnyStruct; | ||
|
||
class AnyType | ||
{ | ||
protected: | ||
|
||
public: | ||
AnyType() = default; | ||
virtual ~AnyType() = default; | ||
|
||
// Integers | ||
virtual bool asInt(int& i) = 0; | ||
// virtual bool asInt8(int8_t& i) = 0; | ||
// virtual bool asInt16(int16_t& i) = 0; | ||
virtual bool asInt32(int32_t& i) = 0; | ||
// virtual bool asInt64(int64_t& i) = 0; | ||
|
||
// Unsigned Integers | ||
virtual bool asUInt(unsigned& i) = 0; | ||
// virtual bool asUInt8(uint8_t& i) = 0; | ||
// virtual bool asUInt16(uint16_t& i) = 0; | ||
// virtual bool asUInt32(uint32_t& i) = 0; | ||
// virtual bool asUInt64(uint64_t& i) = 0; | ||
|
||
// Boolean | ||
virtual bool asBool(bool& b) = 0; | ||
|
||
// Floating-point | ||
// virtual bool asFloat(float& f) = 0; | ||
virtual bool asDouble(double& d) = 0; | ||
|
||
// Characters | ||
virtual bool asString(std::string& s) = 0; | ||
|
||
// Struct | ||
virtual bool asAnyStruct(AnyStruct& map) = 0; | ||
|
||
// Cell array | ||
virtual bool asAnyCell(AnyCell& map) = 0; | ||
|
||
// Matrix | ||
// TODO: constraint max 2-dimension | ||
// virtual bool asMatrixFloat(Eigen::MatrixXf mat) = 0; | ||
// virtual bool asMatrixDouble(Eigen::MatrixXd mat) = 0; | ||
|
||
// Vector | ||
virtual bool asVectorDouble(std::vector<double>& vec) = 0; | ||
}; | ||
|
||
#endif /* ANYTYPE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#ifndef MXANYTYPE_H | ||
#define MXANYTYPE_H | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <unordered_map> | ||
#include <cassert> | ||
#include "AnyType.h" | ||
#include "matrix.h" | ||
|
||
class MxAnyType; | ||
|
||
// If needed in the future | ||
// class MxAnyCell : public AnyCell {}; | ||
// class MxAnyStruct : public AnyStruct {}; | ||
|
||
struct MxArrayMetadata { | ||
mxClassID id; | ||
bool isScalar; | ||
size_t rows; | ||
size_t cols; | ||
size_t nElem; | ||
size_t nDims; | ||
std::vector<size_t> dims; | ||
}; | ||
|
||
class MxAnyType : public AnyType | ||
{ | ||
private: | ||
const mxArray* mx; | ||
MxArrayMetadata md; | ||
bool validate; | ||
|
||
// TODO: https://it.mathworks.com/help/matlab/apiref/mxgetscalar.html returns a double always | ||
bool asScalar(double& d); | ||
bool validateClassId(mxClassID id1, mxClassID id2); | ||
|
||
// mxArray* getMxArrayPtr() const { return static_cast<mxArray*>(getAnyDataPtr()); } | ||
|
||
public: | ||
// void* getAnyDataPtr() const override { | ||
// return (void*) mx; | ||
// } | ||
|
||
MxAnyType(); | ||
MxAnyType(const mxArray* m, bool validateId = false); | ||
~MxAnyType() = default; | ||
MxAnyType(const MxAnyType& mxAnyType); | ||
|
||
void enableClassIDValidation(); | ||
|
||
// STRING / CHARS | ||
// ============== | ||
|
||
bool asString(std::string& s) override; | ||
|
||
// SCALAR TYPES | ||
// ============ | ||
|
||
// Generic casting | ||
// --------------- | ||
|
||
bool asInt(int& i) override; | ||
bool asUInt(unsigned& i) override; | ||
|
||
// Specific casting | ||
// ---------------- | ||
|
||
bool asInt32(int32_t& i) override; | ||
|
||
// TODO: complete with all the other scalar types | ||
// bool asInt64(int64_t& i) override | ||
// { | ||
// double buffer; | ||
// if (!asScalar(buffer)) return false; | ||
// i = static_cast<int64_t>(buffer); | ||
// return validateClassId(md.id, mxINT64_CLASS); | ||
// } | ||
|
||
bool asDouble(double& d) override; | ||
bool asBool(bool& b) override; | ||
|
||
// COMPOSITE DATA TYPES | ||
// ==================== | ||
|
||
bool asAnyStruct(AnyStruct& s) override; | ||
bool asAnyCell(AnyCell& cell) override; | ||
|
||
// MATRIX | ||
// ====== | ||
|
||
// VECTOR | ||
// ====== | ||
|
||
bool asVectorDouble(std::vector<double>& vec) override; | ||
}; | ||
|
||
#endif /* MXANYTYPE_H */ |
Oops, something went wrong.