[C++ pyclustering] pyclustering package error message support
#592 opened on Feb 18, 2020
Repository metrics
- Stars
- (1,215 stars)
- PR merge metrics
- (PR metrics pending)
Description
Introduction
Almost all objects are returned from C++ pyclustering to python pyclustering using pyclustering_package. See files ccore/include/interface/pyclustering_package.hpp and ccore/src/interface/pyclustering_package.cpp.
Description
In order to return error message new type of data within pyclustering_package should be introduced:
PYCLUSTERING_TYPE_CHAR_PTR
And non-exported function pyclustering_package * pyclustering_pachage_from_exception(const std::exception & p_error) should be introduced. That should return pyclustering_package where void * data contains pointer char * line that should be created from p_error.what(). For example:
pyclustering_package * package = new pyclustering_package;
package.size = std::strlen(p_error) + 1;
package.type = PYCLUSTERING_TYPE_CHAR_PTR;
char * buffer = new char[package.size];
std::strcpy(buffer, p_error.what());
package.data = (void *) buffer;
The most suitable place for the function is files pyclustering_package.cpp and pyclustering_package.hpp.