1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
19 #ifndef _include_jitcraft_rooting_h_
20 #define _include_jitcraft_rooting_h_
28 template <typename T> class Local;
29 template <typename T> class ScopedRoot;
37 Handle(const Handle &other) {
38 thingp_ = other.address();
40 template <typename S> Handle(const Handle<S> &handle) {
42 thingp_ = reinterpret_cast<T * const *>(handle.address());
44 template <typename S> inline Handle(const Local<S> &local);
45 template <typename S> inline Handle(const ScopedRoot<S> &root);
54 operator T *() { return *thingp_; }
55 operator bool() const {
56 return thingp_ && *thingp_;
58 T * const *address() const {
83 Local<Object> *prev() {
86 Local<Object> *toRaw() {
87 return reinterpret_cast<Local<Object>*>(this);
91 // These are implemented in Zone.h.
92 inline explicit Local(Zone *zone, T *thing = NULL);
95 const Local &operator =(T *thing) {
99 T *operator ->() const {
102 T *operator *() const {
105 operator bool () const {
110 return (Object **)&thing_;
112 Object * const *address() const {
113 return (Object * const *)&thing_;
123 // Disallow heap allocation.
124 void *operator new(size_t size);
125 void *operator new[](size_t size);
127 // Disallow copy construction.
128 Local(const Local<T> &other);
129 Local &operator =(const Local &other);
132 // A ScopedRoot is a special kind of handle for storing references on the
134 template <typename T>
140 // This is implemented in Zone.h.
141 inline T **make(T *other);
143 void assign(T *other) {
150 // This is implemented in Zone.h.
151 inline ScopedRoot(T *thing);
153 ScopedRoot &operator =(const ScopedRoot<T> &other) {
157 ScopedRoot &operator =(T *other) {
161 T *operator ->() const {
164 T *operator *() const {
167 operator T *() const {
170 operator bool () const {
173 T **address() const {
178 template <typename T> template <typename S> inline
179 Handle<T>::Handle(const Local<S> &local)
182 thingp_ = reinterpret_cast<T * const *>(local.address());
185 template <typename T> template <typename S> inline
186 Handle<T>::Handle(const ScopedRoot<S> &root)
189 thingp_ = reinterpret_cast<T * const *>(root.address());
194 #endif // _include_jitcraft_rooting_h_