1 /* "CodeWorker": a scripting language for parsing and generating text. 2 3 Copyright (C) 1996-1997, 1999-2002 C�dric Lemaire 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 19 To contact the author: codeworker@free.fr 20 */ 21 22 #ifdef WIN32 23 #pragma warning (disable : 4786) 24 #endif 25 26 #include "ExprScriptFunction.h" 27 #include "DtaProject.h" 28 #include "CppParsingTree.h" 29 #include "GrfWritefileHook.h" 30 31 namespace CodeWorker { GrfWritefileHook(GrfBlock * pParent)32 GrfWritefileHook::GrfWritefileHook(GrfBlock* pParent) : GrfFunction(pParent, "writefileHook", "", false), _writefileHook(NULL) { 33 DtaProject::getInstance().setWritefileHook(this); 34 } 35 GrfWritefileHook(WRITEFILEHOOK_FUNCTION writefileHook)36 GrfWritefileHook::GrfWritefileHook(WRITEFILEHOOK_FUNCTION writefileHook) : GrfFunction(NULL, "writefileHook", "", false), _writefileHook(writefileHook) { 37 DtaProject::getInstance().setWritefileHook(this); 38 } 39 ~GrfWritefileHook()40 GrfWritefileHook::~GrfWritefileHook() { 41 if (DtaProject::existInstance()) DtaProject::getInstance().setWritefileHook(NULL); 42 } 43 setFileNameArgument(const char * sArgument)44 bool GrfWritefileHook::setFileNameArgument(const char* sArgument) { 45 if (!getParameterTypes().empty()) return false; 46 return addParameterAndType(sArgument, VALUE_EXPRTYPE, NULL); 47 } 48 setPositionArgument(const char * sArgument)49 bool GrfWritefileHook::setPositionArgument(const char* sArgument) { 50 if (getParameterTypes().size() != 1) return false; 51 return addParameterAndType(sArgument, VALUE_EXPRTYPE, NULL); 52 } 53 setCreationArgument(const char * sArgument)54 bool GrfWritefileHook::setCreationArgument(const char* sArgument) { 55 if (getParameterTypes().size() != 2) return false; 56 return addParameterAndType(sArgument, VALUE_EXPRTYPE, NULL); 57 } 58 executeHook(DtaScriptVariable & visibility,const std::string & sFile,int iPosition,bool bCreation)59 std::string GrfWritefileHook::executeHook(DtaScriptVariable& visibility, const std::string& sFile, int iPosition, bool bCreation) { 60 std::string sSuccess; 61 if (_writefileHook != NULL) { 62 sSuccess = _writefileHook(sFile, iPosition, bCreation); 63 } else { 64 std::auto_ptr<ExprScriptFunction> pFunctionCall(new ExprScriptFunction(this)); 65 pFunctionCall->addParameter(new ExprScriptConstant(sFile.c_str())); 66 pFunctionCall->addParameter(new ExprScriptConstant(iPosition)); 67 pFunctionCall->addParameter(new ExprScriptConstant(bCreation)); 68 sSuccess = launchExecution(visibility, *pFunctionCall); 69 } 70 return sSuccess; 71 } 72 } 73