Re: Normalizing Every Thing with XDb2
From: Neo <neo55592_at_hotmail.com>
Date: 28 Jul 2004 16:24:05 -0700
Message-ID: <4b45d3ad.0407281524.59c214e9_at_posting.google.com>
}
Date: 28 Jul 2004 16:24:05 -0700
Message-ID: <4b45d3ad.0407281524.59c214e9_at_posting.google.com>
// Create money
NLI_create_r(_T("*money cls thing"));
// Create 1 $
NLI_create_r(_T("*"));
NLI_create_r(_T("* cls money"));
NLI_create_r(_T("* quantity 1"));
NLI_create_r(_T("* unit $"));
// Create relators
NLI_create_r(_T("*thickness cls relator"));
NLI_create_r(_T("*weight cls relator"));
NLI_create_r(_T("*cost cls relator"));
// Create box
NLI_create_r(_T("*box cls thing"));
// Create box1
NLI_create_r(_T("*box1 cls box"));
NLI_create_r(_T("box1 thickness (distance)((quantity)1)((unit)cm)"));
NLI_create_r(_T("box1 weight (mass)(1)(kg)"));
NLI_create_r(_T("box1 cost (money)(1)($)"));
// Create box2
NLI_create_r(_T("*box2 cls box"));
NLI_create_r(_T("box2 thickness (distance)((quantity)1)((unit)cm)"));
NLI_create_r(_T("box2 weight (mass)(10)(kg)"));
NLI_create_r(_T("box2 cost (money)(1)($)"));
// Get ptr to things created above
// Note: one of several methods
int* pBox = Str_getDefT(_T("box"));
int* pQty = Str_getDefT(_T("quantity"));
int* pWeight = Str_getDefT(_T("weight"));
int* pInteger = Str_getDefT(_T("integer"));
// Loop thru box instances
int totalWeight = 0;
int* pE[32];
Expr_SVx_get_r(pBox, pReInst_g, pE);
while (int* pBoxX = X2(pE)){
// Get boxX's weight
int* pWeightX = S_SVx_1st(pBoxX, pWeight);
if (pWeightX){
// Get weightX's qty
int* pQtyX = S_SVx_1st(pWeightX, pQty);
if (pQtyX){
// If qtyX is an integer
if (S_SVO_1st(pQtyX, pReCls_g, pInteger)){
// Get qtyX's name as an ascii str
TCHAR sQtyX[kStrSz_g+1] = _T("");
T_Name_get(pQtyX, sQtyX, kStrSz_g);
// Convert ascii str to integer
int iQtyX = _ttoi(sQtyX);
// Sum weight
totalWeight = totalWeight + iQtyX;
}
}
}
}
// Print total weight of boxes (prints 11)
TRACE(_T("Total weight of boxes is: %d\n"), totalWeight);
}
Received on Thu Jul 29 2004 - 01:24:05 CEST
