📄 formulaimpl.cpp
字号:
// FormulaImpl.cpp: implementation of the CFormulaImpl class.
//
//////////////////////////////////////////////////////////////////////
/*
* Generated by MyEclipse Struts
*
* Written by Yang Huaisheng
* Homepage: http://codefan.spaces.live.com
* version 0.01
* create at 2006-04-30
*
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice.
* No warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* user.
*
* Send bug reports, bug fixes, enhancements, requests, flames, etc. to
* codefan@hotmial.com
*
*/
#include "stdafx.h"
#include "..\HEADER\FormulaImpl.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFormulaImpl::CFormulaImpl()
{
//m_pCurModula = &m_CurModula;
CFormulaModule mainFormula;
mainFormula.sModuleName = "main";
//int nInd = m_FMList.Add(mainFormula);
//m_CurModula.pParentModule = &m_FMList[nInd];
POSITION pPos = m_FMList.AddTail(mainFormula);
m_pMainModula = &m_FMList.GetAt(pPos);
m_CurModula.pParentModule = m_pMainModula;
}
CFormulaImpl::~CFormulaImpl()
{
}
int CFormulaImpl::CompileFormula(LPCTSTR szFormula,int nLen)
{
m_CurModula.SetSource(szFormula,nLen);
m_Compile.SetFormulaModule(&m_CurModula);
return m_Compile.Compile();
}
int CFormulaImpl::CompileFile(LPCTSTR szFilename)
{
CFile txtFile;
if(!txtFile.Open(szFilename,CFile::modeRead))
return -1;
int nLen = txtFile.GetLength();
char * szFormula = new char[nLen+1];
txtFile.ReadHuge(szFormula,nLen);
txtFile.Close();
m_CurModula.SetSource(szFormula,nLen);
delete [] szFormula;
m_Compile.SetFormulaModule(&m_CurModula);
return m_Compile.Compile();
}
CString CFormulaImpl::Run(int nModuleInd)
{
if( nModuleInd <1 || nModuleInd >= m_FMList.GetCount() ){
ASSERT(m_Compile.GetErrorSum()==0);
m_Execute.SetFormulaModule(&m_CurModula);
m_Execute.Run();
}else{
POSITION pPos = m_FMList.FindIndex(nModuleInd);
PFORMUALMODULE pCurMod = &m_FMList.GetAt(pPos);
m_Execute.SetFormulaModule(pCurMod);
m_Execute.Run( );//TRUE);
}
return m_Execute.GetRetDesc();
}
float CFormulaImpl::Calc(int nModuleInd)
{
if( nModuleInd <1 || nModuleInd >= m_FMList.GetCount() ){
ASSERT(m_Compile.GetErrorSum()==0);
m_Execute.SetFormulaModule(&m_CurModula);
m_Execute.Run();
}else{
POSITION pPos = m_FMList.FindIndex(nModuleInd);
PFORMUALMODULE pCurMod = &m_FMList.GetAt(pPos);
m_Execute.SetFormulaModule(pCurMod);
m_Execute.Run( );//TRUE);
}
return m_Execute.GetResult();
}
CString CFormulaImpl::Run(LPCTSTR szModuleName)
{
POSITION p = m_FMList.GetHeadPosition();
while(p){
CFormulaModule & refFormula =m_FMList.GetNext(p);
if(refFormula.sModuleName == szModuleName){
m_Execute.SetFormulaModule(& refFormula);
m_Execute.Run();//TRUE);
return m_Execute.GetRetDesc();
}
}
return CString("no this module!");
}
LPCTSTR CFormulaImpl::GetSource()
{
return m_CurModula.GetSource();
}
int CFormulaImpl::GetSourceLen()
{
return m_CurModula.GetSourceLen();
}
void CFormulaImpl::SetVariable(LPCTSTR szName,LPCTSTR szValue)
{
m_pMainModula->SetVariable(szName,szValue);
}
void CFormulaImpl::SetFloat(LPCTSTR szName,float fVal)
{
m_pMainModula->SetFloat(szName,fVal);
}
void CFormulaImpl::SetArrayNumberVar(LPCTSTR szName,int nLen,float * lpValue)
{
m_pMainModula->SetArrayNumberVar(szName,nLen,lpValue);
}
int CFormulaImpl::GetVariableSum()
{
return m_pMainModula->GetVariableSum();
}
CString CFormulaImpl::ListVariable(int nVarInd, LIST_VAR_TYPE nListType)
{
return m_pMainModula->ListVariable(nVarInd,nListType);
}
int CFormulaImpl::GetFormulaItemSum()
{
return m_CurModula.GetFormulaItemSum();
}
CString CFormulaImpl::ListFormulaItem(int nFormulaInd, LIST_FORMULA_ITEM_TYPE nListType)
{
return m_CurModula.ListFormulaItem(nFormulaInd,nListType);
}
int CFormulaImpl::GetModuleSum()
{
return m_FMList.GetCount();
}
CString CFormulaImpl::GetModuleName(int nModuleInd)
{
POSITION p = m_FMList.FindIndex(nModuleInd);
if(p==NULL)
return CString("");
return m_FMList.GetAt(p).sModuleName;
}
void CFormulaImpl::SaveModule(LPCTSTR szModuleName)
{
POSITION p = m_FMList.GetHeadPosition();
m_CurModula.sModuleName = szModuleName;
while(p){
CFormulaModule & refFormula =m_FMList.GetNext(p);
if(refFormula.sModuleName == szModuleName){
refFormula = m_CurModula;
// refFormula.GetVarInPlace();
return;
}
}
p = m_FMList.AddTail(m_CurModula);
CFormulaModule & refFormula =m_FMList.GetNext(p);
// refFormula.GetVarInPlace();
}
BOOL CFormulaImpl::GetModule(LPCTSTR szModuleName)
{
POSITION p = m_FMList.GetHeadPosition();
while(p){
CFormulaModule & refFormula =m_FMList.GetNext(p);
if(refFormula.sModuleName == szModuleName){
m_CurModula = refFormula;
m_Compile.SetFormulaModule(&m_CurModula);
m_Compile.Compile();
//m_Compile.ClearError();
return TRUE;
}
}
return FALSE;
}
void CFormulaImpl::SaveCompileScene(int nModuleInd,LPCTSTR szFilename)
{
}
void CFormulaImpl::LoadCompileScene(int nModuleInd,LPCTSTR szFilename)
{
}
int CFormulaImpl::GetCompileErrorSum()
{
return m_Compile.GetErrorSum();
}
CString CFormulaImpl::GetCompileError(int nErrorInd)
{
return m_Compile.GetErrorDesc(nErrorInd);
}
int CFormulaImpl::GetOutputSum()
{
return m_Execute.GetOutputSum();
}
CString CFormulaImpl::GetOutputDesc(int nOPInd)
{
return m_Execute.GetOutputDesc(nOPInd);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -