Re: Transitive Closure with XDb1
Date: 13 May 2004 11:34:31 -0700
Message-ID: <4b45d3ad.0405131034.da76855_at_posting.google.com>
> Leandro said: You are 30 years late. Relational is declarative.
Below shows how to create the simple hierarchy "declaratively" via XDb1's API and loop thru parts of universe.
void Example003()
{
// Vars set by S_process_r
int* pR_r = NULL; // Relation created const kMsgSz = 1023; // Error message size TCHAR msg_r[kMsgSz+1] = _T(""); // Error message
// Create universe
S_process_r(_T("universe isa thing"), NULL, msg_r, kMsgSz, &pR_r);
// Create planets
S_process_r(_T("planet isa thing"), NULL, msg_r, kMsgSz, &pR_r); S_process_r(_T("mars isa planet"), NULL, msg_r, kMsgSz, &pR_r); S_process_r(_T("venus isa planet"), NULL, msg_r, kMsgSz, &pR_r);
// Create persons
S_process_r(_T("person isa thing"), NULL, msg_r, kMsgSz, &pR_r); S_process_r(_T("john isa person"), NULL, msg_r, kMsgSz, &pR_r); S_process_r(_T("mary isa person"), NULL, msg_r, kMsgSz, &pR_r);
// Create hierarchy
S_process_r(_T("mars isPartOf universe"), NULL,msg_r,kMsgSz,&pR_r); S_process_r(_T("venus isPartOf universe"),NULL,msg_r,kMsgSz,&pR_r); S_process_r(_T("john isPartOf mars"), NULL, msg_r, kMsgSz, &pR_r); S_process_r(_T("mary isPartOf venus"), NULL, msg_r, kMsgSz, &pR_r);
// Get ptr to universe
// Note: one of several methods
int* pUniverse = R_Dest(Str_getDefT(_T("universe")));
// Looping thru parts of universe
// Prints: mars, john, venus, mary
#define maxTreeDepth 64
int* pDescX_a[maxTreeDepth] = {T_R_PriRecip(pUniverse), NULL};
while (int i=T_Relative(pDescX_a, maxTreeDepth, rPart, TRUE)){
TCHAR sName[kNmSz_g+1] = _T(""); int* pT = R_Dest(pDescX_a[i]); T_Name_get(pT, sName, kNmSz_g); TRACE(_T("%s\n"), sName);
}
} Received on Thu May 13 2004 - 20:34:31 CEST