tbaseObjOrigin.hpp
Go to the documentation of this file.
1
2#pragma once
3
4#include "core/ast/tmock.hpp"
6
7namespace by {
8
25 template <typename T> class tbaseObjOrigin: public T {
26 BY(ME(tbaseObjOrigin, T), INIT_META(tbaseObjOrigin))
27 static_assert(tifSub<T, baseObj>::is, "you need to input 'T' as derived class of baseObj.");
28
29 public:
30 tbaseObjOrigin(): me(dumScope::singleton()) {}
31
32 tbaseObjOrigin(const scope& subs): me(subs, *new modifier()) {}
33
34 tbaseObjOrigin(const scope& subs, const modifier& mod): super(), _subs(subs), _mod(mod) {
35 this->_setOrigin(*this);
36 }
37
38 public:
39 const node& getSubPack() const override {
40 static mockNode inner;
41 return inner;
42 }
43
44 const ntype& getType() const override { return ttype<super>::get(); }
45
46 using super::subs;
47
48 scope& subs() override { return *_subs; }
49
50 const modifier& getModifier() const override { return *_mod; }
51
52 clonable* clone() const override {
53 baseObj* ret = new super(*this);
54 ret->_setOrigin(*this);
55 return ret;
56 }
57
58 clonable* cloneDeep() const override {
59 me* ret = new me(*this);
60 ret->onCloneDeep(*this);
61 return ret;
62 }
63
64 void onCloneDeep(const clonable& from) override {
65 const me& rhs = (const me&) from;
66 if(rhs._subs) _subs.bind((scope&) *rhs._subs->cloneDeep());
67 if(rhs._mod) _mod.bind((modifier&) *rhs._mod->cloneDeep());
68 }
69
70 protected:
71 void _setModifier(const modifier& mod) override { _mod.bind(mod); }
72
73 private:
74 tstr<scope> _subs;
75 tstr<modifier> _mod;
76 };
77} // namespace by
Base class for all objects in byeol language.
Definition: baseObj.hpp:24
Interface for objects that can be cloned.
Definition: clonable.hpp:12
Access modifier for class members and func.
Definition: modifier.hpp:12
Base class for all AST nodes in byeol language.
Definition: node.hpp:30
Native type system for byeol language.
Definition: ntype.hpp:19
Template base object origin for user-defined classes.
Definition: tbaseObjOrigin.hpp:25
Mock object template for testing and verification.
Definition: tmock.hpp:13
Strong reference smart pointer with strict type checking.
Definition: tstr.hpp:13
Template type wrapper for type metadata management.
Definition: ttype.hpp:16
Type trait to check if T is subclass of super.
Definition: rtti.hpp:48