• Places
    • Home
    • Graphs
    • Prefixes
  • Admin
    • Users
    • Settings
    • Plugins
    • Statistics
  • CPACK
    • Home
    • List packs
    • Submit pack
  • Repository
    • Load local file
    • Load from HTTP
    • Load from library
    • Remove triples
    • Clear repository
  • Query
    • YASGUI SPARQL Editor
    • Simple Form
    • SWISH Prolog shell
  • Help
    • Documentation
    • Tutorial
    • Roadmap
    • HTTP Services
  • Login

1.6 Overview
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog
          • Overview
            • Design philosophy of the classes
            • Summary of files
            • Summary of classes
            • Wrapper functions
            • Naming conventions, utility functions and methods
            • PlTerm class
            • PlTermScoped class (experimental)
            • Blobs
            • Limitations of the interface
            • Linking embedded applications using swipl-ld

1.6.4 Wrapper functions

The various PL_*() functions in SWI-Prolog.h have corresponding Plx_*() functions, defined in SWI-cpp2-plx.h, which is always included by SWI-cpp2.h. There are three kinds of wrappers, with the appropriate one being chosen according to the semantics of the wrapped function:

  • “as-is” - the PL_*() function cannot cause an error. If it has a return value, the caller will want to use it.

  • “exception wrapper” - the PL_*() function can return false, indicating an error. The Plx_*() function checks for this and throws a PlException object containing the error. The wrapper uses template<typename C_t> C_t PlEx(C_t rc), where C_t is the return type of the PL_*() function.

  • “success, failure, or error” - the PL_*() function can return true if it succeeds and false if it fails or has a runtime error. If it fails, the wrapper checks for a Prolog error and throws a PlException object containing the error. The wrapper uses template<typename C_t> C_t PlWrap(C_t rc), where C_t is the return type of the PL_*() function.

A few PL_*() functions do not have a corresponding Plx*() function because they do not fit into one of these categories. For example, PL_next_solution() has multiple return values (PL_S_EXCEPTION, PL_S_LAST, etc.) if the query was opened with the PL_Q_EXT_STATUS flag.

Most of the PL_*() functions whose first argument is of type term_t, atom_t, etc. have corresponding methods in classes PlTerm, PlAtom, etc.

Important: You should use the Plx_*() wrappers only in the context of a PREDICATE() call, which will handle any C++ exceptions. Some blob callbacks can also handle an exception (see section 1.6.8). Everywhere else, the result of calling a Plx_*() function is unpredicatable - probably a crash.

ClioPatria (version V3.1.1-51-ga0b30a5)