1    /*******************************************************/
2    /*      "C" Language Integrated Production System      */
3    /*                                                     */
4    /*             CLIPS Version 6.30  01/25/15            */
5    /*                                                     */
6    /*               DEFTEMPLATE HEADER FILE               */
7    /*******************************************************/
8 
9 /*************************************************************/
10 /* Purpose:                                                  */
11 /*                                                           */
12 /* Principal Programmer(s):                                  */
13 /*      Gary D. Riley                                        */
14 /*                                                           */
15 /* Contributing Programmer(s):                               */
16 /*      Brian L. Dantes                                      */
17 /*                                                           */
18 /* Revision History:                                         */
19 /*                                                           */
20 /*      6.23: Added support for templates maintaining their  */
21 /*            own list of facts.                             */
22 /*                                                           */
23 /*      6.24: Renamed BOOLEAN macro type to intBool.         */
24 /*                                                           */
25 /*            Corrected code to remove run-time program      */
26 /*            compiler warnings.                             */
27 /*                                                           */
28 /*      6.30: Added code for deftemplate run time            */
29 /*            initialization of hashed comparisons to        */
30 /*            constants.                                     */
31 /*                                                           */
32 /*            Removed conditional code for unsupported       */
33 /*            compilers/operating systems (IBM_MCW,          */
34 /*            MAC_MCW, and IBM_TBC).                         */
35 /*                                                           */
36 /*            Support for deftemplate slot facets.           */
37 /*                                                           */
38 /*            Added const qualifiers to remove C++           */
39 /*            deprecation warnings.                          */
40 /*                                                           */
41 /*            Converted API macros to function calls.        */
42 /*                                                           */
43 /*            Changed find construct functionality so that   */
44 /*            imported modules are search when locating a    */
45 /*            named construct.                               */
46 /*                                                           */
47 /*************************************************************/
48 
49 #ifndef _H_tmpltdef
50 #define _H_tmpltdef
51 
52 struct deftemplate;
53 struct templateSlot;
54 struct deftemplateModule;
55 
56 #ifndef _H_conscomp
57 #include "conscomp.h"
58 #endif
59 #ifndef _H_symbol
60 #include "symbol.h"
61 #endif
62 #ifndef _H_expressn
63 #include "expressn.h"
64 #endif
65 #ifndef _H_evaluatn
66 #include "evaluatn.h"
67 #endif
68 #ifndef _H_constrct
69 #include "constrct.h"
70 #endif
71 #ifndef _H_moduldef
72 #include "moduldef.h"
73 #endif
74 #ifndef _H_constrnt
75 #include "constrnt.h"
76 #endif
77 #include "factbld.h"
78 #ifndef _H_factmngr
79 #include "factmngr.h"
80 #endif
81 #ifndef _H_cstrccom
82 #include "cstrccom.h"
83 #endif
84 
85 struct deftemplate
86   {
87    struct constructHeader header;
88    struct templateSlot *slotList;
89    unsigned int implied       : 1;
90    unsigned int watch         : 1;
91    unsigned int inScope       : 1;
92    unsigned short numberOfSlots;
93    long busyCount;
94    struct factPatternNode *patternNetwork;
95    struct fact *factList;
96    struct fact *lastFact;
97   };
98 
99 struct templateSlot
100   {
101    struct symbolHashNode *slotName;
102    unsigned int multislot : 1;
103    unsigned int noDefault : 1;
104    unsigned int defaultPresent : 1;
105    unsigned int defaultDynamic : 1;
106    CONSTRAINT_RECORD *constraints;
107    struct expr *defaultList;
108    struct expr *facetList;
109    struct templateSlot *next;
110   };
111 
112 struct deftemplateModule
113   {
114    struct defmoduleItemHeader header;
115   };
116 
117 #define DEFTEMPLATE_DATA 5
118 
119 struct deftemplateData
120   {
121    struct construct *DeftemplateConstruct;
122    int DeftemplateModuleIndex;
123    struct entityRecord DeftemplatePtrRecord;
124 #if DEBUGGING_FUNCTIONS
125    int DeletedTemplateDebugFlags;
126 #endif
127 #if CONSTRUCT_COMPILER && (! RUN_TIME)
128    struct CodeGeneratorItem *DeftemplateCodeItem;
129 #endif
130 #if (! RUN_TIME) && (! BLOAD_ONLY)
131    int DeftemplateError;
132 #endif
133   };
134 
135 #define DeftemplateData(theEnv) ((struct deftemplateData *) GetEnvironmentData(theEnv,DEFTEMPLATE_DATA))
136 
137 #ifdef LOCALE
138 #undef LOCALE
139 #endif
140 
141 #ifdef _TMPLTDEF_SOURCE_
142 #define LOCALE
143 #else
144 #define LOCALE extern
145 #endif
146 
147    LOCALE void                           InitializeDeftemplates(void *);
148    LOCALE void                          *EnvFindDeftemplate(void *,const char *);
149    LOCALE void                          *EnvFindDeftemplateInModule(void *,const char *);
150    LOCALE void                          *EnvGetNextDeftemplate(void *,void *);
151    LOCALE intBool                        EnvIsDeftemplateDeletable(void *,void *);
152    LOCALE void                          *EnvGetNextFactInTemplate(void *,void *,void *);
153    LOCALE struct deftemplateModule      *GetDeftemplateModuleItem(void *,struct defmodule *);
154    LOCALE void                           ReturnSlots(void *,struct templateSlot *);
155    LOCALE void                           IncrementDeftemplateBusyCount(void *,void *);
156    LOCALE void                           DecrementDeftemplateBusyCount(void *,void *);
157    LOCALE void                          *CreateDeftemplateScopeMap(void *,struct deftemplate *);
158 #if RUN_TIME
159    LOCALE void                           DeftemplateRunTimeInitialize(void *);
160 #endif
161    LOCALE const char                    *EnvDeftemplateModule(void *,void *);
162    LOCALE const char                    *EnvGetDeftemplateName(void *,void *);
163    LOCALE const char                    *EnvGetDeftemplatePPForm(void *,void *);
164 
165 #if ALLOW_ENVIRONMENT_GLOBALS
166 
167    LOCALE const char                    *DeftemplateModule(void *);
168    LOCALE void                          *FindDeftemplate(const char *);
169    LOCALE const char                    *GetDeftemplateName(void *);
170    LOCALE const char                    *GetDeftemplatePPForm(void *);
171    LOCALE void                          *GetNextDeftemplate(void *);
172    LOCALE intBool                        IsDeftemplateDeletable(void *);
173    LOCALE void                          *GetNextFactInTemplate(void *,void *);
174 
175 #endif /* ALLOW_ENVIRONMENT_GLOBALS */
176 
177 #endif /* _H_tmpltdef */
178 
179 
180