BashSpark
Loading...
Searching...
No Matches
bs::shell_node_operator Class Reference

Base class for binary operator nodes (pipe, and, or) with priority handling. More...

#include <shell_node.h>

Inheritance diagram for bs::shell_node_operator:
Collaboration diagram for bs::shell_node_operator:

Public Member Functions

int get_priority () const noexcept
 Get the operator priority.
 
const shell_node_evaluableget_left () const noexcept
 Get (non-owning) pointer to the left operand.
 
const shell_node_evaluableget_right () const noexcept
 Get (non-owning) pointer to the right operand.
 
std::unique_ptr< shell_node_evaluableswap_left (std::unique_ptr< shell_node_evaluable > &&pLeft)
 Swap-in a new left operand, returning the old one.
 
std::unique_ptr< shell_node_evaluableswap_right (std::unique_ptr< shell_node_evaluable > &&pRight)
 Swap-in a new right operand, returning the old one.
 
- Public Member Functions inherited from bs::shell_node_evaluable
 shell_node_evaluable (const shell_node_type nType, const std::size_t nPos)
 Construct an evaluable node.
 
virtual shell_status evaluate (shell_session &oSession) const =0
 Evaluate (execute) the node.
 
- Public Member Functions inherited from bs::shell_node
virtual ~shell_node ()=default
 Virtual default destructor for polymorphic deletion.
 
shell_node_type get_type () const noexcept
 Get the node type.
 
std::size_t get_pos () const noexcept
 Get node position in the original input stream.
 

Static Public Member Functions

static std::unique_ptr< shell_node_evaluablemake (shell_node_type nType, std::size_t nPos, std::unique_ptr< shell_node_evaluable > &&pLeft, std::unique_ptr< shell_node_evaluable > &&pRight)
 Makes an operator node.
 

Static Public Attributes

static constexpr int PRIORITY_PIPE = 5
 Priority for operator pipe.
 
static constexpr int PRIORITY_AND = 4
 Priority for operator and.
 
static constexpr int PRIORITY_OR = 3
 Priority for operator or.
 

Protected Member Functions

 shell_node_operator (shell_node_type nType, std::size_t nPos, int nPriority, std::unique_ptr< shell_node_evaluable > &&pLeft, std::unique_ptr< shell_node_evaluable > &&pRight)
 Construct an operator with both operands.
 
 shell_node_operator (shell_node_type nType, std::size_t nPos, int nPriority)
 
- Protected Member Functions inherited from bs::shell_node
 shell_node (const shell_node_type nType, const std::size_t nPos)
 Protected constructor used by derived classes.
 

Additional Inherited Members

- Protected Attributes inherited from bs::shell_node
const shell_node_type m_nType
 Node type.
 
const std::size_t m_nPos
 Position in the input stream.
 

Detailed Description

Base class for binary operator nodes (pipe, and, or) with priority handling.

Operator nodes hold left and right evaluable children and a priority used when building or reorganizing operator trees.

Constructor & Destructor Documentation

◆ shell_node_operator() [1/2]

bs::shell_node_operator::shell_node_operator ( shell_node_type  nType,
std::size_t  nPos,
int  nPriority,
std::unique_ptr< shell_node_evaluable > &&  pLeft,
std::unique_ptr< shell_node_evaluable > &&  pRight 
)
protected

Construct an operator with both operands.

Exceptions
shell_node_invalid_argumentIf pLeft or pRight is null.
Parameters
nTypeNode type (operator).
nPosPosition in stream.
nPriorityOperator priority.
pLeftLeft operand.
pRightRight operand.

◆ shell_node_operator() [2/2]

bs::shell_node_operator::shell_node_operator ( shell_node_type  nType,
std::size_t  nPos,
int  nPriority 
)
protected
Warning
This constructor supports constructing an operator node without left/right operands. Use with caution; the node will be invalid until left and right are set.
Parameters
nTypeNode type (must be operator).
nPosPosition in stream.
nPriorityPriority of the operator.

Member Function Documentation

◆ get_left()

const shell_node_evaluable * bs::shell_node_operator::get_left ( ) const
inlinenoexcept

Get (non-owning) pointer to the left operand.

Returns
const shell_node_evaluable* Left operand or nullptr.

◆ get_priority()

int bs::shell_node_operator::get_priority ( ) const
inlinenoexcept

Get the operator priority.

Returns
int Priority value (higher means evaluated earlier).

◆ get_right()

const shell_node_evaluable * bs::shell_node_operator::get_right ( ) const
inlinenoexcept

Get (non-owning) pointer to the right operand.

Returns
const shell_node_evaluable* Right operand or nullptr.

◆ make()

std::unique_ptr< shell_node_evaluable > bs::shell_node_operator::make ( shell_node_type  nType,
std::size_t  nPos,
std::unique_ptr< shell_node_evaluable > &&  pLeft,
std::unique_ptr< shell_node_evaluable > &&  pRight 
)
static

Makes an operator node.

Utility that constructs an appropriate operator subclass and performs priority handling if left/right are operator nodes too.

Exceptions
shell_node_invalid_argumentIf pLeft or pRight is null.
shell_node_invalid_argumentIf nType is not an operator node type.
Parameters
nTypeOperator node type.
nPosNode position in stream.
pLeftLeft operand (moved in).
pRightRight operand (moved in).
Returns
std::unique_ptr<shell_node_evaluable> Newly created operator node.

◆ swap_left()

std::unique_ptr< shell_node_evaluable > bs::shell_node_operator::swap_left ( std::unique_ptr< shell_node_evaluable > &&  pLeft)

Swap-in a new left operand, returning the old one.

Exceptions
shell_node_invalid_argumentIf pLeft is null.
Parameters
pLeftNew left operand (moved in).
Returns
std::unique_ptr<shell_node_evaluable> The previous left operand.

◆ swap_right()

std::unique_ptr< shell_node_evaluable > bs::shell_node_operator::swap_right ( std::unique_ptr< shell_node_evaluable > &&  pRight)

Swap-in a new right operand, returning the old one.

Exceptions
shell_node_invalid_argumentIf pRight is null.
Parameters
pRightNew right operand (moved in).
Returns
std::unique_ptr<shell_node_evaluable> The previous right operand.

The documentation for this class was generated from the following files: