This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/CXX/yapa.hh

124 lines
3.8 KiB
C++
Raw Normal View History

2017-04-07 23:10:59 +01:00
/// @file yapa.hh
///
/// @brief C++ Interface to atoms and their properties.
2017-03-20 15:52:48 +00:00
2015-02-09 01:52:10 +00:00
#ifndef YAPA_HH
#define YAPA_HH 1
/**
2017-03-20 15:52:48 +00:00
*
2017-04-07 23:10:59 +01:00
* @defgroup yap-cplus-interface-atoms Prolog Atoms
2017-03-20 15:52:48 +00:00
*
2017-04-07 23:10:59 +01:00
* @brief Symbols and associated propeeties.
*
* @ingroup yap-cplus-interface
2017-03-20 15:52:48 +00:00
* @tableofcontents
2017-04-07 23:10:59 +01:00
* @{
2017-03-20 15:52:48 +00:00
*
*
2017-04-07 23:10:59 +01:00
* Prolog interns symbols, called *atoms* in a Hash table, usually
called the atom table_. Each entry in this table stores the atom's
name, but also may have a linked list of _properties_ We use
properties to represent all kinds of data including. data-base
tecords, predicates. operators, and more.
2017-03-20 15:52:48 +00:00
*
2017-04-07 23:10:59 +01:00
* In a nutshell:
* - YAPAtom serves as the gateway to the data-base;
2017-09-06 01:16:36 +01:00
*
2017-04-07 23:10:59 +01:00
* - YAProp abstracts most data-base objects.
2017-03-20 15:52:48 +00:00
*
2017-04-07 23:10:59 +01:00
* - PropTag allows distinguishing the different classes of YAPProp.
2017-03-20 15:52:48 +00:00
*/
2015-02-09 01:52:10 +00:00
enum PropTag {
/// predicate
PRED_TAG = PEProp, // 0x0000,
/// db key, may be associated with a functor
2017-03-20 15:52:48 +00:00
DB_TAG = DBProperty, // 0x8000,
2015-02-09 01:52:10 +00:00
/// generic functor, may include sub-properties
2017-03-20 15:52:48 +00:00
FUNCTOR_TAG = FunctorProperty, // 0xBB00,
2015-02-09 01:52:10 +00:00
// SPARSE_FUNCTOR_TAG = 0xFFDF,
/// arithmetic function
2017-03-20 15:52:48 +00:00
ARITHMETIC_PROPERTY_TAG = ExpProperty, // 0xFFE0,
2015-02-09 01:52:10 +00:00
/// map the atom to an integer
2017-03-20 15:52:48 +00:00
TRANSLATION_TAG = TranslationProperty, // 0xFFF4,
2017-09-06 01:16:36 +01:00
/// ensure the atom may not be garbafe colected
HOLD_TAG = HoldProperty, // 0xFFF6
2017-03-20 15:52:48 +00:00
/// named mutEX
MUTEX_TAG = MutexProperty, // 0xFFF6,
2015-02-09 01:52:10 +00:00
/// A typed array, may be in-db or in-stack deped
2017-09-06 01:16:36 +01:00
ARRAY_TAG = ArrayProperty, // 0xFFF7,
2015-02-09 01:52:10 +00:00
/// module
2017-03-20 15:52:48 +00:00
MODULE_TAG = ModProperty, // 0xFFFA,
2015-02-09 01:52:10 +00:00
/// the original SICStus blackboard
2017-03-20 15:52:48 +00:00
BLACKBOARD_TAG = BBProperty, // 0xFFFB,
2015-02-10 09:14:55 +00:00
/// associate an atomic value with the atom
2017-03-20 15:52:48 +00:00
VALUE_TAG = ValProperty, // 0xFFFC,
2015-02-09 01:52:10 +00:00
/// Demoen's proposal for gkobal variables
2017-03-20 15:52:48 +00:00
GLOBAL_VAR_TAG = GlobalProperty, // 0xFFFD
2015-02-10 09:14:55 +00:00
/// SWI-STYLE ATOM Extension
2017-03-20 15:52:48 +00:00
BLOB_TAG = BlobProperty, // 0xFFFE,
2017-09-06 01:16:36 +01:00
/// Prolog operator,
OPERATOR_TAG = OpProperty, // 0xFFFF,
2017-03-20 15:52:48 +00:00
};
2015-02-09 01:52:10 +00:00
/**
* @brief Atom
* A YAP data-base is a collection of atoms, where each atom has a name
* and a set of Properties. Examples of properties include functors,
* predicates, operators, modules, almost everything.
*
*/
2017-06-12 18:00:47 +01:00
class X_API YAPAtom {
2016-07-31 16:22:24 +01:00
friend class YAPEngine;
2015-02-09 01:52:10 +00:00
friend class YAPModuleProp;
friend class YAPPredicate;
friend class YAPFunctor;
friend class YAPAtomTerm;
friend class YAProp;
friend class YAPModule;
2016-07-31 16:22:24 +01:00
friend class YAPQuery;
2015-02-09 01:52:10 +00:00
Atom a;
/// construct new YAPAtom from Atom
YAPAtom( Atom at ) { a = at; }
public:
2017-03-20 15:52:48 +00:00
/// construct new YAPAtom from UTF-8 string
YAPAtom( const char * s) { a = Yap_LookupAtom( s ); }
/// construct new YAPAtom from UTF-8 string
YAPAtom( const wchar_t * s) { CACHE_REGS a = UTF32ToAtom( s PASS_REGS ); }
2015-02-09 01:52:10 +00:00
/// construct new YAPAtom from wide string
//YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); }
2015-02-09 01:52:10 +00:00
/// construct new YAPAtom from max-length string
2017-03-20 15:52:48 +00:00
YAPAtom( const char * s, size_t len) { a = Yap_LookupAtomWithLength( s, len ); }
2015-02-09 01:52:10 +00:00
/// get name of atom
2016-07-31 16:22:24 +01:00
const char *getName(void);
/// get name of (other way)
2017-03-20 15:52:48 +00:00
inline const char *text(void) { return getName(); } ;
/// get prop of type
2017-09-06 01:16:36 +01:00
Prop getProp( PropTag tag ) { return Yap_GetAProp( a , (PropFlags)tag ); }
2015-02-09 01:52:10 +00:00
};
/**
* @brief Prop
* A YAP Propery is ameta-class for everything one can in a atom.
* Examples of properties include functors,
* predicates, operators, modules, almost everything.
*
*/
2017-06-12 18:00:47 +01:00
class X_API YAPProp {
2015-02-09 01:52:10 +00:00
friend class YAPModuleProp;
friend class YAPFunctor;
/// does nothing, p is defined by the subclass
YAPProp() { }
/// get type of prop
PropTag tag( Prop p ) { return (PropTag)(p->KindOfPE); }
public:
/// get name of property
2017-02-20 14:38:00 +00:00
// virtual YAPAtom name();
2017-03-20 15:52:48 +00:00
virtual ~YAPProp() {};
2017-09-06 01:16:36 +01:00
2015-02-09 01:52:10 +00:00
};
2017-09-06 01:16:36 +01:00
#endif /* YAPA_HH */
2017-03-20 15:52:48 +00:00
/// @}