annoviko/pyclustering

[C++ pyclustering] pyclustering package error message support

Aperta

#592 aperta il 18 feb 2020

 (0 commenti) (0 reazioni) (0 assegnatari)Python (263 fork)auto 404
EnhancementGood First Issue

Metriche repository

Star
 (1215 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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.

Guida contributor