• 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.11 Overview of accessing and changing values
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • A C++ interface to SWI-Prolog
        • A C++ interface to SWI-Prolog
          • Overview of accessing and changing values
            • Converting PlTerm to native C and C++ types
            • Unification
            • Comparison
            • Analysing compound terms
            • Miscellaneous
            • The class PlTerm_string
            • The class PlCodeList
            • The class PlCharList
            • The class PlCompound
            • The class PlTerm_tail
            • The class PlTermv
            • The class PlAtom - Supporting Prolog constants
            • Classes for the recorded database: PlRecord and PlRecordExternalCopy

1.11.11 The class PlTermv

The class PlTermv represents an array of term-references. This type is used to pass the arguments to a foreign defined predicate, construct compound terms (see PlTerm::PlTerm(const char *name)PlTermv arguments ), and to create queries (see PlQuery).

The only useful member function is the overloading of [], providing (0-based) access to the elements. Range checking is performed and raises a domain_error exception.

The constructors for this class are below. Note that these can be error-prone because there's no distinction between term_t and size_t; the form of the constructor is determined by whether the first argument is an integer (term_t or size_t) or PlTerm.

PlTermv :: PlTermv(size_t size)
Create a new array of term-references, all holding variables.
PlTermv :: PlTermv(size_t size, term_t t0)
Convert a C-interface defined term-array into an instance. Typyically, t0 was created using Pl_new_term_refs(size).
PlTermv :: PlTermv(PlTerm ...)
Create a vector from 1 to 5 initialising arguments. For example:
load_file(const char *file)
{ return PlCall("compile", PlTermv(PlAtom(file)));
}

If the vector has to contain more than 5 elements, the following construction should be used:

{ PlTermv av(10);

  av[0].put_term(PlTerm_atom("hello"));
  av[1].put_term(PlTerm_integer(666));
  ...
}

Important: be sure that all the arguments are of type PlTerm - PlTermv(i) is not the same as PlTermv(PlTerm_integer(i)), and will result in a runtime error.

ClioPatria (version V3.1.1-51-ga0b30a5)