forb
type_primitive.hpp
1 #ifndef FORBCC_PRIMITIVE_TYPE_H
2 #define FORBCC_PRIMITIVE_TYPE_H
3 
4 #include <templates/shareable.hpp>
5 #include <types/type.hpp>
6 #include <module.hpp>
7 
8 
9 namespace forbcc {
10 
12  class type_primitive : public type, public shareable<type_primitive> {
13 
14  /* *********************************************** ATTRIBUTES *********************************************** */
15  private:
18  std::string actual_type;
19 
21  size_t _size = 0;
22 
23  /* ************************************************* STATIC ************************************************* */
24  public:
27 
32 
33  private:
35  class static_initializer {
36  public:
38  static_initializer();
39  };
40 
42  static static_initializer _init;
43 
44  /* ********************************************** CONSTRUCTORS ********************************************** */
45  public:
47  type_primitive() : type() {};
48 
50  type_primitive(const std::string &name, const std::string &actual_type, const size_t size)
51  : type(nullptr, name), actual_type(actual_type), _size(size) {};
52 
53  /**************************************************************************************************************/
54 
56  ~type_primitive() override = default;
57 
59  type_primitive(type_primitive &&) = default;
60 
63 
65  type_primitive(const type_primitive &) = default;
66 
68  type_primitive &operator=(const type_primitive &) = default;
69 
70  /**************************************************************************************************************/
71 
73  void print_declaration(code_ostream &) const override {};
74 
76  void print_definition(code_ostream &) const override {};
77 
79  std::string codename() const final {
80  return actual_type;
81  };
82 
84  size_t size_of() const override {
85  return _size;
86  };
87 
89  size_t alignment() const override {
90  return _size;
91  };
92 
93 
94  };
95 
96 } // namespace forbcc
97 
98 #endif //FORBCC_PRIMITIVE_TYPE_H
void print_declaration(code_ostream &) const override
Does nothing, primitive types do not need to be declared.
Definition: type_primitive.hpp:73
~type_primitive() override=default
This class is virtual, so it requires a virtual destructor.
std::string codename() const final
The codename for primitive types is defined by their actual type.
Definition: type_primitive.hpp:79
A template that can be used to declare a list of unique ordered items.
Definition: ordered_unique_list.hpp:16
static type_primitive_list known_types
The list of all known primitive types.
Definition: type_primitive.hpp:31
size_t alignment() const override
Returns the alignment of the given type.
Definition: type_primitive.hpp:89
A template that can be used to ease the declaration of a shared_pointer of a given type...
Definition: shareable.hpp:13
type_primitive & operator=(type_primitive &&)=default
This class supports moving.
void print_definition(code_ostream &) const override
Does nothing, primitive types do not need to be defined.
Definition: type_primitive.hpp:76
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
type_primitive(const std::string &name, const std::string &actual_type, const size_t size)
Each primitive types corresponds to an actual type with fixed size.
Definition: type_primitive.hpp:50
Definition: code_ostream.hpp:11
Identifies one of the primitive types recognized by the library when parsing a FORB IDL file...
Definition: type_primitive.hpp:12
Base class used to define primitive types, custom types (structures) and arrays.
Definition: type.hpp:22
type_primitive()
Empty primitive type, used to preallocate variables in arrays or to use later assignment operator...
Definition: type_primitive.hpp:47
size_t size_of() const override
The size of the given type.
Definition: type_primitive.hpp:84