Did you know ... | Search Documentation: |
Discussion of the sample PlBlob code (wrapping a pointer) |
<cstdio>
. The blob wraps the
file pointer returned from fopen() and also keeps a few other
values for debugging (the mode, flags, filename from the call to fopen())
plus a buffer for read operations.
[search,read]
would map to‘examPL_FILE_SEARCH|PL_FILE_READ‘.
MyFileBlob
struct defines the blob that wraps a
FILE*
. The constructor (which is called by predicate
my_file_open/4)
converts the flags term (a list of atoms or strings) to a
flag that is passed to PL_get_file_name(), to convert the filename
to a string containing the abslute file name. This is then passed to fopen(),
together with the
mode. If the call to fopen() fails, a C++ exception is
thrown, to be handled by Prolog. Other errors, such as a wrong argument
type to PL_get_file_name() can also cause an exception.
FILE*
to null, so that close won't be done twice.
MyBlob
in section
1.6.8.5.
MyFileBlob
constructor with Filename, Mode,
flags and unifies the blob with File.