?? factmngr.c
字號:
/*===============================*/ /* Return a pointer to the fact. */ /*===============================*/ return((void *) theFact); }/**************************************//* RemoveAllFacts: Loops through the *//* fact-list and removes each fact. *//**************************************/globle void RemoveAllFacts( void *theEnv) { while (FactData(theEnv)->FactList != NULL) { EnvRetract(theEnv,(void *) FactData(theEnv)->FactList); } }/************************************************//* EnvCreateFact: Creates a fact data structure *//* of the specified deftemplate. *//************************************************/globle struct fact *EnvCreateFact( void *theEnv, void *vTheDeftemplate) { struct deftemplate *theDeftemplate = (struct deftemplate *) vTheDeftemplate; struct fact *newFact; int i; /*=================================*/ /* A deftemplate must be specified */ /* in order to create a fact. */ /*=================================*/ if (theDeftemplate == NULL) return(NULL); /*============================================*/ /* Create a fact for an explicit deftemplate. */ /*============================================*/ if (theDeftemplate->implied == FALSE) { newFact = CreateFactBySize(theEnv,theDeftemplate->numberOfSlots); for (i = 0; i < (int) theDeftemplate->numberOfSlots; i++) { newFact->theProposition.theFields[i].type = RVOID; } } /*===========================================*/ /* Create a fact for an implied deftemplate. */ /*===========================================*/ else { newFact = CreateFactBySize(theEnv,1); newFact->theProposition.theFields[0].type = MULTIFIELD; newFact->theProposition.theFields[0].value = CreateMultifield2(theEnv,0L); } /*===============================*/ /* Return a pointer to the fact. */ /*===============================*/ newFact->whichDeftemplate = theDeftemplate; return(newFact); }/******************************************//* EnvGetFactSlot: Returns the slot value *//* from the specified slot of a fact. *//******************************************/globle intBool EnvGetFactSlot( void *theEnv, void *vTheFact, char *slotName, DATA_OBJECT *theValue) { struct fact *theFact = (struct fact *) vTheFact; struct deftemplate *theDeftemplate; short whichSlot; /*===============================================*/ /* Get the deftemplate associated with the fact. */ /*===============================================*/ theDeftemplate = theFact->whichDeftemplate; /*==============================================*/ /* Handle retrieving the slot value from a fact */ /* having an implied deftemplate. An implied */ /* facts has a single multifield slot. */ /*==============================================*/ if (theDeftemplate->implied) { if (slotName != NULL) return(FALSE); theValue->type = theFact->theProposition.theFields[0].type; theValue->value = theFact->theProposition.theFields[0].value; SetpDOBegin(theValue,1); SetpDOEnd(theValue,((struct multifield *) theValue->value)->multifieldLength); return(TRUE); } /*===================================*/ /* Make sure the slot name requested */ /* corresponds to a valid slot name. */ /*===================================*/ if (FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&whichSlot) == NULL) { return(FALSE); } /*======================================================*/ /* Return the slot value. If the slot value wasn't set, */ /* then return FALSE to indicate that an appropriate */ /* slot value wasn't available. */ /*======================================================*/ theValue->type = theFact->theProposition.theFields[whichSlot-1].type; theValue->value = theFact->theProposition.theFields[whichSlot-1].value; if (theValue->type == MULTIFIELD) { SetpDOBegin(theValue,1); SetpDOEnd(theValue,((struct multifield *) theValue->value)->multifieldLength); } if (theValue->type == RVOID) return(FALSE); return(TRUE); }/***************************************//* EnvPutFactSlot: Sets the slot value *//* of the specified slot of a fact. *//***************************************/globle intBool EnvPutFactSlot( void *theEnv, void *vTheFact, char *slotName, DATA_OBJECT *theValue) { struct fact *theFact = (struct fact *) vTheFact; struct deftemplate *theDeftemplate; struct templateSlot *theSlot; short whichSlot; /*===============================================*/ /* Get the deftemplate associated with the fact. */ /*===============================================*/ theDeftemplate = theFact->whichDeftemplate; /*============================================*/ /* Handle setting the slot value of a fact */ /* having an implied deftemplate. An implied */ /* facts has a single multifield slot. */ /*============================================*/ if (theDeftemplate->implied) { if ((slotName != NULL) || (theValue->type != MULTIFIELD)) { return(FALSE); } if (theFact->theProposition.theFields[0].type == MULTIFIELD) { ReturnMultifield(theEnv,(struct multifield *) theFact->theProposition.theFields[0].value); } theFact->theProposition.theFields[0].type = theValue->type; theFact->theProposition.theFields[0].value = DOToMultifield(theEnv,theValue); return(TRUE); } /*===================================*/ /* Make sure the slot name requested */ /* corresponds to a valid slot name. */ /*===================================*/ if ((theSlot = FindSlot(theDeftemplate,(SYMBOL_HN *) EnvAddSymbol(theEnv,slotName),&whichSlot)) == NULL) { return(FALSE); } /*=============================================*/ /* Make sure a single field value is not being */ /* stored in a multifield slot or vice versa. */ /*=============================================*/ if (((theSlot->multislot == 0) && (theValue->type == MULTIFIELD)) || ((theSlot->multislot == 1) && (theValue->type != MULTIFIELD))) { return(FALSE); } /*=====================*/ /* Set the slot value. */ /*=====================*/ if (theFact->theProposition.theFields[whichSlot-1].type == MULTIFIELD) { ReturnMultifield(theEnv,(struct multifield *) theFact->theProposition.theFields[whichSlot-1].value); } theFact->theProposition.theFields[whichSlot-1].type = theValue->type; if (theValue->type == MULTIFIELD) { theFact->theProposition.theFields[whichSlot-1].value = DOToMultifield(theEnv,theValue); } else { theFact->theProposition.theFields[whichSlot-1].value = theValue->value; } return(TRUE); }/********************************************************//* EnvAssignFactSlotDefaults: Sets a fact's slot values *//* to its default value if the value of the slot has *//* not yet been set. *//********************************************************/globle intBool EnvAssignFactSlotDefaults( void *theEnv, void *vTheFact) { struct fact *theFact = (struct fact *) vTheFact; struct deftemplate *theDeftemplate; struct templateSlot *slotPtr; int i; DATA_OBJECT theResult; /*===============================================*/ /* Get the deftemplate associated with the fact. */ /*===============================================*/ theDeftemplate = theFact->whichDeftemplate; /*================================================*/ /* The value for the implied multifield slot of */ /* an implied deftemplate is set to a multifield */ /* of length zero when the fact is created. */ /*================================================*/ if (theDeftemplate->implied) return(TRUE); /*============================================*/ /* Loop through each slot of the deftemplate. */ /*============================================*/ for (i = 0, slotPtr = theDeftemplate->slotList; i < (int) theDeftemplate->numberOfSlots; i++, slotPtr = slotPtr->next) { /*===================================*/ /* If the slot's value has been set, */ /* then move on to the next slot. */ /*===================================*/ if (theFact->theProposition.theFields[i].type != RVOID) continue; /*======================================================*/ /* Assign the default value for the slot if one exists. */ /*======================================================*/ if (DeftemplateSlotDefault(theEnv,theDeftemplate,slotPtr,&theResult,FALSE)) { theFact->theProposition.theFields[i].type = theResult.type; theFact->theProposition.theFields[i].value = theResult.value; } } /*==========================================*/ /* Return TRUE to indicate that the default */ /* values have been successfully set. */ /*==========================================*/ return(TRUE); } /********************************************************//* DeftemplateSlotDefault: Determines the default value *//* for the specified slot of a deftemplate. *//********************************************************/globle intBool DeftemplateSlotDefault( void *theEnv, struct deftemplate *theDeftemplate, struct templateSlot *slotPtr, DATA_OBJECT *theResult, int garbageMultifield) { /*================================================*/ /* The value for the implied multifield slot of an */ /* implied deftemplate does not have a default. */ /*=================================================*/ if (theDeftemplate->implied) return(FALSE); /*===============================================*/ /* If the (default ?NONE) attribute was declared */ /* for the slot, then return FALSE to indicate */ /* the default values for the fact couldn't be */ /* supplied since this attribute requires that a */ /* default value can't be used for the slot. */ /*===============================================*/ if (slotPtr->noDefault) return(FALSE); /*==============================================*/ /* Otherwise if a static default was specified, */ /* use this as the default value. */ /*==============================================*/ else if (slotPtr->defaultPresent) { if (slotPtr->multislot) { StoreInMultifield(theEnv,theResult,slotPtr->defaultList,garbageMultifield); } else { theResult->type = slotPtr->defaultList->type; theResult->value = slotPtr->defaultList->value; } } /*================================================*/ /* Otherwise if a dynamic-default was specified, */ /* evaluate it and use this as the default value. */ /*================================================*/ else if (slotPtr->defaultDynamic) { if (! EvaluateAndStoreInDataObject(theEnv,(int) slotPtr->multislot, (EXPRESSION *) slotPtr->defaultList, theResult,garbageMultifield)) { return(FALSE); } } /*====================================*/ /* Otherwise derive the default value */ /* from the slot's constraints. */ /*====================================*/ else { DeriveDefaultFromConstraints(theEnv,slotPtr->constraints,theResult, (int) slotPtr->multislot,garbageMultifield); } /*==========================================*/ /* Return TRUE to indicate that the default */ /* values have been successfully set. */ /*==========================================*/ return(TRUE); }/***************************************************************//* CopyFactSlotValues: Copies the slot values from one fact to *//* another. Both facts must have the same relation name. *//***************************************************************/globle intBool CopyFactSlotValues( void *theEnv, void *vTheDestFact, void *vTheSourceFact) { struct fact *theDestFact = (struct fact *) vTheDestFact; struct fact *theSourceFact = (struct fact *) vTheSourceFact; struct deftemplate *theDeftemplate; struct templateSlot *slotPtr; int i; /*===================================*/ /* Both facts must be the same type. */ /*===================================*/ theDeftemplate = theSourceFact->whichDeftemplate; if (theDestFact->whichDeftemplate != theDeftemplate) { return(FALSE); } /*===================================================*/ /* Loop through each slot of the deftemplate copying */ /* the source fact value to the destination fact. */ /*===================================================*/ for (i = 0, slotPtr = theDeftemplate->slotList; i < (int) theDeftemplate->numberOfSlots; i++, slotPtr = slotPtr->next) { theDestFact->theProposition.theFields[i].type = theSourceFact->theProposition.theFields[i].type; if (theSourceFact->theProposition.theFields[i].type != MULTIFIELD) { theDestFact->theProposition.theFields[i].value = theSourceFact->theProposition.theFields[i].value; } else { theDestFact->theProposition.theFields[i].value = CopyMultifield(theEnv,(struct multifield *) theSourceFact->theProposition.theFields[i].value); } } /*========================================*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -