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

WIP: maoxdb library

parent eac9eb96
No related branches found
No related tags found
1 merge request!1Initial functionality
Pipeline #11086 failed
......@@ -34,8 +34,7 @@ doc:
cd doc && $(MAKE) html
style:
# Disabled until https://github.com/florianschanda/miss_hit/issues/224 is resolved.
# mh_style --fix --octave src doc
mh_style --fix --octave src doc
clang-format-11 --dry-run --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in")
.PHONY: style
......
......@@ -5,7 +5,8 @@
This package requires the following software:
- conan: `pip install conan`
- libcaosdb: See https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib for further instructions.
- libcaosdb installed with Conan: See https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib for
further instructions.
- For running this library, a valid libcaosdb configuration is needed, for example a
`.caosdb_client.json` file in your home directory or current working directory. Please look at
[`README_SETUP.md` in caosdb-cpplib](https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib/-/blob/main/README_SETUP.md) for more information.
......@@ -50,4 +51,3 @@ static website. If you rather would like to use the native,
- `sphinx`
- `sphinx-autoapi`
- `recommonmark`
[requires]
caosdb/0.0.5
caosdb/0.0.6
[generators]
cmake
......@@ -17,11 +17,12 @@ classdef caosdbClass < handle
function res = info(obj)
disp(["connection: >", obj.connection, "<"]);
try
info_result = _info(obj.connection);
info_result = maox_info(obj.connection);
res = info_result;
catch
disp("some error!")
res = NA
disp(lasterror())
res = NA;
end_try_catch
endfunction
endmethods
......
/*
* ** header v3.0
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
* Copyright (C) 2021 Daniel Hornung <d.hornung@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ** end header
*/
/**
* Mostly utility functions for MEX files interacting with libcaosdb.
*/
#include "maoxdb.hpp"
#include "caosdb/status_code.h"
namespace maoxdb {
using std::string;
/**
* Extract useful strings from an Exception: ID and description.
*/
std::pair<string, string> exceptionToMessage(const caosdb::exceptions::Exception &exc) {
string id = std::to_string(exc.GetCode());
string text = caosdb::get_status_description(exc.GetCode()) + "\n" + exc.what();
return std::pair<string, string>(id, text);
}
/**
* Just throw the error.
*/
void throwOctException(const caosdb::exceptions::Exception &exc) {
std::pair<string, string> excContent = exceptionToMessage(exc);
mexErrMsgIdAndTxt(excContent.first, excContent.second);
}
}
#ifndef MAOXDB_H
#define MAOXDB_H
#include "caosdb/exceptions.h"
#include "caosdb/status_code.h"
#include "mex.h"
#include "mexproto.h"
#include <string>
// Macros /////////////////////////////////////////////////////////////////////
......@@ -21,6 +24,7 @@
* scalar_data[0] = value;
* mxSetData(scalar, scalar_data);
*
* TODO: This macro could be rewritten as a function now.
*/
#define mxSCALAR(type, name, value) \
mxCreateNumericMatrix(1, 1, mx##type##_CLASS, mxREAL); \
......@@ -29,7 +33,37 @@
mxSetData(name, __##name##_data)
// Utility functions //////////////////////////////////////////////////////////
namespace maoxdb {
using std::string;
// doxy
void test();
/**
* @brief Handle a CaosDB Exception and transform into error code and message.
*
* @details This function does all the processing to transform the information in an Exception
* object into a form that can conveniently be handled by Octave via the mexErrMsgIdAndTxt function.
*
* @param exc The Exception object.
*
* @return pair<string msgId, string msgText> The message ID and message text which can be passed to
* Octave.
*/
std::pair<string, string> exceptionToMessage(const caosdb::exceptions::Exception &exc);
/**
* @brief Throw a CaosDB Exception inside Octave.
*
* @details This function does all the processing to transform the information in an Exception
* object into a form that is accepted by Octave's error handling.d
*
* Internally, this function uses the exceptionToMessage function.
*
* @param exc The Exception object.
*/
void throwOctException(const caosdb::exceptions::Exception &exc);
} // maoxdb
#endif /* MAOXDB_H */
......@@ -2,7 +2,11 @@
#include "mex.h"
#include "mexproto.h"
namespace maoxdb {
void test() {
// do nothing.
auto *mx_str = mxCreateString("Hello World!");
}
} // maoxdb
File moved
......@@ -64,9 +64,8 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
try {
auto info_struct = info(conn_name);
plhs[0] = info_struct;
} catch (const std::runtime_error &err) {
} catch (const caosdb::exceptions::Exception &exc) {
mexPrintf("Some exception!");
mexErrMsgIdAndTxt("someID", err.what());
maoxdb::throwOctException(exc);
}
test();
}
......@@ -7,4 +7,4 @@ function test_suite=test_caosdb
function test_print_version
v = caosdb("--version")
assertEqual(v, "v0.1 (libcaosdb v0.0.5)")
assertEqual(v, "v0.1 (libcaosdb v0.0.6)")
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