external database "chain" object
Posted: 7 Aug 2009 11:26
Hi,
Here is a very simple class that I use when using the external database. The class is "adl_chain", and each adl_chain object is created with a chainDB and a chain name. When an object is created, you no longer have to ensure the chain name is correct. So instead of
you would use:
No, big deal, but it makes things a bit easier to control if you have many chains. The predicates are the same as chaindb, but the chain name is not required.
Here is the code.
File: adl_chain.i
File: adl_chain.cl
File: adl_chain.pro
Here is a very simple class that I use when using the external database. The class is "adl_chain", and each adl_chain object is created with a chainDB and a chain name. When an object is created, you no longer have to ensure the chain name is correct. So instead of
Code: Select all
clauses
fred(ChainDB):-
ChainDB:chain_inserta("chain_name",Term,Ref),
Code: Select all
fred(ADL_CHAIN):-
ADL_CHAIN:chain_inserta(Term,Ref),
Here is the code.
File: adl_chain.i
Code: Select all
interface adl_chain
open core
domains
chain_name=string.
predicates
chain_inserta:(_ Term,chainDB::ref) procedure (i,o).
chain_insertz:(_ Term,chainDB::ref) procedure (i,o).
ref_term:(chainDB::ref,_) procedure (i,o).
term_replace:(chainDB::ref,_ Term).
term_delete:(chainDB::ref).
chain_terms:(_ Term,chainDB::ref) nondeterm (o,o).
p_chain_delete:().
get_nth:(integer)->_ Term determ.
end interface adl_chain
Code: Select all
class adl_chain : adl_chain
open core
predicates
classInfo : core::classInfo.
% @short Class information predicate.
% @detail This predicate represents information predicate of this class.
% @end
constructors
new:(chaindb,chain_name).
end class adl_chain
Code: Select all
implement adl_chain
open core
constants
className = "vip6pack/mychainDB/adl_chain".
classVersion = "".
clauses
classInfo(className, classVersion).
facts
zz_db:chaindb:=erroneous.
zz_chain_name:chain_name:=erroneous.
clauses
new(Chaindb,Chain_name):-
zz_db:=ChainDB,
zz_chain_name:=Chain_name.
clauses
chain_inserta(Term,Ref):-
zz_db:chain_inserta(zz_chain_name,Term,Ref).
clauses
chain_insertz(Term,Ref):-
zz_db:chain_insertz(zz_chain_name,Term,Ref).
clauses
ref_term(Ref,Term):-
zz_dB:ref_term(Ref, Term).
clauses
term_replace(Ref,Term):-
zz_db:term_replace(Ref,Term).
clauses
term_delete(Ref):-
zz_db:term_delete(zz_chain_name,Ref).
clauses
chain_terms(Term,Ref):-
zz_db:chain_terms(zz_chain_name,Term,Ref).
clauses
p_chain_delete():-
zz_db:chain_delete(zz_chain_name),
fail.
p_chain_delete().
facts
zz_count:integer:=0.
clauses
get_nth(N)=Term:-
zz_count:=0,
zz_db:chain_terms(zz_chain_name,Term,_Ref),
zz_count:=zz_count+1,
zz_count=N,!.
end implement adl_chain