muParser API -  1.35
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
muParserStack.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2011 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 
37 /** \file
38  \brief This file defines the stack used by muparser.
39 */
40 
41 namespace mu
42 {
43 
44  /** \brief Parser stack implementation.
45 
46  Stack implementation based on a std::stack. The behaviour of pop() had been
47  slightly changed in order to get an error code if the stack is empty.
48  The stack is used within the Parser both as a value stack and as an operator stack.
49 
50  \author (C) 2004-2011 Ingo Berg
51  */
52  template <typename TValueType>
53  class ParserStack
54  {
55  private:
56 
57  /** \brief Type of the underlying stack implementation. */
58  typedef std::stack<TValueType, std::vector<TValueType> > impl_type;
59 
60  impl_type m_Stack; ///< This is the actual stack.
61 
62  public:
63 
64  //---------------------------------------------------------------------------
65  ParserStack()
66  :m_Stack()
67  {}
68 
69  //---------------------------------------------------------------------------
70  virtual ~ParserStack()
71  {}
72 
73  //---------------------------------------------------------------------------
74  /** \brief Pop a value from the stack.
75 
76  Unlike the standard implementation this function will return the value that
77  is going to be taken from the stack.
78 
79  \throw ParserException in case the stack is empty.
80  \sa pop(int &a_iErrc)
81  */
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 
92  /** \brief Push an object into the stack.
93 
94  \param a_Val object to push into the stack.
95  \throw nothrow
96  */
97  void push(const TValueType& a_Val)
98  {
99  m_Stack.push(a_Val);
100  }
101 
102  /** \brief Return the number of stored elements. */
103  unsigned size() const
104  {
105  return (unsigned)m_Stack.size();
106  }
107 
108  /** \brief Returns true if stack is empty false otherwise. */
109  bool empty() const
110  {
111  return m_Stack.empty();
112  }
113 
114  /** \brief Return reference to the top object in the stack.
115 
116  The top object is the one pushed most recently.
117  */
118  TValueType& top()
119  {
120  return m_Stack.top();
121  }
122  };
123 } // namespace MathUtils
124 
125 #endif
#define _T(x)
Activate this option in order to compile with OpenMP support.
Definition: muParserDef.h:69
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.
Error class of the parser.
Namespace for mathematical applications.
Definition: muParser.cpp:49
bool empty() const
Returns true if stack is empty false otherwise.
This file contains the parser token definition.
unsigned size() const
Return the number of stored elements.
This file defines the error class used by the parser.