This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/CXX/yapie.hh

93 lines
2.8 KiB
C++
Raw Normal View History

2017-06-12 18:00:47 +01:00
/**
2017-04-07 23:10:59 +01:00
* @file yapie.hh
2017-03-20 15:52:48 +00:00
*
2018-05-20 00:47:27 +01:00
* @defgroup yap-cplus-error-hanadlinge Error Handling in the YAP interface.
2017-03-20 15:52:48 +00:00
*
2018-05-20 00:47:27 +01:00
* @brief error handling in C++ and OO languages
2017-04-07 23:10:59 +01:00
*
2017-03-20 15:52:48 +00:00
* @ingroup yap-cplus-interface
2018-05-20 00:47:27 +01:00
*
2017-03-20 15:52:48 +00:00
*
2017-04-07 23:10:59 +01:00
* @{
2017-03-20 15:52:48 +00:00
*
* These classes define an object that we can then throw when an error
* or unexoected event interrupts YAP. Often, the object is built by
2017-04-07 23:10:59 +01:00
* YAP itself. One can also define one's own error objects.
*
* Errors will be thrown from the `C++` code, and may be processed in
2018-05-20 00:47:27 +01:00
* very different ways. The error object should provide as much data as
2017-04-07 23:10:59 +01:00
* possible.
2017-03-20 15:52:48 +00:00
*/
2014-06-30 14:34:58 +01:00
2016-09-21 20:41:23 +01:00
#ifndef YAPIE_HH
#define YAPIE_HH
2014-06-30 14:34:58 +01:00
2017-06-12 18:00:47 +01:00
class X_API YAPPPredicate;
2018-05-20 00:47:27 +01:00
2016-09-21 20:41:23 +01:00
/// take information on a Prolog error:
2017-06-12 18:00:47 +01:00
class X_API YAPError {
2016-09-23 03:53:42 +01:00
int swigcode;
2018-05-20 00:47:27 +01:00
yap_error_descriptor_t *info;
2014-06-30 14:34:58 +01:00
public:
2018-05-20 00:47:27 +01:00
/// wraps the default error descriptor
YAPError() {
info = LOCAL_ActiveError;
if (!info)
LOCAL_ActiveError = info = (yap_error_descriptor_t *)calloc( sizeof( yap_error_descriptor_t ), 1);
// if (info->errorNo != YAP_NO_ERROR) {};
//std::cerr << "Error detected" << info->errorNo << "\n";
2017-02-20 14:38:00 +00:00
}
2018-05-20 00:47:27 +01:00
/// if des != nullptr, wrap a preexisting error descriptor;
/// otherwise, generate a new one
YAPError(yap_error_descriptor_t *des) {
if (des)
info= des;
else info = (yap_error_descriptor_t *)calloc( sizeof( yap_error_descriptor_t ), 1);
// if (info->errorNo != YAP_NO_ERROR) {};
//std::cerr << "Error detected" << info->errorNo << "\n";
2018-04-07 19:45:18 +01:00
}
2018-05-20 00:47:27 +01:00
2017-02-20 14:38:00 +00:00
/// error handler object with initial data when receiving the error term
2018-05-20 00:47:27 +01:00
// YAPError( std::string file, std::string function, int lineno,
// yap_error_number id, YAPTerm culprit, std::string txt) {
// info = new yap_error_descriptor_t;
// Yap_MkErrorRecord(info, file.c_str(), function.c_str(), lineno, id, culprit.term(), txt.c_str());
//}
/// error handler object with initial data when receiving the error term
YAPError( const char * file, const char * function, int lineno,
yap_error_number id, YAP_Term culprit, const char * txt) {
info = (yap_error_descriptor_t *)calloc( sizeof( yap_error_descriptor_t ), 1);
Yap_MkErrorRecord(info, file, function, lineno, id, culprit, txt);
}
/// short version
#define SOURCE() __FILE__, __FUNCTION__, __LINE__
2017-02-20 14:38:00 +00:00
2016-09-21 20:41:23 +01:00
/// we just know the error number
/// exact error ID
2018-05-20 00:47:27 +01:00
yap_error_number getID() { return info->errorNo; };
2016-09-21 20:41:23 +01:00
/// class of error
yap_error_class_number getErrorClass() {
2018-05-20 00:47:27 +01:00
return Yap_errorClass(info->errorNo);
2016-09-21 20:41:23 +01:00
};
/// where in the code things happened;
2018-05-20 00:47:27 +01:00
const char *getFile() { return info->errorFile; };
2016-09-21 20:41:23 +01:00
/// predicate things happened;
2018-05-20 00:47:27 +01:00
Int getLine() { return info->errorLine; };
2016-09-21 20:41:23 +01:00
/// the term that caused the bug
2018-05-20 00:47:27 +01:00
// YAPTerm getCulprit(info->errorFile){};
2016-09-21 20:41:23 +01:00
/// text describing the Error
2017-02-20 14:38:00 +00:00
std::string text();
2014-07-10 15:07:55 +01:00
};
2014-06-30 14:34:58 +01:00
2016-09-21 20:41:23 +01:00
#endif
2017-03-20 15:52:48 +00:00
/// @}