|Did you know ...||Search Documentation:|
|Summary of changes between Versions 1 and 2|
Version 1 is in
SWI-cpp.h; version 2 is in
The overall structure of the API has been retained - that is, it is a
thin layer on top of the interface provided by
SWI-Prolog.h. Based on experience with the API, most of the
conversion operators have been removed or deprecated, and replaced by
"getter" methods. The overloaded constructors have been replaced by
subclasses for the various types. Some changes were also made to ensure
PlTermv doesn't cause unexpected implicit conversions.
2If there is an implicit
conversion operator from
char*, then the
operator is ambiguous in
PlTerm t=...; f(t) if
is overloaded to accept a
falsefrom a predicate to indicate failure, you can use
throw PlFail(). The convenience function PlCheck(rc) can be used to throw
PlFail(), if a
falseis returned from a function in
(int64_t)t) have been deprecated, replaced by "getters" (e.g.,
(char*)tis a C-style cast; C++'s preferred form is more verbose:
char*have been replaced by methods that return
std::stringto ensure that lifetime issues don't cause subtle bugs.4If you want to return a
char*from a function, you should not do
return t.as_string().c_str()because that will return a pointer to local or stack memory. Instead, you will need to change your interface to return a
std::stringand apply the
c_str()method to it. These errors can sometimes be caught by specifying the Gnu C++ or Clang options
-Wreturn-local-addr- Clang seems to do a better analysis.
PlStringhas been renamed to
PlTerm_stringto make it clear that it's a term that contains a Prolog string.
PL_...(term_t, ...)methods have been added to
std::wstringare now supported in most places where
intfor true/false now return a C++
atom_t, etc.) have been renamed from
ref, etc. to
C_.5This is done by subclassing from
Wrapped<atom_t>, etc., which define the field
C_, standard constructors, the methods is_null(), not_null(), reset(), and reset(v), plus the constant
PlForeignContextPtr<ContextType>has been added, to simplify dynamic memory allocation in non-deterministic predicates.
PlStringBuffersprovides a simpler interface for allocating strings on the stack than PL_STRINGS_MARK() and PL_STRINGS_RELEASE().
More details are given in section 2.6 and section 2.7.