GCC Code Coverage Report


./
File: mrubynativeobject.hpp
Date: 2024-05-21 01:02:25
Lines:
21/21
100.0%
Functions:
120/127
94.5%
Branches:
1/2
50.0%

Line Branch Exec Source
1 #ifndef __MRUBYNATIVEOBJECT_HPP__
2 #define __MRUBYNATIVEOBJECT_HPP__
3
4 #include <mruby.h>
5
6 #include <string>
7 #include <memory>
8
9 template<class TClass>
10 class NativeObject
11 {
12 std::string classname;
13 mrb_data_type datatype;
14 std::shared_ptr<TClass> instance;
15
16 105 static void destructor(mrb_state* mrb, void* ptr)
17 {
18
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
105 delete (NativeObject<TClass>*)ptr;
19 105 }
20
21 public:
22 105 NativeObject(const std::string& classname, std::shared_ptr<TClass> instance) :
23 105 classname(classname),
24 105 instance(instance)
25 {
26 105 datatype.dfree = destructor;
27 105 datatype.struct_name = classname.c_str();
28 105 }
29
30 303 ~NativeObject()
31 {
32 //printf("NativeObject<%s> %p deleted\n", typeid(TClass).name(), this);
33 303 }
34
35 105 mrb_data_type* get_type_ptr()
36 {
37 105 return &datatype;
38 }
39
40 68 TClass* get_instance() const
41 {
42 68 return instance.get();
43 }
44
45 1 std::shared_ptr<TClass> get_shared_instance() const
46 {
47 1 return instance;
48 }
49
50 37 std::string get_classname() const
51 {
52 37 return classname;
53 }
54
55 1 TClass* operator->()
56 {
57 1 return instance.operator->();
58 }
59
60 TClass &operator*()
61 {
62 return instance.operator*();
63 }
64 };
65
66 #endif // __MRUBYNATIVEOBJECT_HPP__
67