-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression.hpp
57 lines (31 loc) · 1.59 KB
/
expression.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once
#ifndef __EXPRESSION_H__
#define __EXPRESSION_H__
#include <vector>
#include "token.hpp"
namespace math {
class Expression {
public:
Expression() {}
~Expression() {}
inline const Token& operator[] (const int i) const { return (i < 0 || i > m_tokens.size() ? Token() : m_tokens[i]); }
inline Token& operator[] (const int i) { return m_tokens[i]; }
inline const Token& peek(const int i) const { return (i < 0 || i >= m_tokens.size() ? Token() : m_tokens[i]); }
inline const Token& operator() (const int i) const { return (i < 0 || i > m_tokens.size() ? Token() : m_tokens[i]); }
inline void push_back(const Token& token) { m_tokens.push_back(token); }
inline void erase(const std::vector<Token>::iterator& it) { m_tokens.erase(it); }
inline void clear() { m_tokens.clear(); }
inline void insert(const std::vector<Token>::iterator& where, const Token& token) { m_tokens.insert(where, token); }
inline bool empty() const { return m_tokens.empty(); }
inline size_t size() const { return m_tokens.size(); }
inline std::vector<Token>::iterator begin() { return m_tokens.begin(); }
inline std::vector<Token>::iterator end() { return m_tokens.end(); }
inline std::vector<Token>::const_iterator begin() const { return m_tokens.begin(); }
inline std::vector<Token>::const_iterator end() const { return m_tokens.end(); }
inline Token& front() { return m_tokens.front(); }
inline Token& back() { return m_tokens.back(); }
private:
std::vector<Token> m_tokens;
};
}
#endif // __EXPRESSION_H__