- Documentation
- Reference manual
- Packages
- A C++ interface to SWI-Prolog
- A C++ interface to SWI-Prolog (Version 2)
- Overview of accessing and changing values (version 2)
- Converting PlTerm to native C and C++ types (version 2)
- Unification (version 2)
- Comparison (version 2)
- Analysing compound terms (version 2)
- Miscellaneous (version 2)
- The class PlTerm_string (version 2)
- The class PlCodeList (version 2)
- The class PlCharList (version 2)
- The class PlCompound (version 2)
- The class PlTail (version 2)
- The class PlTermv (version 2)
- The class PlAtom - Supporting Prolog constants (version 2)
- Classes for the recorded database: PlRecord and PlRecordExternalCopy
- Overview of accessing and changing values (version 2)
- A C++ interface to SWI-Prolog (Version 2)
- A C++ interface to SWI-Prolog
2.10.13 Classes for the recorded database: PlRecord and PlRecordExternalCopy
The recorded database is has two wrappers, for supporting the internal records and external records.
Currently, the interface to internal records requires that
the programmer explicitly call the dupicate() and erase()
methods - in future, it is intended that this will be done automatically
by a new
PlRecord
class, so that the internal records behave like “smart
pointers” ; in the meantime, the PlRecord
provides a
trivial wrapper around the various recorded database functions.
The class PlRecord
supports the following methods:
- PlRecord(PlTerm)
- Constructor.
- PlRecord(PlRecord)
- Copy and move constructors. Currently these do not do any reference counting. The assignment operator is currently not supported.
- PlRecord()
- Destructor. Currently this does not call PL_erase().
- PlTerm term()
- creates a term from the record, using PL_recorded().
- void erase()
- decrements the reference count of the record and deletes it if the count
goes to zero, using PL_erase(). It is safe to do this multiple
times on the same
PlRecord
object. - PlRecord duplicate()
- increments the reference count of the record, using PL_duplicate_record().
The class PlRecord
provides direct access to the
reference counting aspects of the recorded term (through the duplicate()
and
erase() methods), but does not
connect these with C++'s copy constructor, assignment operator, or
destructor. If the recorded term is encapsulated within an object, then
the containing object can use the duplicate()
and erase() methods in its copy and
move constructors and assignment operators (and the erase()
method in the destructor).26The
copy constructor and assignment use the duplicate()
method; the move constructor and assignment use the duplicate()
method to assign to the destination and the erase()
method on the source; and the destructor uses erase().
Alternatively, the std::shared_ptr
or std::unique_ptr
can be used with the supplied PlrecordDeleter
, which calls
the
erase() method when the shared_ptr
reference count goes to zero or when the std::unique_ptr
goes out of scope.
For example:
std::shared_ptr<PlRecord> r(new PlRecord(t.record()), PlRecordDeleter()); assert(t.unify_term(r->term()));
The class PlRecordExternalCopy
keeps the external
record as an uninterpreted string. It supports the following
methods.
- PlRecordExternalCopy()
- Constructor. Creates a string using Pl_record_external(), copies it into the object, then deletes the reference using PL_erase_external().
- PlTerm term()
- creates a term from the record, using PL_recorded_external()).