From 3be37b2599c8d7419034b7a0a4098c1472fd64c9 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Mon, 16 Aug 2010 07:31:10 +0000 Subject: [PATCH] adopted that it does compile with Microsoft Visual Studio 2008 Express Edition (see spirit_fcn_test.mak which is an input file for nmake.exe) --- src/tests/spirit/.kdbgrc.spirit_fcn_test | 0 src/tests/spirit/PFunction.cpp | 18 +++-- src/tests/spirit/PFunctionHandler.cpp | 91 +++++++++++++----------- src/tests/spirit/PFunctionHandler.h | 9 ++- src/tests/spirit/fcnInput.txt | 3 +- src/tests/spirit/spirit_fcn_test.cpp | 7 +- src/tests/spirit/spirit_fcn_test.mak | 33 +++++++++ 7 files changed, 101 insertions(+), 60 deletions(-) delete mode 100755 src/tests/spirit/.kdbgrc.spirit_fcn_test create mode 100644 src/tests/spirit/spirit_fcn_test.mak diff --git a/src/tests/spirit/.kdbgrc.spirit_fcn_test b/src/tests/spirit/.kdbgrc.spirit_fcn_test deleted file mode 100755 index e69de29b..00000000 diff --git a/src/tests/spirit/PFunction.cpp b/src/tests/spirit/PFunction.cpp index 77f505bd..078fe902 100644 --- a/src/tests/spirit/PFunction.cpp +++ b/src/tests/spirit/PFunction.cpp @@ -36,6 +36,10 @@ using namespace std; #include // for stripping leading whitespace in std::string +#include +#include +#include + #include "PFunction.h" //-------------------------------------------------------------------------- @@ -164,7 +168,7 @@ bool PFunction::CheckParameterAndMapInTree(iter_t const& i) assert(i->children.size() == 0); string str(i->value.begin(), i->value.end()); boost::algorithm::trim(str); - cout << endl << "parameterID: value = '" << str << "'" << endl; +cout << endl << "parameterID: value = '" << str << "'" << endl; bool minus_sign_present = false; if (str[0] == '-') @@ -283,7 +287,7 @@ void PFunction::FillFuncEvalTree(iter_t const& i, PFuncTreeNode &node) status = sscanf(str.c_str(), "%lf", &dvalue); // convert string to double node.fID = PFunctionGrammar::realID; // keep the ID node.fDvalue = dvalue; // keep the value -// cout << endl << ">> realID: value = " << dvalue; + cout << endl << ">> realID: value = " << dvalue; } else if (i->value.id() == PFunctionGrammar::constPiID) { // handle constant pi node.fID = PFunctionGrammar::constPiID; // keep the ID node.fDvalue = 3.14159265358979323846; // keep the value @@ -300,7 +304,7 @@ void PFunction::FillFuncEvalTree(iter_t const& i, PFuncTreeNode &node) } node.fID = PFunctionGrammar::parameterID; // keep the ID node.fIvalue = ivalue; // keep the value -cout << endl << ">> parameterID: value = " << ivalue; + cout << endl << ">> parameterID: value = " << ivalue; } else if (i->value.id() == PFunctionGrammar::mapID) { // handle map number str = string(i->value.begin(), i->value.end()); // get string status = sscanf(str.c_str(), "MAP%d", &ivalue); // convert string to map number @@ -463,13 +467,13 @@ double PFunction::EvalNode(PFuncTreeNode &node) } else if (node.fFunctionTag == FUN_ATAN) { return atan(EvalNode(node.children[0])); } else if (node.fFunctionTag == FUN_ACOSH) { - return acosh(EvalNode(node.children[0])); + return boost::math::acosh(EvalNode(node.children[0])); } else if (node.fFunctionTag == FUN_ASINH) { - return asinh(EvalNode(node.children[0])); + return boost::math::asinh(EvalNode(node.children[0])); } else if (node.fFunctionTag == FUN_ATANH) { - return atanh(EvalNode(node.children[0])); + return boost::math::atanh(EvalNode(node.children[0])); } else if (node.fFunctionTag == FUN_LOG) { - return log(EvalNode(node.children[0]))/log(10); + return log(EvalNode(node.children[0]))/log(10.0); } else if (node.fFunctionTag == FUN_LN) { return log(EvalNode(node.children[0])); } else if (node.fFunctionTag == FUN_EXP) { diff --git a/src/tests/spirit/PFunctionHandler.cpp b/src/tests/spirit/PFunctionHandler.cpp index 1b06bf69..d467cd27 100644 --- a/src/tests/spirit/PFunctionHandler.cpp +++ b/src/tests/spirit/PFunctionHandler.cpp @@ -32,9 +32,10 @@ #include #include -#include -#include -#include +#include +using namespace std; + +#include #include "PFunctionHandler.h" @@ -46,13 +47,12 @@ * * \param fln */ -PFunctionHandler::PFunctionHandler(char *fln, bool debug) : fDebug(debug) +PFunctionHandler::PFunctionHandler(char *fln, bool debug) : fDebug(debug), fFileName(fln) { fValid = true; - fFileName = QString(fln); cout << endl << "in PFunctionHandler(char *fln)"; - cout << endl << "fFileName = " << fFileName.latin1(); + cout << endl << "fFileName = " << fFileName; fValid = ReadFile(); if (fValid) @@ -67,12 +67,12 @@ PFunctionHandler::PFunctionHandler(char *fln, bool debug) : fDebug(debug) * * \param lines */ -PFunctionHandler::PFunctionHandler(vector lines) +PFunctionHandler::PFunctionHandler(vector lines) { fValid = true; fFileName = ""; - cout << endl << "in PFunctionHandler(vector lines)"; + cout << endl << "in PFunctionHandler(vector lines)"; if (lines.size() == 0) { fValid = false; @@ -86,26 +86,31 @@ PFunctionHandler::PFunctionHandler(vector lines) double dval[10]; bool inFcnBlock = false; for (unsigned int i=0; i lines) for (int i=0; i lines) if (fValid) { cout << endl << "Functions: "; for (unsigned int i=0; i info = ast_parse(fLines[i].latin1(), function, space_p); + tree_parse_info<> info = ast_parse(fLines[i].c_str(), function, space_p); if (info.full) { cout << endl << "parse successfull ..." << endl; @@ -277,41 +282,38 @@ bool PFunctionHandler::ReadFile() { cout << endl << "in ~PFunctionHandler::ReadFile()"; - if (fFileName.isEmpty()) { + if (fFileName.length() == 0) { cout << endl << "PFunctionHandler::ReadFile(): **ERROR**"; cout << endl << " no file name given :-(. Will quit"; return false; } - QFile f(fFileName); - if (!f.exists()) { + ifstream f; + f.open(fFileName.c_str(), ifstream::in); + + if (!f.is_open()) { cout << endl << "PFunctionHandler::ReadFile(): **ERROR**"; - cout << endl << " File '" << fFileName.latin1() << "' does not exist."; + cout << endl << " File '" << fFileName.c_str() << "' couldn't being opened."; return false; } - if (!f.open(IO_ReadOnly)) { - cout << endl << "PFunctionHandler::ReadFile(): **ERROR**"; - cout << endl << " File '" << fFileName.latin1() << "' couldn't being opened."; - return false; - } - - QTextStream stream(&f); - QString line; + string line; + char c_line[128]; bool done = false; bool success = true; int status; int val[10]; double dval[10]; bool inFcnBlock = false; - while ( !stream.atEnd() && !done) { - line = stream.readLine(); // line of text excluding '\n' - if (line.startsWith("#")) // comment hence ignore + while ( !f.eof() && !done) { + f.getline(c_line, 128); // line of text excluding '\n' + line = c_line; + if (line.find("#") == 0) // comment hence ignore continue; - line = line.upper(); - if (line.startsWith("PAR")) { + boost::to_upper(line); + if (line.find("PAR") == 0) { cout << endl << "this is a parameter line ..."; - status = sscanf(line.latin1(), "PAR %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", + status = sscanf(line.c_str(), "PAR %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &dval[0], &dval[1], &dval[2], &dval[3], &dval[4], &dval[5], &dval[6], &dval[7], &dval[8], &dval[9]); if (status < 0) { @@ -322,10 +324,13 @@ bool PFunctionHandler::ReadFile() cout << endl << "PAR line, status = " << status; for (int i=0; i #include +#include using namespace std; -#include - #include "PFunctionGrammar.h" #include "PFunction.h" @@ -45,7 +44,7 @@ class PFunctionHandler { public: PFunctionHandler(char *fln, bool debug); - PFunctionHandler(vector lines); + PFunctionHandler(vector lines); virtual ~PFunctionHandler(); virtual bool IsValid() { return fValid; } @@ -58,11 +57,11 @@ class PFunctionHandler bool fDebug; bool fValid; - QString fFileName; + string fFileName; vector fParam; vector fMap; - vector fLines; + vector fLines; vector fFuncs; diff --git a/src/tests/spirit/fcnInput.txt b/src/tests/spirit/fcnInput.txt index 58d79838..4476383a 100644 --- a/src/tests/spirit/fcnInput.txt +++ b/src/tests/spirit/fcnInput.txt @@ -17,13 +17,14 @@ PAR 1.0 2.1 3.5 -0.87 0.87 MAP 2 1 4 5 FUNCTIONS +fun0 = cos(par1) #fun0 = sin(par3/(par1+map2)) #fun0 = 1.2+pi #fun1 = gamma_mu #fun2 = -par1*(sin(par2)*cos(par3)+((map1))) #fun1 = cos(par1) #fun0 = par1 + map3 * cos(cos(par2 - map1)) -fun8 = -par1*log(sin(par1)) + exp(-1.0*map2) +#fun8 = -par1*log(sin(par1)) + exp(-1.0*map2) #fun1 = par1 + map1 * (0.01355+par1*(2.1 - (-2.3 / 3.4))) #fun2 = par1 * par2 - map3 #fun3 = -3.2 + (par2-par1)/(map2+map3) diff --git a/src/tests/spirit/spirit_fcn_test.cpp b/src/tests/spirit/spirit_fcn_test.cpp index 2ef7c520..3266950c 100644 --- a/src/tests/spirit/spirit_fcn_test.cpp +++ b/src/tests/spirit/spirit_fcn_test.cpp @@ -1,8 +1,7 @@ #include +#include using namespace std; -#include - #include "PFunctionHandler.h" //----------------------------------------------------- @@ -17,7 +16,7 @@ void syntax() } //----------------------------------------------------- -void handle_input(vector &lines) +void handle_input(vector &lines) { cout << endl << "will handle input ..."; cout << endl << "you should provide a PAR, a MAP, and a FUNCTION block"; @@ -80,7 +79,7 @@ int main(int argc, char *argv[]) if (inputFile) { fcnHandler = new PFunctionHandler(argv[2], debug); } else { - vector lines; + vector lines; handle_input(lines); cout << endl << "lines.size() = " << lines.size(); fcnHandler = new PFunctionHandler(lines); diff --git a/src/tests/spirit/spirit_fcn_test.mak b/src/tests/spirit/spirit_fcn_test.mak new file mode 100644 index 00000000..1829924f --- /dev/null +++ b/src/tests/spirit/spirit_fcn_test.mak @@ -0,0 +1,33 @@ +#------------------------------------------------- +# spirit_fcn_test.mak +#------------------------------------------------- + +# Paths +STD_INC = "C:\Program Files\Microsoft Visual Studio 9.0\VC\include" +BOOST_INC = "D:\boost_1_43_0\boost_1_43_0" + +LIB_PATH_1 = "C:\Program Files\Microsoft Visual Studio 9.0\VC\lib" +LIB_PATH_2 = "C:\Program Files\Microsoft SDKs\Windows\v6.0a\Lib" +LIB_PATH_3 = "D:\boost_1_43_0\boost_1_43_0\bin.v2\libs" + +# Compiler etc +CC = cl +LINK32 = link + +# Options +CXXFLAGS = /c /W3 /O2 /nologo /EHsc /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /I$(STD_INC) /I$(BOOST_INC) +LINK32_FLAGS = /nologo /subsystem:console /incremental:no /machine:I386 + +fln = spirit_fcn_test + +OBJ = $(fln).obj PFunction.obj PFunctionHandler.obj + +$(fln): $(OBJ) + $(LINK32) $(LINK32_FLAGS) /LIBPATH:$(LIB_PATH_1) /LIBPATH:$(LIB_PATH_2) /LIBPATH:$(LIB_PATH_3) $(OBJ) /out:$(fln).exe + +.cpp.obj: + $(CC) $(CXXFLAGS) $< + +clean: + @del /f *.obj +