muParser: muParserStack.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Examples

# muParserStack.h

Go to the documentation of this file.

    00001 /*
    00002                  __________
    00003     _____   __ __\______   \_____  _______  ______  ____ _______
    00004    /     \ |  |  \|     ___/\__  \ \_  __ \/  ___/_/ __ \\_  __ \
    00005   |  Y Y  \|  |  /|    |     / __ \_|  | \/\___ \ \  ___/ |  | \/
    00006   |__|_|  /|____/ |____|    (____  /|__|  /____  > \___  >|__|
    00007         \/                       \/            \/      \/
    00008   Copyright (C) 2004-2006 Ingo Berg
    00009
    00010   Permission is hereby granted, free of charge, to any person obtaining a copy of this
    00011   software and associated documentation files (the "Software"), to deal in the Software
    00012   without restriction, including without limitation the rights to use, copy, modify,
    00013   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    00014   permit persons to whom the Software is furnished to do so, subject to the following conditions:
    00015
    00016   The above copyright notice and this permission notice shall be included in all copies or
    00017   substantial portions of the Software.
    00018
    00019   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
    00020   NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    00021   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00022   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00024 */
    00025
    00026 #ifndef MU_PARSER_STACK_H
    00027 #define MU_PARSER_STACK_H
    00028
    00029 #include <cassert>
    00030 #include <string>
    00031 #include <stack>
    00032 #include <vector>
    00033
    00034 #include "muParserError.h"
    00035 #include "muParserToken.h"
    00036
    00041 namespace mu
    00042 {
    00043
    00052   template <typename TValueType>
    00053   class ParserStack
    00054   {
    00055     private:
    00056
    00058       typedef std::stack<TValueType, std::vector<TValueType> > impl_type;
    00059
    00060       impl_type m_Stack;
    00061
    00062     public:
    00063
    00064       //---------------------------------------------------------------------------
    00065       ParserStack()
    00066         :m_Stack()
    00067       {}
    00068
    00069       //---------------------------------------------------------------------------
    00070       virtual ~ParserStack()
    00071       {}
    00072
    00073       //---------------------------------------------------------------------------
    00082             TValueType pop()
    00083       {
    00084         if (empty())
    00085           throw ParserError( _T("stack is empty.") );
    00086
    00087         TValueType el = top();
    00088         m_Stack.pop();
    00089         return el;
    00090       }
    00091
    00097       void push(const TValueType& a_Val)
    00098       {
    00099         m_Stack.push(a_Val);
    00100       }
    00101
    00103       unsigned size() const
    00104       {
    00105         return (unsigned)m_Stack.size();
    00106       }
    00107
    00109       bool empty() const
    00110       {
    00111         return m_Stack.size()==0;
    00112       }
    00113
    00118       TValueType& top()
    00119       {
    00120         return m_Stack.top();
    00121       }
    00122   };
    00123 } // namespace MathUtils
    00124
    00125 #endif