| Did you know ... | Search Documentation: |
| Extraction of the atom and comparison to char * |
Example:
PREDICATE(test, 1)
{ PlAtom a1(A1);
if ( a1 == "read" )
...;
}
This approach extracts the atom once and for each test extracts the represented string from the atom and compares it. It avoids the need for global atom constructors.
atom_t). Used
internally and for integration with the C-interface.char* and std::string
forms
rep gives the byte encoding (see section
1.8.2); it defaults to ENC_INPUT. See PL_new_atom_mbchars()
and
PL_new_atom_wchars(). The constructors
PlAtom(PlEncoding, len, s)
and PlAtom(PlEncoding,
std::string&) are [[deprecated]] in favour
of the trailing-PlEncoding forms above.type_error is thrown.true if the atom represents text, false
otherwise. Performs a strcmp() or similar for this.true or
false. Because atoms are unique, there is no need to use strcmp()
for this.== operator.true.char* from a function, you should not
do return t.as_string().c_str()
because that will return a pointer into the stack (Gnu C++ or Clang
options -Wreturn-stack-address or -Wreturn-local-addr)
can sometimes catch this, as can the runtime address sanitizer
when run with detect_stack_use_after_return=1.
This does not quote or escape any characters that would need to be
escaped if the atom were to be input to the Prolog parser. The possible
values for enc are (see section
1.8.2):
PlEncoding::Latin1 - throws an exception if the text
cannot be represented in ISO Latin-1.PlEncoding::UTF8 - UTF-8.PlEncoding::Locale - uses the locale to determine the
representation.ENC_INPUT (PlEncoding::Latin1)
and
ENC_OUTPUT (PlEncoding::Locale) name the
defaults used for constructing and returning text respectively.