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

Iterative 'for' loop node that iterates over an expandable sequence. More...

#include <shell_node.h>

Inheritance diagram for bs::shell_node_for:
Collaboration diagram for bs::shell_node_for:

Public Member Functions

 shell_node_for (std::size_t nPos, std::string sVariable, std::unique_ptr< shell_node_expandable > &&pSequence, std::unique_ptr< shell_node_evaluable > &&pIterative)
 Construct a for-loop node.
 
shell_status evaluate (shell_session &oSession) const override
 Evaluate the for-loop.
 
const std::string & get_variable () const noexcept
 Get the loop variable name.
 
const shell_node_expandableget_sequence () const noexcept
 Get the sequence expandable.
 
const shell_node_evaluableget_iterative () const noexcept
 Get the iterative block executed on each element.
 
- 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

Iterative 'for' loop node that iterates over an expandable sequence.

The loop assigns successive elements of the expanded sequence to shell session variable m_sVariable and executes the iterative block for each value.

Constructor & Destructor Documentation

◆ shell_node_for()

bs::shell_node_for::shell_node_for ( std::size_t  nPos,
std::string  sVariable,
std::unique_ptr< shell_node_expandable > &&  pSequence,
std::unique_ptr< shell_node_evaluable > &&  pIterative 
)

Construct a for-loop node.

Exceptions
shell_node_invalid_argumentIf pSequence or pIterative is null.
Parameters
nPosPosition in the input stream where the for loop starts.
sVariableName of the loop variable that receives each sequence value (moved in).
pSequenceOwned expandable that yields the sequence to iterate.
pIterativeOwned evaluable block executed for each sequence element.

Member Function Documentation

◆ evaluate()

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

Evaluate the for-loop.

The sequence is expanded (respecting split semantics). For each token produced, the session variable named by m_sVariable is set to that token and m_pIterative is executed. The loop follows shell semantics for control (break/continue) and returns the last command status or an appropriate control status.

Parameters
oSessionSession context used for variable assignment and execution.
Returns
shell_status Status from the loop's execution (last iteration or control status).

Implements bs::shell_node_evaluable.

◆ get_iterative()

const shell_node_evaluable * bs::shell_node_for::get_iterative ( ) const
inlinenoexcept

Get the iterative block executed on each element.

Returns
Non-owning pointer to the iterative block.

◆ get_sequence()

const shell_node_expandable * bs::shell_node_for::get_sequence ( ) const
inlinenoexcept

Get the sequence expandable.

Returns
Non-owning pointer to the sequence node.

◆ get_variable()

const std::string & bs::shell_node_for::get_variable ( ) const
inlinenoexcept

Get the loop variable name.

Returns
Reference to the variable name.

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