Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Modelling Variable Properties with XDb1

 
   Database Help (Home) -> Object-Oriented RSS
Next:  Are circular relationships a bad thing in ER-mode..  
Author Message
Neo

External


Since: Nov 30, 2003
Posts: 45



(Msg. 1) Posted: Wed May 05, 2004 12:00 am
Post subject: Modelling Variable Properties with XDb1
Archived from groups: comp>databases>object (more info?)

The following XDb1 example models things with variable properties. See
www.xdb1.com/Example/Ex109.asp for additional info.

Data to Model
-------------
wig1's color is red.
wig2's color is red, green AND texture is soft AND material is nylon.
wig3's texture is soft AND material is jute.

coat1's color is red.
coat2's texture is soft AND material is cotton.
coat3's color is green AND texture is smooth, supple.

Queries
-------
Find all things with attributes color and texture.
Print the property and values of all wigs.

void Example109()
{
// Create wig class
int* pWig = T_create();
T_relate(&pWig, rCls, &pThing_g);
T_Name_relate(&pWig, _T("wig"));

// Create coat class
int* pCoat = T_create();
T_relate(&pCoat, rCls, &pThing_g);
T_Name_relate(&pCoat, _T("coat"));

// Create color class
int* pColor = T_create();
T_relate(&pColor, rCls, &pThing_g);
T_Name_relate(&pColor, _T("color"));

// Create texture class
int* pTexture = T_create();
T_relate(&pTexture, rCls, &pThing_g);
T_Name_relate(&pTexture, _T("texture"));

// Create material class
int* pMaterial = T_create();
T_relate(&pMaterial, rCls, &pThing_g);
T_Name_relate(&pMaterial, _T("material"));

// Create wig1
// Its color is red.
int* pWig1 = T_create();
T_relate(&pWig1, rCls, &pWig);
T_Name_relate(&pWig1, _T("wig1"));
T_Val_relate(&pWig1, &pColor, _T("red"));

// Create wig2
// Its color is red, green
// AND texture is soft AND material is nylon.
int* pWig2 = T_create();
T_relate(&pWig2, rCls, &pWig);
T_Name_relate(&pWig2, _T("wig2"));
T_Val_relate(&pWig2, &pColor, _T("red"));
T_Val_relate(&pWig2, &pColor, _T("green"));
T_Val_relate(&pWig2, &pTexture, _T("soft"));
T_Val_relate(&pWig2, &pMaterial, _T("nylon"));

// Create wig3
// Its texture is soft AND material is jute.
int* pWig3 = T_create();
T_relate(&pWig3, rCls, &pWig);
T_Name_relate(&pWig3, _T("wig3"));
T_Val_relate(&pWig3, &pTexture, _T("soft"));
T_Val_relate(&pWig3, &pMaterial, _T("jute"));

// Create coat1
// Its color is red.
int* pCoat1 = T_create();
T_relate(&pCoat1, rCls, &pCoat);
T_Name_relate(&pCoat1, _T("coat1"));
T_Val_relate(&pCoat1, &pColor, _T("red"));

// Create coat2
// Its texture is soft AND material is cotton.
int* pCoat2 = T_create();
T_relate(&pCoat2, rCls, &pCoat);
T_Name_relate(&pCoat2, _T("coat2"));
T_Val_relate(&pCoat2, &pTexture, _T("soft"));
T_Val_relate(&pCoat2, &pMaterial, _T("cotton"));

// Create coat3
// Its color is green AND texture is smooth, supple.
int* pCoat3 = T_create();
T_relate(&pCoat3, rCls, &pCoat);
T_Name_relate(&pCoat3, _T("coat3"));
T_Val_relate(&pCoat3, &pColor, _T("green"));
T_Val_relate(&pCoat3, &pTexture, _T("smooth"));
T_Val_relate(&pCoat3, &pTexture, _T("supple"));

// Create a relational expression
// to find things related to color AND texture
TCHAR sExpr[kNmSz_g+1] = _T("((color)) ((texture))");

// Prepare relational expression
#define aSz 255
int* pExpr[aSz+1] = {NULL};
if (X_parse_r(sExpr, pExpr, aSz)) {return;}

// Loop thru distinct things satisfying expression
// and print thier full name.
// The loop below prints the following three lines
// "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))(((material))(nylon))"
// "((coat))(coat3)(((color))(green))(((texture))(smooth))(((texture))(supple))"
while (int* pT=X(pExpr, TRUE)){
TCHAR sName[kNmSz_g+1] = _T("");
T_Name_get(pT, sName, kNmSz_g, TRUE);
TRACE(_T("%s\n"), sName);
}

// Given wig1, print its info
// Prints "((wig))(wig1)(((color))(red))"
TCHAR sName[kNmSz_g+1] = _T("");
T_Name_get(pWig1, sName, kNmSz_g, TRUE);
TRACE(_T("%s\n"), sName);

// Given wig2, print its info
// Prints "((wig))(wig2)(((color))(red))(((color))(green))(((texture))(soft))(((material))(nylon))"
_tcscpy(sName, _T(""));
T_Name_get(pWig2, sName, kNmSz_g, TRUE);
TRACE(_T("%s\n"), sName);

// Given wig3, print its properties/values using alternate method
// "wig3's name is wig3."
// "wig3's texture is soft."
// "wig3's material is jute."
// Loop thru wig3's relations
int* pR = pWig3;
while (*(++pR)){
// If relation is to a value
if (rIs == R_Type_get(pR)){
// Get value
int* pVal = R_Dest(pR);

// Get value's Cls (same a property)
int* pProp = T_R_Xth(pVal, rCls);

// Print "thingX's propY is valX."
TCHAR sTh[kNmSz_g+1] = _T("");
T_Name_get(pWig3, sTh, kNmSz_g);

TCHAR sProp[kNmSz_g+1] = _T("");
T_Name_get(pProp, sProp, kNmSz_g);

TCHAR sVal[kNmSz_g+1] = _T("");
T_Name_get(pVal, sVal, kNmSz_g);

TCHAR sSent[3*kNmSz_g+1] = _T("");
_stprintf(sSent, _T("%s's %s is %s."), sTh, sProp, sVal);
TRACE(_T("%s\n"), sSent);
}
}
}

 >> Stay informed about: Modelling Variable Properties with XDb1 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Modelling Books (with XDb2) -

oops help - Question 1:- Describe the following with the help of examples: 1)Generalization and its role in Inheritance. 2)abstract Classes 3)State Diagrams. 4)OMT and its impact in programming. 5)future of Object Oriented languages. Qusetion2: -Identify the..

Idempotent ODBMS iterators - I am building a client/server ODBMS in Java. It occurred to me that one way of helping to guarantee the consistency of the database was to ensure that all atomic requests were idempotent -- that is, that if a particular request is performed more than..

Help Understanding OODBMS' - <font color=purple> ;> 3) Are relationships recorded in the same way as in an RDB - 1:M and</font> <font color=purple> ;> M:M? I assume that program code has to place the IDs in a "table" to</font> ...

CfP Reminder: The Second Scala Workshop - Scala Days 2011 - The Second Scala Workshop ========================= Call for Papers --------------- Scala is a general purpose programming language designed to express common programming patterns in a concise, elegant, and type-safe way. It smoothly integrates..
   Database Help (Home) -> Object-Oriented All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]