2.9 The class PlTerm (version 2)
AllApplicationManualNameSummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog (Version 2)
          • The class PlTerm (version 2)
            • Constructors (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 PlTermString (version 2)
            • The class PlCodeList (version 2)
            • The class PlCharList (version 2)
            • The class PlCompound (version 2)
            • The class PlTail (version 2)

2.9.3 Converting PlTerm to native C and C++ types (version 2)

These are deprecated and replaced by the various as_*() methods.

PlTerm can be converted to the following types:

PlTerm ::operator term_t(void)
This cast is used for integration with the C-interface primitives.
PlTerm ::operator long(void)
Yields a long if the PlTerm is a Prolog integer or float that can be converted without loss to a long. throws a type_error exception otherwise.
PlTerm ::operator int(void)
Same as for long, but might represent fewer bits.
PlTerm ::operator double(void)
Yields the value as a C double if PlTerm represents a Prolog integer or float.
PlTerm ::operator wchar_t *(void)
PlTerm ::operator char *(void)
Converts the Prolog argument using PL_get_chars() using the flags CVT_ALL|CVT_WRITE|BUF_RING, which implies Prolog atoms and strings are converted to the represented text. All other data is handed to write/1. If the text is static in Prolog, a direct pointer to the string is returned. Otherwise the text is saved in a ring of 16 buffers and must be copied to avoid overwriting.
PlTerm ::operator void *(void)
Extracts pointer value from a term. The term should have been created by PlTerm::PlTerm(void*).

In addition, the Prolog type (`PL_VARIABLE`,‘PL_ATOM`, ...‘PL_DICT`) can be determined using the type() method. There are also boolean methods that check the type:

int type()
See PL_term_type()
bool is_variable()
See PL_is_variable()
bool is_ground()
See PL_is_ground()
bool is_atom(S)
ee PL_is_atom()
bool is_integer(S)
ee PL_is_integer()
bool is_string(S)
ee PL_is_string()
bool is_float(S)
ee PL_is_float()
bool is_rational(S)
ee PL_is_rational()
bool is_compound(S)
ee PL_is_compound()
bool is_callable(S)
ee PL_is_callable()
bool is_list(S)
ee PL_is_list()
bool is_dict(S)
ee PL_is_dict()
bool is_pair(S)
ee PL_is_pair()
bool is_atomic(S)
ee PL_is_atomic()
bool is_number(S)
ee PL_is_number()
bool is_acyclic(S)
ee PL_is_acyclic()
bool is_functor(PlFunctor)
See PL_is_functor()