⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clipslibwrap_old.h

📁 clips专家系统内核打包类,很有参考性.
💻 H
字号:
#ifndef	_CLIPSWrap
	#define _CLIPSWrap
/////////////////////////////////////////////////////////////////////////////
// CCLIPSWrap defintion 

//CLIPS core code version
#define CLIPS_BUILD_VER 610
//define number of routes to handle
#define NUMROUTES		100
//define number of user routes to handle
// #define NUM_U_ROUTES	100
//define the maximum length of a fact string
#define MAX_FACT_LEN	640
//define max length of an item
#define MAX_ITEM_SIZE	640
//define max length of a list
#define MAX_LIST_SIZE	32000
//define number of iterations between msg pump calls
#define MAX_MSG_PUMP	1
//size of temp buffer variable
#define MBUFSIZE		1024

#ifndef __AFX_H__
	#include <afx.h>
#endif
#ifndef __AFXCOLL_H__
	#include <afxcoll.h>
#endif

#define DllExport	__declspec( dllexport )

//set this to 1 if you want ODBC support...
//remember to include rsvarcol.cpp into yor project as well
#define USE_ODBC 0
 #ifdef USE_ODBC
	#ifndef __AFXDB_H__
		#include <afxdb.h>
	#endif
	#ifndef _RSVARCOL_H_
		#include <rsvarcol.h>
	#endif
#endif

//prototype for route ordinal function
int GetRouteNum(int start, const char far* route);
//default router check function
bool IsDefaultRouter(const char *route);

//prototype for message pump callback
extern "C"	{
void DllExport MsgLoopProc(void);
}
#ifndef __defc
extern int Defcount;
#endif

//a handy macro to check for CLIPSInit and return something on fail
#define INITCHK(p)	if(!m_fClipsInit)	 {	\
						return p;}
//macro to clear the temp buffer
#define CLEARMBUF	memset(m_buf,0,MBUFSIZE);
#define SETMBUF(s)  CLEARMBUF strcpy(m_buf,s);
#define BOOLCHK(s)  (s) ? true : false

// just in case the CLIPS headers are not in 
// the preprocessor stack for this pass
#ifndef FACT_ADDRESS
	#define FACT_ADDRESS		6	
#endif
#ifndef INSTANCE_ADDRESS
	#define INSTANCE_ADDRESS	7
#endif

//the wrapper class
class CCLIPSWrap
{
	//CLIPS exception object
	class CLIPSException	{
		CString	Why;
	public:	//construction & destruction
		CLIPSException() {
			Why = "UnKnown";
		}
		CLIPSException(CString &Text)	{
			Why = Text;
		}
		CLIPSException(const char *szText)	{
			Why = szText;
		}
		virtual ~CLIPSException() {}

	public:	//methods
		void SetWhy(const char *szText)	{
			Why = szText;
		}
		void SetWhy(CString &Text)	{
			Why = Text;
		}
		const char *GetWhy()	{
			return (LPCSTR)Why;
		}
	};

public:
	//constructor and destructor are public
	CCLIPSWrap(int count = -1);
	virtual ~CCLIPSWrap(void);

//UserFunction return types
enum UDF_ReturnValues 
{
UDFReturn_External_Address = (unsigned) 'a',
UDFReturn_Boolean = (unsigned) 'b',
UDFReturn_Character = (unsigned) 'c',
UDFReturn_Double_Prec_Float = (unsigned) 'd',
UDFReturn_Single_Prec_Float = (unsigned) 'f',
UDFReturn_Integer = (unsigned) 'i',
UDFReturn_Symbol_String_or_InstanceName = (unsigned) 'j',
UDFReturn_Symbol_or_String = (unsigned) 'k',
UDFReturn_Long_Integer = (unsigned) 'l',
UDFReturn_Multifield = (unsigned) 'm',
UDFReturn_Integer_or_Float = (unsigned) 'n',
UDFReturn_Instance_Name = (unsigned) 'o',
UDFReturn_String = (unsigned) 's',
UDFReturn_Any = (unsigned) 'u',
UDFReturn_Void = (unsigned) 'v',
UDFReturn_Symbol = (unsigned) 'w',
UDFReturn_Instance_Address = (unsigned) 'x'
};

//Load file return codes
enum LoadStatus	{
	READ_FAIL,
	PARSE_FAIL,
	READ_OK,
	BAD_LOAD_NAME,
	READ_NOT_INIT,
	};

//Save file return codes
enum SaveStatus	{
	SAVE_FAIL,
	SAVE_OK,
	BAD_SAVE_NAME,
	SAVE_NOT_INIT,
	};

//class instance cases
enum InstanceCase	{
	I_PERIOD,
	I_SCOPE,
	I_CLASS
	};

// Attributes
protected:
	//CLIPS struct pointers
	//these are now (3.0) explicitly declared as the
	//correct pointer types rather than void *
	struct fact			*factPtr;
	struct defmodule	*modulePtr;
	struct defrule		*rulePtr;
	struct defglobal	*globalPtr;
	struct instance		*instancePtr;
	struct defclass		*classPtr;
	struct activation	*activationPtr;
	struct deftemplate	*templatePtr;
	struct instanceSlot *insSlotPtr;
	struct templateSlot *tempSlotPtr;
	//other internal stuff
	void* agendaPtr;
	FILE* fastLoad;
	FILE* fastSave;
	bool  m_fClipsInit;
	char  m_buf[MBUFSIZE];

// Operations
public:
	//this is our public interface to the rest of the CPP world
	void  SetMsgLoopCount(int ct)	{ Defcount = ct; }
	void  SetMsgLoopCBfn(void far (*func_ptr)(bool));
	//all of the member pointer accessors are now inline
	void  SetFactPtr(void *ptr = NULL)        { factPtr = (struct fact *)ptr; }
	void  SetRulePtr(void *ptr = NULL)        { rulePtr = (struct defrule*)ptr; }
	void  SetModulePtr(void *ptr = NULL)      { modulePtr = (struct defmodule*)ptr; }
	void  SetGlobalPtr(void *ptr = NULL)      { globalPtr = (struct defglobal*)ptr; }
	void  SetInstancePtr(void *ptr = NULL)    { instancePtr = (struct instance*)ptr; }
	void  SetClassPtr(void *ptr = NULL)       { classPtr = (struct defclass*)ptr; }
	void  SetAgendaPtr(void *ptr = NULL)      { agendaPtr = ptr; }
	void  SetTemplatePtr(void *ptr = NULL)    { templatePtr = (struct deftemplate*)ptr; }
	void  SetActivationPtr(void *ptr = NULL)  { activationPtr = (struct activation*)ptr; }
	void  SetErrorLog(CString & filename);
	void* GetFactPtr(void)       { return factPtr; }
	void* GetRulePtr(void)       { return rulePtr; }
	void* GetModulePtr(void)     { return modulePtr; }
	void* GetGlobalPtr(void)     { return globalPtr; }
	void* GetInstancePtr(void)   {return instancePtr; }
	void* GetClassPtr(void)      { return classPtr; }
	void* GetAgendaPtr(void)     { return agendaPtr; }
	void* GetActivationPtr(void) { return activationPtr; }
	void* GetTemplatePtr(void)	 { return templatePtr; }
	//defglobal functions
	bool		CLIPSGetNextDefglobal(void *pGlobal = NULL);
	bool		CLIPSFindDefglobal(CString & theVar);
	bool		CLIPSUndefglobal(void* Defglobal = NULL);
	bool 		SetConstruct(CString &theVar);
	float		GetDefglobalFloat(CString &name);
	int			GetDefglobalInt(CString &name);
	long int	GetDefglobalLong(CString &name);
const char far*	GetDefglobalString(CString &name);
	void*		GetDefglobalAddress(CString &name);
    bool        CLIPSParseDefglobal(CString &Source);
	//fact functions
 	bool		  CLIPSFindDeftemplate(CString &name);
	bool		  GetAllFacts(CStringArray &buffer);
	bool		  CLIPSNextFactString(CString& FactString, void *pFact = NULL);
	long int 	  CLIPSGetNumberOfFacts(void);
	bool		  CLIPSNextFact(void *pFact = NULL);
	bool		  CLIPSFactString(CString &Data, void *pFact = NULL);
	int			  CLIPSSetFactDup(int value = 0);
	bool		  CLIPSGetFactDup(void);
	bool		  CLIPSAssert(CString &String);
	bool		  CLIPSAssert(void* Fact = NULL);
	bool		  CLIPSIncrementFactCtr(void* Fact = NULL);
	bool		  CLIPSDecrementFactCtr(void* Fact = NULL);
	bool		  CLIPSGetFactListChanged(void);
	bool		  CLIPSSetFactListChanged(bool Value = false);
	bool		  AddFactArray(CStringArray& List, int NumFacts = 0);
	bool		  CLIPSCreateFact(void* tPtr = NULL);
	bool		  CLIPSAssignFactSlotDefaults(void *theFact = NULL);
	//misc
	CStringArray *SetRouteBuffer(CStringArray* pBuffer, CString &Route, bool remove = false);
	CStringArray *SetRouteBuffer(CStringArray* pBuffer, const char *pRoute, bool remove = false);
	bool		  SetRouteFile(CString& RouteName, CString& FileName);		
	bool		  SetRouteFile(CString& RouteName, const char far* FileName);		
	bool 		  CLIPSAgenda(CString& Routename);
	bool		  CLIPSInit(void);
	bool 		  CLIPSReset(void);
	void 		  CLIPSExit(int retVal = 1);
	long int 	  CLIPSRun(long int numIterations = -1);
	bool 		  CLIPSClear(void);
	bool		  CLIPSRetract(void *Fact = NULL);
	bool		  CLIPSWatch(CString &Item);
	bool		  CLIPSUnWatch(CString &Item);
	bool		  CLIPSMatches(void *Rule = NULL);
	bool 		  CLIPSGetCurrentModule(void);
	void		  MultifieldToString(CString &buffer, struct multifield *segment, int printParens);
	//file functions
	int 		  CLIPSLoad(CString &scriptFile);
	int			  CLIPSSave(CString &Filename);
	int 		  CLIPSBSave(CString &BinName);
	int 		  CLIPSBLoad(CString &BinName);
	int			  CLIPSSaveFacts(CString &FileName, bool Visable = TRUE);
	int			  CLIPSLoadFacts(CString &FileName);
	bool		  CLIPSDribble(CString &FileName, bool Switch = FALSE);
	//instance functions
	bool		  GetInstanceSlotName(CString &name, void *pSlot);
	bool		  CLIPSGetNextInstance(int Which = 0,void* Class = NULL);
	bool		  CLIPSMakeInstance(CString &Data);
	bool		  CLIPSFindInstance(CString &Name, bool SearchImports = FALSE);
	bool		  CLIPSDeleteInstance(void* Instance = NULL);
	bool 		  DeleteAllInstances(void);
	bool		  CLIPSGetInstanceClass(void* Instance = NULL);
	bool		  CLIPSGetNextInstanceInClass(void *pClass = NULL);
	bool		  CLIPSGetInstanceName(CString &Data, void* Instance = NULL);
	bool		  CLIPSGetInstanceData(CString &Data, void* Instance = NULL);
	bool		  CLIPSGetInstancePPForm(CString &Data, void *pInst = NULL);
	bool		  CLIPSCreateRawInstance(CString &Name, void *pClass = NULL);
	bool		  CLIPSValidInstance(void* Instance = NULL);
	bool		  CLIPSDirectGetSlot(CString &Class, CString &Slot, CString &Value);
	bool		  CLIPSDirectPutSlot(CString &Class, CString &Slot, CString &Value, int type = -1);
	long		  GetSlotCount(void *pFact, bool IsFact);
unsigned long int CLIPSGetGlobalNumberOfInstances(void);
	long int	  CLIPSLoadInstances(CString &FileName);
	long int	  CLIPSSaveInstances(CString &FileName, bool Visable = FALSE);
	bool 		  SetSlotValue(CString &Class, CString &Slot, CString &Value);
	bool 		  GetSlotValue(CString &Class, CString &Slot, CString &Value);
	bool		  ReadFactSlot(CString &Slot, CString &Data, void *pFact = NULL);
	bool		  WriteFactSlot(CString&Slot, CString &Data, int type, void *pFact = NULL);
	long		  GetInstanceSlotType(void *pSlot = NULL);
	void*         GetInstanceSlot(CString &name, void *pInstance = NULL);
	bool	 	  CLIPSRouteCommand(CString &Command, CString &route, int do_print = 1);
	long int	  CLIPSGetStrategy(void);
	long int	  CLIPSSetStrategy(long int data = 0);
	void*		  CLIPSAddSymbol(CString &Symbol);
	void*		  CLIPSAddLong(long int lValue);
	void*		  CLIPSAddDouble(double dValue);
	long int	  CLIPSMemoryUsed(void);
	long int	  CLIPSMemoryRequests(void);
	bool		  CLIPSGetFocus(void);
	bool		  CLIPSRemoveAllFacts(void);
	long int	  CLIPSMemUsed(void);
	bool		  CLIPSBatch(CString &FileName);
	bool		  CLIPSBatchStar(CString &FileName);
	void		  CLIPSFreeMem(void);
	void		  CLIPSSetHaltExecution(bool);
	bool		  CLIPSGetHaltExecution(void);
    int           Version(void);
	bool		  CLIPSGetNextDefclass(void* pClass = NULL);
	bool		  CLIPSGetNextActivation(void* pAct = NULL);
	bool		  CLIPSSend(CString &Msg, CString &Args, CString &InsName, CString &RetStr);
	bool		  CLIPSBuild(CString& Command);
	bool		  CLIPSAddResetFunction(const char *szCLIPSFunctionName, void(*pFunction)(void), int iPriorityValue);
#if USE_ODBC
	int					CLIPSODBCQuery(CString& Query, CString& Credentials, CString& DeftemplateName, bool bImplode);
	BOOL				CLIPSODBCQuery(CString& Query, CString& Credentials, CString& DeftemplateName, bool bImplode, CString& strError);
	BOOL				CLIPSODBCQuery(CString& Query, CDatabase& DataSource, CString& DeftemplateName, bool bImplode, CString& strError);
#endif
	bool				AddFunction(const char *szCLIPSFunctionName, char cReturnType, int (*pFunction)(void), const char *szFunctionName, const char *szParameterTypes);
	int					CLIPSRtnArgCount(void);
	int					CLIPSArgCountCheck(CString& FunctionName, int iRestriction, int iCount);
	bool				CLIPSArgTypeCheck(CString& FunctionName, int iPos, int iType, void *pDataObject);
	char			   *CLIPSRtnLexeme(int iPos);
	double				CLIPSRtnDouble(int iPos);
	long int			CLIPSRtnLong(int iPos);
	void			   *CLIPSRtnUnknown(int iPos, void *DataObject);
	void			   *CLIPSCreateMultifield(int iSize);
	void				CLIPSSetMultifieldErrorValue(void *pMultifield);
private:
	char *    GetGlobal(CString & name);
#if USE_ODBC
	bool	  IssueODBCQuery(CVarRecordset& rsODBC, CString& strDeftemplateName, CString& strFact, bool bImplode);
#endif

};

/////////////////////////////////////////////////////////////////////////////
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -