The PrologDatabase class represents a database, or list, of Prolog-like expressions. Instances of this class are used for reading, writing and creating data files.
PrologDatabase::PrologDatabase
PrologDatabase::~PrologDatabase
PrologDatabase::AddTemplate
PrologDatabase::Append
PrologDatabase::BeginFind
PrologDatabase::ClearDatabase
PrologDatabase::FindClause
PrologDatabase::FindClauseByFunctor
PrologDatabase::FindTemplate
PrologDatabase::GetErrorCount
PrologDatabase::HashFind
PrologDatabase::ReadProlog
PrologDatabase::ReadPrologFromString
PrologDatabase::WriteClips
PrologDatabase::WriteClipsFiltering
PrologDatabase::WriteLisp
PrologDatabase::WriteProlog
void PrologDatabase(proioErrorHandler handler = 0)
Construct a new, unhashed database, with an optional error handler. The error handler must be a function returning a Bool and taking an integer and a string argument. When an error occurs when reading or writing a database, this function is called. The error is given as the first argument (currently one of PROIO_ERROR_GENERAL, PROIO_ERROR_SYNTAX) and an error message is given as the second argument. If FALSE is returned by the error handler, processing of the PROLOGIO operation stops.
Another way of handling errors is simply to call GetErrorCount after the operation, to check whether errors have occurred, instead of installing an error handler. If the error count is more than zero, WriteProlog and ReadProlog will return FALSE to the application.
For example:
Bool myErrorHandler(int err, chat *msg) { if (err == PROIO_ERROR_SYNTAX) { wxMessageBox(msg, "Syntax error"); } return FALSE; } PrologDatabase database(myErrorHandler);void PrologDatabase(PrologType type, char *attribute,
Construct a new database hashed on a combination of the clause functor and a named attribute (often an integer identification).
See above for an explanation of the error handler.
void ~PrologDatabase(void)
Delete the database and contents.
void AddTemplate(ClipsTemplate *temp)
Add a CLIPS template definition to the template list associated with the database.
void Append(PrologExpr *clause)
Append a clause to the end of the database. If the database is hashing, the functor and a user-specified attribute will be hashed upon, giving the option of random access in addition to linear traversal of the database.
void BeginFind(void)
Reset the current position to the start of the database. Subsequent FindClause calls will move the pointer.
void ClearDatabase(void)
Clears the contents of the database.
Various ways of retrieving clauses from the database. A return value of NULL indicates no (more) clauses matching the given criteria. Calling the functions repeatedly retrieves more matching clauses, if any.
PrologExpr * FindClause(long id)
Find a clause based on the special "id'' attribute.
PrologExpr * FindClause(char *attribute, char *value)
Find a clause which has the given attribute set to the given string or word value.
PrologExpr * FindClause(char *attribute, long value)
Find a clause which has the given attribute set to the given integer value.
PrologExpr * FindClause(char *attribute, float value)
Find a clause which has the given attribute set to the given floating point value.
PrologExpr * FindClauseByFunctor(char * functor)
Find the next clause with the specified functor.
ClipsTemplate * FindTemplate(char *template_name)
Finds a named CLIPS template definition associated with the database.
int GetErrorCount(void)
Returns the number of errors encountered during the last read or write operation.
PrologExpr * HashFind(char * functor, long value)
Finds the clause with the given functor and with the attribute specified in the database constructor having the given integer value.
For example,
// Hash on a combination of functor and integer "id" attribute when reading in PrologDatabase db(PrologInteger, "id"); // Read it in db.ReadProlog("data"); // Retrieve a clause with specified functor and id PrologExpr *clause = db.HashFind("node", 24);This would retrieve a clause which is written: node(id = 24, ..., ).
PrologExpr * HashFind(char * functor, char *value)
Finds the clause with the given functor and with the attribute specified in the database constructor having the given string value.
Bool ReadProlog(char * filename)
Reads in the given file, returning TRUE if successful.
Bool ReadPrologFromString(char * buffer)
Reads a Prolog database from the given string buffer, returning TRUE if successful.
void WriteClips(ostream& stream)
Writes the database as a CLIPS deftemplate and deffacts file.
void WriteClipsFiltering(ostream& stream)
Writes the database as a CLIPS deftemplate and deffacts file, filtering slots in the facts according to the template definitions (e.g. to reduce the size of the output file by not including irrelevant slots).
void WriteLisp(ostream& stream)
Writes the database as a LISP-format file.
void WriteProlog(ostream& stream)
Writes the database as a Prolog-format file.