BashSpark
Loading...
Searching...
No Matches
bs::shell_node_if Class Referencefinal

Conditional execution node (if-then-else). More...

#include <shell_node.h>

Inheritance diagram for bs::shell_node_if:
Collaboration diagram for bs::shell_node_if:

Public Member Functions

 shell_node_if (std::size_t nPos, std::unique_ptr< shell_node_evaluable > &&pCondition, std::unique_ptr< shell_node_evaluable > &&pCaseIf, std::unique_ptr< shell_node_evaluable > &&pCaseElse)
 Construct an if node.
 
shell_status evaluate (shell_session &oSession) const override
 Evaluate the if statement.
 
const shell_node_evaluableget_condition () const noexcept
 Get the condition node.
 
const shell_node_evaluableget_case_if () const noexcept
 Get the 'if' branch node.
 
const shell_node_evaluableget_case_else () const noexcept
 Get the 'else' branch node.
 
- 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.
 
- 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.
 

Additional Inherited Members

- 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.
 
- 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

Conditional execution node (if-then-else).

Represents an if statement with a condition and two branches: the 'if' branch executed on success and the optional 'else' branch executed on failure.

Constructor & Destructor Documentation

◆ shell_node_if()

bs::shell_node_if::shell_node_if ( std::size_t  nPos,
std::unique_ptr< shell_node_evaluable > &&  pCondition,
std::unique_ptr< shell_node_evaluable > &&  pCaseIf,
std::unique_ptr< shell_node_evaluable > &&  pCaseElse 
)

Construct an if node.

Exceptions
shell_node_invalid_argumentIf pCondition or pCaseIf is null.
Parameters
nPosPosition in the input stream where the if starts.
pConditionOwned evaluable node representing the condition.
pCaseIfOwned evaluable block executed when condition returns success.
pCaseElseOwned evaluable block executed when condition returns error (may be null).

Member Function Documentation

◆ evaluate()

shell_status bs::shell_node_if::evaluate ( shell_session oSession) const
overridevirtual

Evaluate the if statement.

The condition is evaluated first. If it returns success, the pCaseIf branch is evaluated and its status returned; otherwise pCaseElse (if present) is evaluated and its status returned. The exact semantics follow shell evaluation rules for conditionals.

Parameters
oSessionSession context used for evaluation.
Returns
shell_status Status from the executed branch or the condition.

Implements bs::shell_node_evaluable.

◆ get_case_else()

const shell_node_evaluable * bs::shell_node_if::get_case_else ( ) const
inlinenoexcept

Get the 'else' branch node.

Returns
Non-owning pointer to the 'else' block or nullptr.

◆ get_case_if()

const shell_node_evaluable * bs::shell_node_if::get_case_if ( ) const
inlinenoexcept

Get the 'if' branch node.

Returns
Non-owning pointer to the 'if' block.

◆ get_condition()

const shell_node_evaluable * bs::shell_node_if::get_condition ( ) const
inlinenoexcept

Get the condition node.

Returns
const Non-owning pointer to condition.

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