-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCObject.h
44 lines (35 loc) · 933 Bytes
/
GCObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by v4kst1z.
//
#pragma once
#include "Common.h"
class Visitor;
class GarbageCollectedBase {
public:
explicit GarbageCollectedBase(int obj_size, bool mark = false)
: mark_(mark), obj_size_(obj_size) {}
virtual void Trace(Visitor *visitor) const {}
int GetObjSize() { return obj_size_; }
virtual ~GarbageCollectedBase() = default;
private:
bool mark_;
int obj_size_;
friend class Visitor;
friend class TinyGC;
};
template <typename T>
class GarbageCollected : public GarbageCollectedBase {
public:
GarbageCollected() : GarbageCollectedBase(sizeof(T), false) {}
void Trace(Visitor *visitor) const override {}
DISALLOW_COPY_AND_ASSIGN(GarbageCollected);
};
template <typename T>
class Member {
public:
explicit Member(T *raw) : raw_(raw) {}
T *GetRaw() const { return raw_; }
DISALLOW_COPY_AND_ASSIGN(Member);
private:
T *raw_;
};