|Did you know ...||Search Documentation:|
|Porting from version 1 to version 2|
The easiest way of porting from
is to change the
#include "SWI-cpp.h" to
"SWI-cpp2.h" and look at the warning and error messages. Where
possible, version 2 keeps old interfaces with a "deprecated" flag if
there is a better way of doing things with version 2.
For convenience when calling PL_*() functions, the Plx_*() wrapper
functions add error checking. Also, most of the PL_*() functions that
atom_t, etc. have
corresponding methods in
Here is a list of typical changes:
term_t, PlTerm_integer(i), PlTerm_float(v), or PlTerm_pointer(p).
wchar_tand replace them by
std::wstringif appropriate. For example,
cout << "Hello " << (char*)A1 << endlcan be replaced by
cout << "Hello " << A1.as_string() << endl. In general,
std::stringis safer than
char*because the latter can potentially point to freed memory.
falsefrom a predicate for failure, you can do
throw PlFail(). This mechanism is also used by PlCheckFail(rc). Note that throwing an exception is slower than returning
false, so performance-critical code should avoid PlCheckFail(rc) if failure is expected to happen often.
SWI-Prologand throw a
PlFailexception to short-circuit execution and return failure (
false) to Prolog (or throw a
PlExceptionif there was a Prolog error.
PlAtom::handlehas been replaced by
PlAtom::C_, which should be accessed by PlAtom::unwrap().
PlTerm::refhas been replaced by
PlTerm::C_, which should be accessed by PlTerm::unwrap().
PlFunctor::functorhas been replaced by
PlFunctor::C_, which should be accessed by PlFunctor::unwrap().
for unification has been deprecated, replaced by various unify_*() methods (PlTerm::unify_term(t2), PlTerm::unify_atom(a), etc.).
static_cast<char*>(t)is replaced by
t.as_string().c_str()(and you should prefer
static_cast<int32_t>(t)is replaced by
longbecause of problems porting between Unix and Windows platforms; instead, use