栈  0.1
数据结构_第3章
RPN::Rpn_t::Item Struct Reference

< 后缀式的元素: 操作数, 操作符 More...

Public Types

enum  Item_type { Item_type::Operand, Item_type::Operator }
 < 项的类型 More...
 
enum  Operator_type : int8_t {
  Operator_type::NAO = (int8_t)0xFF, Operator_type::Add = 0x10, Operator_type::Sub = 0x11, Operator_type::Mul = 0x20,
  Operator_type::Div = 0x21, Operator_type::Exp = 0x30, Operator_type::Oparen = 0x01, Operator_type::Cparen = 0x02
}
 

Public Member Functions

 Item (Item_type item_type, Operator_type operator_type, double operand_val=NAN)
 Construct a new Item object. More...
 
 Item (double operand_val)
 Construct a new Item object. More...
 
 Item (Operator_type op=Operator_type::NAO)
 Construct a new Item object. More...
 
bool hasLoPriThan (const Item &rhs) const
 Item内嵌类的工具函数 More...
 
bool isOperator () const
 是操作符 More...
 
bool isOperand () const
 是操作数 More...
 
bool isNAO () const
 是NAO? More...
 
int8_t priority () const
 获取优先级. More...
 

Static Public Member Functions

static Item nao ()
 获得一个NAO(非法操作符) More...
 
static Item excOp (const Item &op, const Item &opL=nao(), const Item &opR=nao())
 执行一次运算. More...
 

Public Attributes

Item_type item_type
 项的类型 More...
 
Operator_type operator_type
 操作符类型 More...
 
double operand_val = NAN
 操作数的值(为操作符时, 无效) More...
 

Static Public Attributes

static const int8_t priOfAdd = static_cast<int8_t>(Operator_type::Add) >> 4
 二元加法的优先级(同减法) More...
 
static const int8_t priOfMul = static_cast<int8_t>(Operator_type::Mul) >> 4
 二元乘法的优先级(同除法) More...
 

Friends

bool operator== (const Item &lhs, const Item &rhs)
 operator== More...
 

Detailed Description

< 后缀式的元素: 操作数, 操作符

Definition at line 129 of file Rpn.hh.

Member Enumeration Documentation

◆ Item_type

< 项的类型

Enumerator
Operand 

操作数

Operator 

操作符

Definition at line 131 of file Rpn.hh.

◆ Operator_type

enum RPN::Rpn_t::Item::Operator_type : int8_t
strong
Enumerator
NAO 

Not an operator(lowest priority): 0xFF.

priority = 算术右移4位(得0 ~ 7, -1). 0: 未定义; -1: NAO; 1 ~ 7: 一般运算符, 7为最高优先级

Add 

lowest(but NAO) priority: 0x01

Sub 
Mul 
Div 
Exp 

highest priority: 0x07

Oparen 

undefine priority : 0x00

Cparen 

Definition at line 137 of file Rpn.hh.

Constructor & Destructor Documentation

◆ Item() [1/3]

RPN::Rpn_t::Item::Item ( Item_type  item_type,
Operator_type  operator_type,
double  operand_val = NAN 
)
inline

Construct a new Item object.

Parameters
item_type
operator_type
operand_val

Definition at line 165 of file Rpn.hh.

Referenced by nao().

Here is the caller graph for this function:

◆ Item() [2/3]

RPN::Rpn_t::Item::Item ( double  operand_val)
inlineexplicit

Construct a new Item object.

构造一个操作数item

Parameters
operand_val

Definition at line 174 of file Rpn.hh.

◆ Item() [3/3]

RPN::Rpn_t::Item::Item ( Operator_type  op = Operator_type::NAO)
inlineexplicit

Construct a new Item object.

构造一个操作符item(默认构造函数)

Parameters
op

Definition at line 183 of file Rpn.hh.

Member Function Documentation

◆ excOp()

Rpn_t::Item RPN::Rpn_t::Item::excOp ( const Item op,
const Item opL = nao(),
const Item opR = nao() 
)
static

执行一次运算.

Note
一元运算符, arg2或arg3为NAO.
Parameters
op
opL
opR
Returns
Item

Definition at line 702 of file Rpn.hh.

References isNAO(), isOperand(), isOperator(), operand_val, and operator_type.

Referenced by RPN::Rpn_t::calcVal().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasLoPriThan()

bool RPN::Rpn_t::Item::hasLoPriThan ( const Item rhs) const

Item内嵌类的工具函数

运算符优先级lhs < rhs. NAO(非法运算符)的优先级为最低

Parameters
rhs
Returns
true
false

Definition at line 685 of file Rpn.hh.

References item_type, Operator, and priority().

Referenced by RPN::Rpn_t::infixListToPostfixList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isNAO()

bool RPN::Rpn_t::Item::isNAO ( ) const
inline

是NAO?

Note
操作数不是NAO
Returns
true
false

Definition at line 220 of file Rpn.hh.

References isOperator(), NAO, and operator_type.

Referenced by excOp(), and RPN::Rpn_t::infixListToPostfixList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ isOperand()

bool RPN::Rpn_t::Item::isOperand ( ) const
inline

是操作数

Returns
true 是操作数
false 非操作数

Definition at line 211 of file Rpn.hh.

References item_type, and Operand.

Referenced by excOp().

Here is the caller graph for this function:

◆ isOperator()

bool RPN::Rpn_t::Item::isOperator ( ) const
inline

是操作符

Returns
true 是操作符
false 不是操作符

Definition at line 203 of file Rpn.hh.

References item_type, and Operator.

Referenced by excOp(), and isNAO().

Here is the caller graph for this function:

◆ nao()

static Item RPN::Rpn_t::Item::nao ( )
inlinestatic

获得一个NAO(非法操作符)

Returns
Item

Definition at line 227 of file Rpn.hh.

References Item(), NAO, and Operator.

Referenced by RPN::Rpn_t::infixListToPostfixList().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ priority()

int8_t RPN::Rpn_t::Item::priority ( ) const
inline

获取优先级.

Note
有效: -1(NAO), 0(未定义), 1~7(一般运算符)
Returns
int8_t

Definition at line 235 of file Rpn.hh.

References operator_type.

Referenced by hasLoPriThan(), and RPN::Rpn_t::infixListToPostfixList().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ operator==

bool operator== ( const Item lhs,
const Item rhs 
)
friend

operator==

Parameters
lhs
rhs
Returns
true
false

Definition at line 740 of file Rpn.hh.

Member Data Documentation

◆ item_type

Item_type RPN::Rpn_t::Item::item_type

项的类型

Definition at line 154 of file Rpn.hh.

Referenced by hasLoPriThan(), isOperand(), isOperator(), RPN::Rpn_t::itemToStr(), and RPN::operator==().

◆ operand_val

double RPN::Rpn_t::Item::operand_val = NAN

操作数的值(为操作符时, 无效)

Definition at line 156 of file Rpn.hh.

Referenced by RPN::Rpn_t::calcVal(), excOp(), RPN::Rpn_t::itemToStr(), and RPN::operator==().

◆ operator_type

Operator_type RPN::Rpn_t::Item::operator_type

操作符类型

Definition at line 155 of file Rpn.hh.

Referenced by excOp(), RPN::Rpn_t::infixListToPostfixList(), isNAO(), RPN::Rpn_t::itemToStr(), RPN::operator==(), and priority().

◆ priOfAdd

const int8_t RPN::Rpn_t::Item::priOfAdd = static_cast<int8_t>(Operator_type::Add) >> 4
static

二元加法的优先级(同减法)

Definition at line 252 of file Rpn.hh.

Referenced by RPN::Rpn_t::infixListToPostfixList().

◆ priOfMul

const int8_t RPN::Rpn_t::Item::priOfMul = static_cast<int8_t>(Operator_type::Mul) >> 4
static

二元乘法的优先级(同除法)

Definition at line 258 of file Rpn.hh.

Referenced by RPN::Rpn_t::infixListToPostfixList().


The documentation for this struct was generated from the following file: