1 /*******************************************************/ 2 /* "C" Language Integrated Production System */ 3 /* */ 4 /* CLIPS Version 6.30 02/04/15 */ 5 /* */ 6 /* FACTS MANAGER HEADER FILE */ 7 /*******************************************************/ 8 9 /*************************************************************/ 10 /* Purpose: */ 11 /* */ 12 /* Principal Programmer(s): */ 13 /* Gary D. Riley */ 14 /* */ 15 /* Contributing Programmer(s): */ 16 /* */ 17 /* Revision History: */ 18 /* */ 19 /* 6.23: Added support for templates maintaining their */ 20 /* own list of facts. */ 21 /* */ 22 /* 6.24: Removed LOGICAL_DEPENDENCIES compilation flag. */ 23 /* */ 24 /* Renamed BOOLEAN macro type to intBool. */ 25 /* */ 26 /* AssignFactSlotDefaults function does not */ 27 /* properly handle defaults for multifield slots. */ 28 /* DR0869 */ 29 /* */ 30 /* Support for ppfact command. */ 31 /* */ 32 /* 6.30: Callback function support for assertion, */ 33 /* retraction, and modification of facts. */ 34 /* */ 35 /* Updates to fact pattern entity record. */ 36 /* */ 37 /* Changed integer type/precision. */ 38 /* */ 39 /* Changed garbage collection algorithm. */ 40 /* */ 41 /* Removed conditional code for unsupported */ 42 /* compilers/operating systems (IBM_MCW, */ 43 /* MAC_MCW, and IBM_TBC). */ 44 /* */ 45 /* Added const qualifiers to remove C++ */ 46 /* deprecation warnings. */ 47 /* */ 48 /* Converted API macros to function calls. */ 49 /* */ 50 /* Removed unused global variables. */ 51 /* */ 52 /* Added code to prevent a clear command from */ 53 /* being executed during fact assertions via */ 54 /* JoinOperationInProgress mechanism. */ 55 /* */ 56 /*************************************************************/ 57 58 #ifndef _H_factmngr 59 60 #define _H_factmngr 61 62 struct fact; 63 64 #ifndef _H_facthsh 65 #include "facthsh.h" 66 #endif 67 #ifndef _H_conscomp 68 #include "conscomp.h" 69 #endif 70 #ifndef _H_pattern 71 #include "pattern.h" 72 #endif 73 #include "multifld.h" 74 #ifndef _H_evaluatn 75 #include "evaluatn.h" 76 #endif 77 #ifndef _H_tmpltdef 78 #include "tmpltdef.h" 79 #endif 80 81 struct fact 82 { 83 struct patternEntity factHeader; 84 struct deftemplate *whichDeftemplate; 85 void *list; 86 long long factIndex; 87 unsigned long hashValue; 88 unsigned int garbage : 1; 89 struct fact *previousFact; 90 struct fact *nextFact; 91 struct fact *previousTemplateFact; 92 struct fact *nextTemplateFact; 93 struct multifield theProposition; 94 }; 95 96 #define FACTS_DATA 3 97 98 struct factsData 99 { 100 int ChangeToFactList; 101 #if DEBUGGING_FUNCTIONS 102 unsigned WatchFacts; 103 #endif 104 struct fact DummyFact; 105 struct fact *GarbageFacts; 106 struct fact *LastFact; 107 struct fact *FactList; 108 long long NextFactIndex; 109 unsigned long NumberOfFacts; 110 struct callFunctionItemWithArg *ListOfAssertFunctions; 111 struct callFunctionItemWithArg *ListOfRetractFunctions; 112 struct callFunctionItemWithArg *ListOfModifyFunctions; 113 struct patternEntityRecord FactInfo; 114 #if (! RUN_TIME) && (! BLOAD_ONLY) 115 struct deftemplate *CurrentDeftemplate; 116 #endif 117 #if DEFRULE_CONSTRUCT && (! RUN_TIME) && DEFTEMPLATE_CONSTRUCT && CONSTRUCT_COMPILER 118 struct CodeGeneratorItem *FactCodeItem; 119 #endif 120 struct factHashEntry **FactHashTable; 121 unsigned long FactHashTableSize; 122 intBool FactDuplication; 123 #if DEFRULE_CONSTRUCT 124 struct fact *CurrentPatternFact; 125 struct multifieldMarker *CurrentPatternMarks; 126 #endif 127 long LastModuleIndex; 128 }; 129 130 #define FactData(theEnv) ((struct factsData *) GetEnvironmentData(theEnv,FACTS_DATA)) 131 132 #ifdef LOCALE 133 #undef LOCALE 134 #endif 135 #ifdef _FACTMNGR_SOURCE_ 136 #define LOCALE 137 #else 138 #define LOCALE extern 139 #endif 140 141 LOCALE void *EnvAssert(void *,void *); 142 LOCALE void *EnvAssertString(void *,const char *); 143 LOCALE struct fact *EnvCreateFact(void *,void *); 144 LOCALE void EnvDecrementFactCount(void *,void *); 145 LOCALE long long EnvFactIndex(void *,void *); 146 LOCALE intBool EnvGetFactSlot(void *,void *,const char *,DATA_OBJECT *); 147 LOCALE void PrintFactWithIdentifier(void *,const char *,struct fact *); 148 LOCALE void PrintFact(void *,const char *,struct fact *,int,int); 149 LOCALE void PrintFactIdentifierInLongForm(void *,const char *,void *); 150 LOCALE intBool EnvRetract(void *,void *); 151 LOCALE void RemoveAllFacts(void *); 152 LOCALE struct fact *CreateFactBySize(void *,unsigned); 153 LOCALE void FactInstall(void *,struct fact *); 154 LOCALE void FactDeinstall(void *,struct fact *); 155 LOCALE void *EnvGetNextFact(void *,void *); 156 LOCALE void *GetNextFactInScope(void *theEnv,void *); 157 LOCALE void EnvGetFactPPForm(void *,char *,size_t,void *); 158 LOCALE int EnvGetFactListChanged(void *); 159 LOCALE void EnvSetFactListChanged(void *,int); 160 LOCALE unsigned long GetNumberOfFacts(void *); 161 LOCALE void InitializeFacts(void *); 162 LOCALE struct fact *FindIndexedFact(void *,long long); 163 LOCALE void EnvIncrementFactCount(void *,void *); 164 LOCALE void PrintFactIdentifier(void *,const char *,void *); 165 LOCALE void DecrementFactBasisCount(void *,void *); 166 LOCALE void IncrementFactBasisCount(void *,void *); 167 LOCALE intBool FactIsDeleted(void *,void *); 168 LOCALE void ReturnFact(void *,struct fact *); 169 LOCALE void MatchFactFunction(void *,void *); 170 LOCALE intBool EnvPutFactSlot(void *,void *,const char *,DATA_OBJECT *); 171 LOCALE intBool EnvAssignFactSlotDefaults(void *,void *); 172 LOCALE intBool CopyFactSlotValues(void *,void *,void *); 173 LOCALE intBool DeftemplateSlotDefault(void *,struct deftemplate *, 174 struct templateSlot *,DATA_OBJECT *,int); 175 LOCALE intBool EnvAddAssertFunction(void *,const char *, 176 void (*)(void *,void *),int); 177 LOCALE intBool EnvAddAssertFunctionWithContext(void *,const char *, 178 void (*)(void *,void *),int,void *); 179 LOCALE intBool EnvRemoveAssertFunction(void *,const char *); 180 LOCALE intBool EnvAddRetractFunction(void *,const char *, 181 void (*)(void *,void *),int); 182 LOCALE intBool EnvAddRetractFunctionWithContext(void *,const char *, 183 void (*)(void *,void *),int,void *); 184 LOCALE intBool EnvRemoveRetractFunction(void *,const char *); 185 LOCALE intBool EnvAddModifyFunction(void *,const char *, 186 void (*)(void *,void *,void *),int); 187 LOCALE intBool EnvAddModifyFunctionWithContext(void *,const char *, 188 void (*)(void *,void *,void *),int,void *); 189 LOCALE intBool EnvRemoveModifyFunction(void *,const char *); 190 191 192 #if ALLOW_ENVIRONMENT_GLOBALS 193 194 LOCALE intBool AddAssertFunction(const char *,void (*)(void *,void *),int); 195 LOCALE intBool AddModifyFunction(const char *,void (*)(void *,void *,void *),int); 196 LOCALE intBool AddRetractFunction(const char *,void (*)(void *,void *),int); 197 LOCALE void *Assert(void *); 198 LOCALE void *AssertString(const char *); 199 LOCALE intBool AssignFactSlotDefaults(void *); 200 LOCALE struct fact *CreateFact(void *); 201 LOCALE void DecrementFactCount(void *); 202 LOCALE long long FactIndex(void *); 203 LOCALE int GetFactListChanged(void); 204 LOCALE void GetFactPPForm(char *,unsigned,void *); 205 LOCALE intBool GetFactSlot(void *,const char *,DATA_OBJECT *); 206 LOCALE void *GetNextFact(void *); 207 LOCALE void IncrementFactCount(void *); 208 LOCALE intBool PutFactSlot(void *,const char *,DATA_OBJECT *); 209 LOCALE intBool RemoveAssertFunction(const char *); 210 LOCALE intBool RemoveModifyFunction(const char *); 211 LOCALE intBool RemoveRetractFunction(const char *); 212 LOCALE intBool Retract(void *); 213 LOCALE void SetFactListChanged(int); 214 215 #endif /* ALLOW_ENVIRONMENT_GLOBALS */ 216 217 #endif /* _H_factmngr */ 218 219 220 221 222 223