Bash++
Bash++ compiler internal documentation
bpp_class.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 <memory>
10#include <vector>
11#include <string>
12
13#include "bpp.h"
14#include "bpp_entity.h"
15
16namespace bpp {
17
23class bpp_class : public bpp_entity, public std::enable_shared_from_this<bpp_class> {
24 private:
25 std::vector<std::shared_ptr<bpp_method>> methods;
26 std::vector<std::shared_ptr<bpp_datamember>> datamembers;
28
31 public:
32 std::weak_ptr<bpp_class> get_containing_class() override;
33 bool set_containing_class(std::weak_ptr<bpp::bpp_class> containing_class) override;
34
35 std::shared_ptr<bpp_class> get_class() override;
36
37 void set_name(const std::string& name) override;
38 bool add_method(std::shared_ptr<bpp_method> method);
39 bool add_datamember(std::shared_ptr<bpp_datamember> datamember);
40
41 const std::vector<std::shared_ptr<bpp_method>>& get_methods() const;
42 const std::vector<std::shared_ptr<bpp_datamember>>& get_datamembers() const;
43
44 std::shared_ptr<bpp_method> get_method(const std::string& name, std::shared_ptr<bpp_entity> context);
45 std::shared_ptr<bpp_method> get_method_UNSAFE(const std::string& name);
46 std::shared_ptr<bpp_datamember> get_datamember(const std::string& name, std::shared_ptr<bpp_entity> context);
47 std::shared_ptr<bpp_datamember> get_datamember_UNSAFE(const std::string& name);
48
50 void inherit(std::shared_ptr<bpp_class> parent) override;
51 std::shared_ptr<bpp::bpp_class> get_parent();
52
53 std::vector<std::shared_ptr<bpp_class>> get_all_known_classes() const override;
54};
55
56} // namespace bpp
A class in Bash++.
Definition bpp_class.h:23
void set_name(const std::string &name) override
Definition bpp_class.cpp:59
bool set_containing_class(std::weak_ptr< bpp::bpp_class > containing_class) override
Definition bpp_class.cpp:55
const std::vector< std::shared_ptr< bpp_method > > & get_methods() const
Definition bpp_class.cpp:147
std::shared_ptr< bpp_class > get_class() override
Definition bpp_class.cpp:51
void inherit(std::shared_ptr< bpp_class > parent) override
Inherit from a parent class.
Definition bpp_class.cpp:262
bool add_method(std::shared_ptr< bpp_method > method)
Add a method to the class.
Definition bpp_class.cpp:67
std::vector< std::shared_ptr< bpp_class > > get_all_known_classes() const override
Definition bpp_class.cpp:301
void add_default_toPrimitive()
Add the default toPrimitive method.
Definition bpp_class.cpp:33
std::vector< std::shared_ptr< bpp_datamember > > datamembers
Definition bpp_class.h:26
const std::vector< std::shared_ptr< bpp_datamember > > & get_datamembers() const
Definition bpp_class.cpp:151
std::shared_ptr< bpp_datamember > get_datamember(const std::string &name, std::shared_ptr< bpp_entity > context)
Get a datamember by name.
Definition bpp_class.cpp:223
bool has_custom_toPrimitive
Definition bpp_class.h:27
void remove_default_toPrimitive()
Remove the default toPrimitive method.
Definition bpp_class.cpp:20
std::shared_ptr< bpp::bpp_class > get_parent()
Definition bpp_class.cpp:294
std::shared_ptr< bpp_method > get_method(const std::string &name, std::shared_ptr< bpp_entity > context)
Get a method by name.
Definition bpp_class.cpp:168
std::shared_ptr< bpp_method > get_method_UNSAFE(const std::string &name)
Get a method by name without checking the context.
Definition bpp_class.cpp:201
std::shared_ptr< bpp_datamember > get_datamember_UNSAFE(const std::string &name)
Definition bpp_class.cpp:246
std::weak_ptr< bpp_class > get_containing_class() override
Get the class which contains this entity.
Definition bpp_class.cpp:47
bool add_datamember(std::shared_ptr< bpp_datamember > datamember)
Add a datamember to the class.
Definition bpp_class.cpp:126
std::vector< std::shared_ptr< bpp_method > > methods
Definition bpp_class.h:25
The base class for all entities in the Bash++ compiler.
Definition bpp_entity.h:25
std::string name
Definition bpp_entity.h:27
std::weak_ptr< bpp_class > containing_class
Definition bpp_entity.h:34
void inherit(std::shared_ptr< bpp_entity > parent)
Inherit from a parent entity.
Definition bpp_entity.cpp:93
Definition bash_case.cpp:9