Bash++
Bash++ compiler internal documentation
bash_if.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 Andrew S. Rightenburg
3 * Bash++: Bash with classes
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7#pragma once
8
9#include <vector>
10#include <utility>
11#include <string>
12#include <memory>
13
14#include "bpp.h"
15#include "bpp_string.h"
16#include "bpp_code_entity.h"
17
18namespace bpp {
19
38class bash_if : public bpp_string {
39 private:
40 std::vector<std::pair<std::string, std::string>> conditional_branches;
41 public:
42 void new_branch();
43 void add_condition_code(const std::string& condition_code);
44 void add_branch_code(const std::string& branch_code);
45 const std::vector<std::pair<std::string, std::string>>& get_conditional_branches() const;
46};
47
59 private:
60 std::shared_ptr<bpp::bash_if> if_statement;
61 public:
62 void set_if_statement(std::shared_ptr<bpp::bash_if> if_statement);
63 std::shared_ptr<bpp::bash_if> get_if_statement() const;
64
65 std::string get_code() const override;
66 std::string get_pre_code() const override;
67 std::string get_post_code() const override;
68};
69
70} // namespace bpp
A branch of an if statement in Bash++.
Definition bash_if.h:58
void set_if_statement(std::shared_ptr< bpp::bash_if > if_statement)
Definition bash_if_branch.cpp:11
std::shared_ptr< bpp::bash_if > get_if_statement() const
Definition bash_if_branch.cpp:15
std::string get_pre_code() const override
Return the contents of the pre-code buffer as a string.
Definition bash_if_branch.cpp:23
std::string get_post_code() const override
Return the contents of the post-code buffer as a string.
Definition bash_if_branch.cpp:31
std::string get_code() const override
Return the contents of the main code buffer as a string.
Definition bash_if_branch.cpp:19
std::shared_ptr< bpp::bash_if > if_statement
Definition bash_if.h:60
An if statement in Bash++.
Definition bash_if.h:38
std::vector< std::pair< std::string, std::string > > conditional_branches
Definition bash_if.h:40
void new_branch()
Definition bash_if.cpp:11
void add_branch_code(const std::string &branch_code)
Definition bash_if.cpp:19
void add_condition_code(const std::string &condition_code)
Definition bash_if.cpp:15
const std::vector< std::pair< std::string, std::string > > & get_conditional_branches() const
Definition bash_if.cpp:23
An entity which can contain code.
Definition bpp_code_entity.h:35
The practical difference between bpp_code_entity and bpp_string is how we handle the code buffers.
Definition bpp_string.h:77
Definition bash_case.cpp:9