📄 clipsmfc_old.cpp
字号:
Function : CCLIPSWrap::CLIPSGetStrategy(void)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function GetStrategy():
Returns : GetStrategy return value or -1 on error
****************************************************************************/
long int CCLIPSWrap::CLIPSGetStrategy(void)
{
INITCHK(-1L)
return (dl_GetStrategy)();
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSAddSymbol(CString& Symbol)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function AddSymbol():
Returns : pointer to symbol, NULL on error
****************************************************************************/
void* CCLIPSWrap::CLIPSAddSymbol(CString& Symbol)
{
INITCHK(NULL)
if(Symbol.IsEmpty()) {
return NULL;
}
SETMBUF((LPCSTR)Symbol)
return (dl_AddSymbol)(m_buf);
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSAddLong(long int lValue)
Author : Michael Giordano
Desc. : Accessor for CLIPS function AddLong()
Arguments : lValue = Value to add to Multifield
Returns : Pointer to new long int Multifield Value
****************************************************************************/
void *CCLIPSWrap::CLIPSAddLong(long int lValue)
{
INITCHK(NULL)
return(dl_AddLong)(lValue);
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSAddDouble(Double dValue)
Author : Michael Giordano
Desc. : Accessor for CLIPS function AddDouble()
Arguments : dValue = Value to add to Multifield
Returns : Pointer to new double Multifield Value
****************************************************************************/
void *CCLIPSWrap::CLIPSAddDouble(double dValue)
{
INITCHK(NULL)
return(dl_AddDouble)(dValue);
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSMemoryUsed(void)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function MemUsed():
Returns : return value from MemUsed() or -1 on error
****************************************************************************/
long int CCLIPSWrap::CLIPSMemoryUsed(void)
{
INITCHK(false)
return (dl_MemUsed)();
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSMemoryRequests(void)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function MemRequests():
Returns : return value from MemRequests() or -1 on error
****************************************************************************/
long int CCLIPSWrap::CLIPSMemoryRequests(void)
{
INITCHK(-1L)
return (dl_MemRequests)();
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSGetFocus(void)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function WRGetFocus(), updates modulePtr
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::CLIPSGetFocus(void)
{
INITCHK(false)
modulePtr = (struct defmodule *) (dl_WRGetFocus)();
if(modulePtr == NULL) {
return false;
}
return true;
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSRemoveAllFacts(void)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function RemoveAllFacts(),
updates factPtr
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::CLIPSRemoveAllFacts(void)
{
INITCHK(false)
(dl_RemoveAllFacts)();
factPtr = NULL;
return true;
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSAddFactArray(CStringArray* List)
Author : Mark Tomlinson
Desc. : Accessor for CLIPS function RemoveAllFacts(),
updates factPtr
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::AddFactArray(CStringArray& List, int NumFacts)
{
int i;
CString cTemp;
INITCHK(false)
if(NumFacts == 0)
NumFacts = (int) List.GetSize();
if((!m_fClipsInit) ||
(!NumFacts)) { //insure CLIPS is ready
return false;
}
for(i = 0; i < NumFacts; i++) {
cTemp = List.GetAt(i); //get string from array
SETMBUF((LPCSTR)cTemp) //copy string to buffer
if(!CLIPSAssert(m_buf)) { //assert string, bail if fail
return false;
}
}
return true;
}
/****************************************************************************
Function : CCLIPSWrap::SetRouteBuffer(CStringArray* pBuffer,CString& pRoute, bool remove)
Author : Mark Tomlinson
Desc. : assigns a string arrary pointer for a route name to
a given array pointer, calling app is responsible for
all maintenance of these string arrays. (FORM 1)
Returns : Old Route buffer pointer. You can use this to de-assign
a route to an array also, by passing in the original
buffer pointer and setting the remove flag to true.
****************************************************************************/
CStringArray* CCLIPSWrap::SetRouteBuffer(CStringArray* pBuffer, CString &Route, bool remove)
{
CStringArray* old = NULL;
int i;
if(remove) {
for(i = 0;i < NUMROUTES;i++) {
if(pRoutes[i] == pBuffer) {
old = pRoutes[i];
pRoutes[i] = NULL;
if(pRteNames[i] != NULL) {
delete pRteNames[i];
}
pRteNames[i] = NULL;
break;
}
}
}
else {
for(i = 0; i < NUMROUTES; i++) {
if(pRoutes[i] == NULL) {
old = pRoutes[i];
pRoutes[i] = pBuffer;
pRteNames[i] = new CString(Route);
break;
}
}
}
return old;
}
/****************************************************************************
Function : CCLIPSWrap::SetRouteBuffer(CStringArray* pBuffer,const char *Route, bool remove)
Author : Mark Tomlinson
Desc. : assigns a string arrary pointer for a route name to
a given array pointer, calling app is responsible for
all maintenance of these string arrays. (FORM 3)
Returns : Old buffer pointer
****************************************************************************/
CStringArray* CCLIPSWrap::SetRouteBuffer(CStringArray* pBuffer, const char *Route, bool remove)
{
return SetRouteBuffer(pBuffer, CString(Route), remove);
}
/****************************************************************************
Function : CCLIPSWrap::SetRouteFile(CString& RouteName,CString& FileName) form -1
Author : Mark Tomlinson
Desc. : Assigns the output from a specified route to a
specified filespec.
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::SetRouteFile(CString& Route, CString& FileName)
{
return SetRouteFile(Route, (LPCSTR)FileName);
}
/****************************************************************************
Function : CCLIPSWrap::SetRouteFile(CString& RouteName,char far* FileName) form -2
Author : Mark Tomlinson
Desc. : Assigns the output from a specified route to a
specified filespec. this form allows 'de-routing'
by use of a NULL pointer for FileName
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::SetRouteFile(CString& Route, const char far* FileName)
{
int i, n = -1;
if(FileRoutes == NULL) {
if(FileName != NULL) {
FileRoutes = new CStringArray();
FileNames = new CStringArray();
if(FileRoutes == NULL) {
return false;
}
}
}
for(i = 0;i < FileRoutes->GetSize(); i++) {
if(FileRoutes->GetAt(i) == Route) {
n = i;
break;
}
}
//a safety check
if(n != -1) {
if(FileName != NULL) {
(*FileNames)[n] = FileName;
}
else {
FileNames->RemoveAt(n);
FileRoutes->RemoveAt(n);
}
}
else {
if(FileName != NULL) {
FileNames->Add(FileName);
FileRoutes->Add(Route);
}
else {
return false;
}
}
return true;
}
/****************************************************************************
Function : CCLIPSWrap::GetGlobal(CString& name)
Author : Mark Tomlinson
Desc. : Rtreive the value of a global
Returns : pointer to char string containing value
****************************************************************************/
char far* CCLIPSWrap::GetGlobal(CString& name)
{
SETMBUF((LPCSTR)name)
globalPtr = (struct defglobal *)(dl_FindDefglobal)(m_buf);
if(globalPtr == NULL) {
return NULL;
}
CLEARMBUF
(dl_GetDefglobalValueForm)(m_buf,MBUFSIZE,globalPtr);
return (strstr(m_buf, "=") + 1);
}
/****************************************************************************
Function : CCLIPSWrap::GetDefglobalFloat(CString& name)
Author : Mark Tomlinson
Desc. : returns the floating point value of a named Defglobal
casts the return type. Be sure that you have the right
type defined!.
Returns : cast value, or -9999.99 on error
****************************************************************************/
float CCLIPSWrap::GetDefglobalFloat(CString& name)
{
char* ptc;
float ival = (float)-9999.99;
ptc = GetGlobal(name);
if(ptc!=NULL) {
++ptc;
//read 'm in
ival = (float) atof(ptc);
}
//send it back
return (ival);
}
/****************************************************************************
Function : CCLIPSWrap::GetDefglobalInt(CString& name)
Author : Mark Tomlinson
Desc. : returns the int value of a named Defglobal
casts the return type. Be sure that you have the right
type defined!.
Returns : cast value, or -9999 on error
****************************************************************************/
int CCLIPSWrap::GetDefglobalInt(CString& name)
{
char* ptc;
int ival = -9999;
ptc = GetGlobal(name);
if(ptc!=NULL) {
++ptc;
//read 'm in
ival = atoi(ptc);
}
return ival;
}
/****************************************************************************
Function : CCLIPSWrap::GetDefglobalLong(CString& name)
Author : Mark Tomlinson
Desc. : returns the long value of a named Defglobal
casts the return type. Be sure that you have the right
type defined!.
Returns : cast value, or -999999 on error
****************************************************************************/
long CCLIPSWrap::GetDefglobalLong(CString& name)
{
char* ptc;
long int ival = -999999L;
ptc = GetGlobal(name);
if(ptc!=NULL) {
++ptc;
//read 'm in
ival = atol(ptc);
}
return ival;
}
/****************************************************************************
Function : CCLIPSWrap::GetDefglobalString(CString& name)
Author : Mark Tomlinson
Desc. : returns the string value of a named Defglobal
casts the return type. Be sure that you have the right
type defined!.
Returns : cast value, or NULL on error
****************************************************************************/
const char far* CCLIPSWrap::GetDefglobalString(CString& name)
{
char * ptc;
CString Temp;
ptc = GetGlobal(name);
if(ptc!=NULL) {
++ptc;
//read 'm in
Temp = ptc;
}
SETMBUF((LPCSTR)Temp)
//send it back
return m_buf;
}
/****************************************************************************
Function : CCLIPSWrap::GetDefglobalAddress(CString& name)
Author : Mark Tomlinson
Desc. : returns the address value of a named Defglobal
casts the return type. Be sure that you have the right
type defined!.
Returns : cast value, or NULL on error
****************************************************************************/
void* CCLIPSWrap::GetDefglobalAddress(CString& name)
{
char var[256];
DATA_OBJECT theVar;
INITCHK(NULL)
memset(var,0,256);
memset(&theVar,0,sizeof(DATA_OBJECT));
strcpy(var,(LPCSTR)(name)); //this is necessary because CLIPS is not defined
//as using a CONST CHAR *
if(!(dl_GetDefglobalValue)(var,&theVar)) {
return NULL;
}
return theVar.value;
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSGetNextDefglobal(void)
Author : Mark Tomlinson
Desc. : updates globalPtr
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::CLIPSGetNextDefglobal(void)
{
INITCHK(false)
globalPtr = (struct defglobal *) (dl_GetNextDefglobal)(globalPtr);
if(globalPtr == NULL)
return false;
return true;
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSFindDefglobal(CString& theVar)
Author : Mark Tomlinson
Desc. : updates globalPtr
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::CLIPSFindDefglobal(CString& theVar)
{
INITCHK(false)
SETMBUF((LPCSTR)theVar)
globalPtr = (struct defglobal *) (dl_FindDefglobal)(m_buf);
if(globalPtr == NULL)
return false;
return true;
}
/****************************************************************************
Function : CCLIPSWrap::CLIPSUndefglobal(void)
Author : Mark Tomlinson
Desc. : uses globalPtr, updates globalPtr
Returns : true on success, false on error
****************************************************************************/
bool CCLIPSWrap::CLIPSUndefglobal(void* Defglobal)
{
INITCHK(false)
if(Defglobal == NULL) {
if((dl_Undefglobal)(globalPtr)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -