/* * This file is a part of TTCalc - a mathematical calculator * and is distributed under the (new) BSD licence. * Author: Tomasz Sowa */ /* * Copyright (c) 2006-2007, Tomasz Sowa * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name Tomasz Sowa nor the names of contributors to this * project may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF * THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef headerfilecalculation #define headerfilecalculation /*! \file parsermanager.h \brief object of type ParserManager we're using during calculating */ #include "resource.h" #include #include "programresources.h" #include /*! \brief object of type ParserManager we're using during calculating In our program we're using three kind of precisions. First is the smallest , and the third is the biggest. Because precision is established during compilation (templates) we need three different objects. ParserManager helps us to maintain these objects. */ class ParserManager { public: ParserManager(); ParserManager(const ParserManager & p); ParserManager & operator=(const ParserManager & p); ~ParserManager(); /*! the main method which call parserX.Parse(...) */ ttmath::ErrorCode Parse(); /* it returns the last error code which was during parsing */ ttmath::ErrorCode GetLastCode(); /*! we call this method directly after when we have left WaitForCalculatingAndBlockForStop() method from the ThreadController only in this method we can read variables which can be changed by the first thread */ void MakeCopyOfVariables(); /*! it prepares our three parsers to work, it should be called only once */ void Init(); /*! this method prints result (a correct value if was or an error instead) */ void PrintResult(); private: ttmath::Parser > parser1; ttmath::Parser > parser2; ttmath::Parser > parser3; ttmath::Objects variables, functions; const unsigned int buffer_len; char * buffer; int base_input, base_output; bool always_scientific; int when_scientific; int rounding; int precision; Languages::Country country; ttmath::ErrorCode code; template void PrintResult(ttmath::Parser & matparser) { std::string result, part; unsigned int i = 0; for(i=0 ; iGetLanguages()->GuiMessage(country, Languages::overflow_during_printing); // will be working correctly on gcc with -O3 // this error doesn't appear always, it can be seen, for example, // if we use Big<1,3> type and we give '2^32' for calculating // I didn't check this error on a new version of gcc part = GetPrgRes()->GetLanguages()->GuiMessage(country, Languages::overflow_during_printing); } } catch(...) { part.erase(); part = GetPrgRes()->GetLanguages()->ErrorMessage(country, ttmath::err_internal_error); } result += part; if( i < matparser.stack.size()-1 ) result += " "; } SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,result.c_str()); } }; #endif