forb
interface.hpp
1 //
2 // Created by gabriele on 15/11/18.
3 //
4 
5 #ifndef FORBCC_INTERFACE_H
6 #define FORBCC_INTERFACE_H
7 
8 #include <entity.hpp>
9 #include <module.hpp>
10 #include <templates/ordered_unique_list.hpp>
11 #include <templates/shareable.hpp>
12 
13 namespace forbcc {
14  // Forward declarations
15  class method;
16 
17  class code_ostream;
18 
20  class interface : public entity, public shareable<interface>, public ordered_unique_list<method> {
21  public:
22 
23  /* ********************************************** CONSTRUCTORS ********************************************** */
24 
26  interface() : entity() {};
27 
29  interface(const std::shared_ptr<module> &parent, const std::string &name) : entity(parent, name) {};
30 
31  /**************************************************************************************************************/
32 
34  ~interface() override = default;
35 
37  interface(interface &&) = default;
38 
40  interface &operator=(interface &&) = default;
41 
43  interface(const interface &) = default;
44 
46  interface &operator=(const interface &) = default;
47 
48  /**************************************************************************************************************/
49 
51  void print_declaration(code_ostream &out) const override;
52 
54  void print_definition(code_ostream &out) const override;
55 
56  private:
57 
59  void print_stub_declaration(code_ostream &out) const;
60 
62  void print_skeleton_declaration(code_ostream &out) const;
63 
65  void print_methods_enum(code_ostream &out) const;
66 
68  void print_static_attributes_definition(code_ostream &out) const;
69 
71  void print_factory_match(code_ostream &out) const;
72 
74  void print_factory_create(code_ostream &out) const;
75 
78  void print_narrows(code_ostream &out) const;
79 
81  void print_stub_methods(code_ostream &out) const;
82 
84  void print_skeleton_method(code_ostream &out) const;
85 
87  std::string name_ptr() const {
88  return name() + "_ptr";
89  };
90 
92  std::string name_var() const {
93  return name() + "_var";
94  };
95 
97  std::string name_skeleton() const {
98  return name() + "_skeleton";
99  };
100 
102  std::string name_enum() const {
103  return name() + "_method_codes";
104  };
105 
107  std::string codename_ptr() const {
108  return codename() + "_ptr";
109  };
110 
112  std::string codename_var() const {
113  return codename() + "_var";
114  };
115 
117  std::string codename_skeleton() const {
118  return codename() + "_skeleton";
119  };
120  };
121 } // namespace forbcc
122 
123 
124 #endif //FORBCC_INTERFACE_H
void print_declaration(code_ostream &out) const override
Prints both stub and skeletons declarations.
Definition: interface.cpp:335
virtual std::string codename() const
Returns the codename of the given entity, which is the name of the entity as seen from the global sco...
Definition: entity.hpp:81
A template that can be used to declare a list of unique ordered items.
Definition: ordered_unique_list.hpp:16
interface & operator=(interface &&)=default
This class supports moving.
interface(const std::shared_ptr< module > &parent, const std::string &name)
Using constructors from superclass.
Definition: interface.hpp:29
interface()
Empty interface, used to preallocate variables in arrays or to use later assignment operator...
Definition: interface.hpp:26
A template that can be used to ease the declaration of a shared_pointer of a given type...
Definition: shareable.hpp:13
std::shared_ptr< entity > parent() const
Returns the parent of the given entity.
Definition: entity.hpp:63
std::string name() const
Returns the name of the given entity.
Definition: entity.hpp:68
This output stream supports indentation of code lines, which are formatted at each std::endl...
Definition: code_ostream.hpp:14
Definition: code_ostream.hpp:11
void print_definition(code_ostream &out) const override
Prints both stub and skeletons definitions, among other utilities.
Definition: interface.cpp:346
Any code entity that should be generated by the compiler: namespaces, classes, structures, methods, variables.
Definition: entity.hpp:18
Defines an interface, which will be converted to stub and skeleton pairs upon generation.
Definition: interface.hpp:20
~interface() override=default
This class is virtual, so it requires a virtual destructor.