Go to the documentation of this file.
55 const std::string &
id =
"undefined",
56 const std::string &td =
"Generic ArgException")
85 return (
"Argument: " +
_argId);
91 const char *
what() const noexcept
93 static std::string ex;
302 Item stoItem(
const char *_ch,
const char **_EndPtr =
nullptr)
const;
476 double operandValue = strtod(ch, &pEnd);
494 const char *expr_cstr = exprStr.c_str();
517 for (
auto i = infixList.
begin(); i != infixList.
end(); ++i)
520 if ((*i).isOperand())
545 _topItem = opStack.
top();
559 auto _pri = (*i).priority();
569 _topItem = opStack.
top();
595 if ((*i).isOperand())
647 if (numOfCh > 0 && numOfCh <
buf_size)
681 throw(
RpnException(
"What's wrong with your code???\n"));
695 if (!pri_lhs || !pri_rhs)
698 return pri_lhs < pri_rhs;
705 throw(
RpnException(
"Arg1 should be a valid operator!\n"));
709 case Operator_type::Add:
714 case Operator_type::Div:
719 case Operator_type::Exp:
724 case Operator_type::Mul:
729 case Operator_type::Sub:
const int buf_size
项的最大长度 = buf_size - 1
bool hasLoPriThan(const Item &rhs) const
Item内嵌类的工具函数
static const int8_t priOfMul
二元乘法的优先级(同除法)
bool isOperand() const
是操作数
RpnException(const std::string &text="undefined exception", const std::string &id="undefined", const std::string &td="Generic ArgException")
Constructor.
bool isOperator() const
是操作符
std::string _typeDescription
Describes the type of the exception.
virtual void push(const T &elem)
std::string typeDescription() const
Item(Item_type item_type, Operator_type operator_type, double operand_val=NAN)
Construct a new Item object.
Operator_type operator_type
操作符类型
double calcVal() const
计算(后缀)表达式的值
Item stoItem(const char *_ch, const char **_EndPtr=nullptr) const
Rpn类的工具函数
virtual void push(const T &elem)
static Item nao()
获得一个NAO(非法操作符)
virtual bool isEmpty() const
friend bool operator==(const Item &lhs, const Item &rhs)
operator==
Item(double operand_val)
Construct a new Item object.
std::string itemToStr(const Item &Op) const
获取表示项(操作符/操作数)的string
std::string postfix() const
获取后缀形式的string
int8_t priority() const
获取优先级.
static const int8_t priOfAdd
二元加法的优先级(同减法)
std::string postfixStr
存储后缀形式的字符串
@ Add
lowest(but NAO) priority: 0x01
@ NAO
Not an operator(lowest priority): 0xFF.
const char * what() const noexcept
Returns the arg id and error text.
@ Oparen
undefine priority : 0x00
void push_back(const T &obj)
virtual ~RpnException() noexcept
Destroy the Rpn Exception object.
std::string _errorText
The text of the exception message.
static Item excOp(const Item &op, const Item &opL=nao(), const Item &opR=nao())
执行一次运算.
Rpn_t(const std::string &expr_str="0.0", notationType exprType=notationType::Infix)
Construct a new Rpn_t object.
std::string itemListToStr(const List::dLinkList< Item > &itemList) const
获取表示itemList的string
Rpn_t & assign(const std::string &expr_str, notationType _type=notationType::Infix)
设置Rpn_t类对象的值
~Rpn_t()=default
Destroy the Rpn_t object.
friend bool operator==(const Item &lhs, const Item &rhs)
operator==
List::dLinkList< Item > itemList
存储后缀表达式的双链表
List::dLinkList< Item > exprStrToList(const std::string &exprStr) const
用string中的表达式创建一个list
Item(Operator_type op=Operator_type::NAO)
Construct a new Item object.
double operand_val
操作数的值(为操作符时, 无效)
std::string _argId
The argument related to this exception.
List::dLinkList< Item > infixListToPostfixList(const List::dLinkList< Item > &infixList) const
用一个中缀list创建一个后缀list
std::string error() const
Returns the error text.
std::string argId() const
Returns the argument id.
@ Exp
highest priority: 0x07