Skip to content
Snippets Groups Projects
Commit eac9eb96 authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Exceptions and a utilty C++ library build now.

- No generalized exception handling yet.
- The library has virtually no content yet (only moved the hpp file over).
parent 3c5ce6e4
No related branches found
No related tags found
1 merge request!1Initial functionality
Pipeline #10968 failed
......@@ -53,26 +53,48 @@ if(AUTOFORMATTING)
endif()
#######################################################
### Build utility library
#######################################################
# The library will be called maoxdb until we find a better name. The name is not very important
# though, since the library is used only internally.
execute_process(COMMAND mkoctfile -p OCTINCLUDEDIR
OUTPUT_VARIABLE OCTINCLUDEDIR
)
string(REGEX REPLACE "\n" "" OCTINCLUDEDIR "${OCTINCLUDEDIR}")
set(MAOXDB_DIR "${PROJECT_SOURCE_DIR}/src/lib")
add_library(maoxdb STATIC "${MAOXDB_DIR}/test.cpp")
set_target_properties(maoxdb PROPERTIES PUBLIC_HEADER "${MAOXDB_DIR}/maoxdb.hpp")
message(STATUS "-----\n${FLAGS_MEX_I}")
target_compile_options(maoxdb PRIVATE "-I${OCTINCLUDEDIR}")
#######################################################
### Compile into *.mex files
#######################################################
# Only files in src/private will be compiled. This is to separate the non-mex files in src/lib; if
# this is to change, the GLOB_RECURSE code needs to be changed.
add_subdirectory(src)
set(PKG_INST_DIR "${PROJECT_SOURCE_DIR}/inst")
file(MAKE_DIRECTORY ${PKG_INST_DIR})
# Options for mex compilation
string(REGEX REPLACE ";" ";-I" _MKOCTFILE_INCLUDES "-I${CONAN_INCLUDE_DIRS}")
string(REGEX REPLACE ";" ";-L" _MKOCTFILE_LIB_DIRS "-L${CONAN_LIB_DIRS}")
string(REGEX REPLACE ";" ";-I" _MKOCTFILE_INCLUDES "-I${CONAN_INCLUDE_DIRS};${MAOXDB_DIR}")
string(REGEX REPLACE ";" ";-L" _MKOCTFILE_LIB_DIRS "-L${CONAN_LIB_DIRS};-L;${MAOXDB_DIR}")
string(REGEX REPLACE ";" ";-l" _MKOCTFILE_LIBS "-l${CONAN_LIBS}")
string(REGEX REPLACE ";" ":" _MKOCTFILE_RPATH "${CONAN_LIB_DIRS}")
set(_MKOCTFILE_OPTIONS "-Wl,-rpath,${_MKOCTFILE_RPATH}" "--mex" "-std=gnu++17"
"-L/usr/local/lib" ${_MKOCTFILE_INCLUDES} ${_MKOCTFILE_LIB_DIRS} ${_MKOCTFILE_LIBS})
add_custom_target(mex ALL)
file(GLOB_RECURSE _CPP_SOURCES RELATIVE "${PROJECT_SOURCE_DIR}/src" src/*.cpp)
add_custom_target(mex ALL
DEPENDS maoxdb)
file(GLOB_RECURSE _CPP_SOURCES RELATIVE "${PROJECT_SOURCE_DIR}/src" src/private/*.cpp)
foreach(sourcefile ${_CPP_SOURCES})
string(REGEX REPLACE ".cpp$" ".mex" _mex_ext_file ${sourcefile})
STRING(REGEX REPLACE "/" "__" _target_name "${sourcefile}")
string(REGEX REPLACE "/" "__" _target_name "${sourcefile}")
set(_mex_ext_file "${PKG_INST_DIR}/${_mex_ext_file}")
set(_mkoct_output "-o" "${_mex_ext_file}")
set(_abs_source "${PROJECT_SOURCE_DIR}/src/${sourcefile}")
......@@ -91,11 +113,6 @@ endforeach(sourcefile)
#######################################################
option(LINTING "clang-tidy and iwyu" OFF)
if(LINTING)
execute_process(COMMAND mkoctfile -p OCTINCLUDEDIR
OUTPUT_VARIABLE _OCTINCLUDEDIR
)
string(REGEX REPLACE "\n" "" _OCTINCLUDEDIR "${_OCTINCLUDEDIR}")
find_program(clang_tidy NAMES clang-tidy clang-tidy-11)
if(NOT clang_tidy)
message(WARNING "clang-tidy: Not found")
......@@ -113,7 +130,7 @@ if(LINTING)
COMMAND ${clang_tidy}
ARGS ${_CMAKE_CXX_CLANG_TIDY} ${_CMAKE_CXX_CLANG_TIDY_CHECKS}
${OCTAVE_CAOSDB_SRC} "--" ${_MKOCTFILE_INCLUDES} "-I/usr/include"
"-I${_OCTINCLUDEDIR}" "-std=c++17"
"-I${OCTINCLUDEDIR}" "-std=c++17"
DEPENDS ${OCTAVE_CAOSDB_SRC})
endif()
......@@ -131,7 +148,7 @@ if(LINTING)
add_custom_command(
TARGET caosdb.mex
COMMAND ${iwyu}
ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${_OCTINCLUDEDIR}"
ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${OCTINCLUDEDIR}"
"-std=c++17" "-I/usr/include" ${_MKOCTFILE_INCLUDES}
${OCTAVE_CAOSDB_SRC} "||" "true"
DEPENDS ${OCTAVE_CAOSDB_SRC})
......
......@@ -16,8 +16,13 @@ classdef caosdbClass < handle
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function res = info(obj)
disp(["connection: >", obj.connection, "<"]);
info_result = _info(obj.connection);
res = info_result;
try
info_result = _info(obj.connection);
res = info_result;
catch
disp("some error!")
res = NA
end_try_catch
endfunction
endmethods
endclassdef
#ifndef MAOXDBUTILS_H
#define MAOXDBUTILS_H
#ifndef MAOXDB_H
#define MAOXDB_H
#include "mex.h"
#include "mexproto.h"
// Macros /////////////////////////////////////////////////////////////////////
/**
* mxSCALAR(type, name, value): Create a 1x1 mxArray of type TYPE and value
* VALUE. The NAME must be unique within each scope.
......@@ -26,4 +28,8 @@
__##name##_data[0] = value; \
mxSetData(name, __##name##_data)
#endif /* MAOXDBUTILS_H */
// Utility functions //////////////////////////////////////////////////////////
void test();
#endif /* MAOXDB_H */
#include "maoxdb.hpp"
#include "mex.h"
#include "mexproto.h"
void test() {
// do nothing.
auto *mx_str = mxCreateString("Hello World!");
}
#include "caosdb/connection.h" // for Connection, ConnectionManager
#include "caosdb/constants.h" // for LIBCAOSDB_VERSION_MAJOR, LIBCAOSDB_VE...
#include "caosdb/exceptions.h" // for all error handling
#include "caosdb/info.h" // for VersionInfo
#include "maoxdbUtils.hpp" // caosDB utils for mex files
#include "mex.h" // for mxArray, mexFunction
#include "mexproto.h" // for mexPrintf, mxCreateString, mxGetChars
#include <cstring> // for strcmp
#include <memory> // for unique_ptr, __shared_ptr_access, shar...
#include <string> // for allocator, char_traits, operator+
#include "maoxdb.hpp" // caosDB utils for mex files
using caosdb::connection::Connection;
using caosdb::connection::ConnectionManager;
......@@ -60,6 +61,12 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
conn_name = mxGetChars(prhs[0]);
}
mexPrintf("Connection: >%s< \t %d\n", conn_name.c_str(), nrhs);
auto info_struct = info(conn_name);
plhs[0] = info_struct;
try {
auto info_struct = info(conn_name);
plhs[0] = info_struct;
} catch (const std::runtime_error &err) {
mexPrintf("Some exception!");
mexErrMsgIdAndTxt("someID", err.what());
}
test();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment