00001 /* 00002 The lestes compiler suite 00003 Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy 00004 Copyright (C) 2002, 2003, 2004, 2005 Petr Zika 00005 Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala 00006 Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina 00007 Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda 00008 Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar 00009 Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas 00010 00011 This program is free software; you can redistribute it and/or modify 00012 it under the terms of the GNU General Public License as published by 00013 the Free Software Foundation; version 2 of the License. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 See the full text of the GNU General Public License version 2, and 00021 the limitations in the file doc/LICENSE. 00022 00023 By accepting the license the licensee waives any and all claims 00024 against the copyright holder(s) related in whole or in part to the 00025 work, its use, and/or the inability to use it. 00026 00027 */ 00028 #ifndef lestes__std__mem___root_pointer_hh___included 00029 #define lestes__std__mem___root_pointer_hh___included 00030 00031 /*! \file 00032 \brief Wrapped root pointer. 00033 00034 Declaration of root_pointer class representing gc root pointer. 00035 \author pt 00036 */ 00037 #include <lestes/std/mem/simple_pointer.hh> 00038 #include <lestes/std/mem/gc.hh> 00039 package(lestes); 00040 package(std); 00041 package(mem); 00042 00043 // forward declaration to avoid cycle 00044 class keystone; 00045 00046 /*! 00047 \brief Wrapped bare pointer. 00048 00049 Represents starting place for garbage collection. 00050 Used as common ancestor of all ptr template classes. 00051 */ 00052 class root_pointer/* TODO pt remove : public simple_pointer */ { 00053 public: 00054 //! Destructs the root pointer. 00055 inline ~root_pointer(void); 00056 protected: 00057 //! Creates the root pointer. 00058 inline root_pointer(void); 00059 //! Returns the bare pointer. 00060 inline keystone *pointer_get(void) const; 00061 //! Sets the bare pointer. 00062 inline void pointer_set(keystone *a_pointer); 00063 private: 00064 //! The gc accesses private fields for speed. 00065 friend class gc; 00066 //! The wrapped bare pointer. 00067 keystone *pointer; 00068 //! Creates the head of list of pointers. 00069 inline root_pointer(bool); 00070 //! Previous pointer in linked list of all root pointers. 00071 root_pointer *previous; 00072 //! Next pointer in linked list of all root pointers. 00073 root_pointer *next; 00074 //! Hides copy constructor. 00075 root_pointer(const root_pointer &); 00076 //! Hides assignment operator. 00077 root_pointer &operator=(const root_pointer &); 00078 }; 00079 00080 /*! 00081 Creates the head of all pointers in gc. 00082 */ 00083 inline root_pointer::root_pointer(bool): 00084 /* TODO pt remove // pointer is not important 00085 simple_pointer(), */ 00086 // link to itself 00087 previous(this), 00088 // link to itself 00089 next(this) 00090 { 00091 } 00092 00093 /*! 00094 Creates the root pointer without initialization. 00095 Links the pointer into the list of all root pointers. 00096 */ 00097 inline root_pointer::root_pointer(void): 00098 /* TODO pt remove simple_pointer(),*/ 00099 // previous is first 00100 previous(gc::roots), 00101 // insert between first and first's next 00102 next(gc::roots->next) 00103 { 00104 // link before first's next 00105 next->previous = this; 00106 // link after first 00107 gc::roots->next = this; 00108 } 00109 00110 /*! 00111 Destructs the pointer. Leaves the referenced object unchanged. 00112 Unlinks the root pointer from list of all root pointers. 00113 */ 00114 inline root_pointer::~root_pointer(void) { 00115 // because of dummy head of linked list, this operation is well defined 00116 previous->next = next; 00117 next->previous = previous; 00118 } 00119 00120 /*! 00121 Returns the underlying bare pointer. 00122 \return The bare pointer. 00123 */ 00124 inline keystone *root_pointer::pointer_get(void) const { 00125 return pointer; 00126 } 00127 00128 /*! 00129 Sets the underlying bare pointer. 00130 \param a_pointer The new bare pointer. 00131 */ 00132 inline void root_pointer::pointer_set(keystone *a_pointer) { 00133 pointer = a_pointer; 00134 } 00135 00136 end_package(mem); 00137 end_package(std); 00138 end_package(lestes); 00139 #endif 00140 /* vim: set ft=lestes : */
1.5.1-20070107