MADNESS  version 0.9
muParserStack.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2006 Ingo Berg
9 
10  Permission is hereby granted, free of charge, to any person obtaining a copy of this
11  software and associated documentation files (the "Software"), to deal in the Software
12  without restriction, including without limitation the rights to use, copy, modify,
13  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
14  permit persons to whom the Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in all copies or
17  substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20  NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 
26 #ifndef MU_PARSER_STACK_H
27 #define MU_PARSER_STACK_H
28 
29 #include <cassert>
30 #include <string>
31 #include <stack>
32 #include <vector>
33 
34 #include "muParserError.h"
35 #include "muParserToken.h"
36 
41 namespace mu
42 {
43 
52  template <typename TValueType>
53  class ParserStack
54  {
55  private:
56 
58  typedef std::stack<TValueType, std::vector<TValueType> > impl_type;
59 
60  impl_type m_Stack;
61 
62  public:
63 
64  //---------------------------------------------------------------------------
66  :m_Stack()
67  {}
68 
69  //---------------------------------------------------------------------------
70  virtual ~ParserStack()
71  {}
72 
73  //---------------------------------------------------------------------------
82  TValueType pop()
83  {
84  if (empty())
85  throw ParserError( _T("stack is empty.") );
86 
87  TValueType el = top();
88  m_Stack.pop();
89  return el;
90  }
91 
97  void push(const TValueType& a_Val)
98  {
99  m_Stack.push(a_Val);
100  }
101 
103  unsigned size() const
104  {
105  return (unsigned)m_Stack.size();
106  }
107 
109  bool empty() const
110  {
111  return m_Stack.size()==0;
112  }
113 
118  TValueType& top()
119  {
120  return m_Stack.top();
121  }
122  };
123 } // namespace MathUtils
124 
125 #endif
void push(const TValueType &a_Val)
Push an object into the stack.
Definition: muParserStack.h:97
TValueType pop()
Pop a value from the stack.
Definition: muParserStack.h:82
Parser stack implementation.
Definition: muParserStack.h:53
TValueType & top()
Return reference to the top object in the stack.
Definition: muParserStack.h:118
Error class of the parser.
Definition: muParserError.h:119
Namespace for mathematical applications.
Definition: muParser.cpp:47
ParserStack()
Definition: muParserStack.h:65
bool empty() const
Returns true if stack is empty false otherwise.
Definition: muParserStack.h:109
#define _T
Definition: muParserDef.h:62
This file contains the parser token definition.
virtual ~ParserStack()
Definition: muParserStack.h:70
unsigned size() const
Return the number of stored elements.
Definition: muParserStack.h:103
This file defines the error class used by the parser.