00001 #ifndef SAFE_LIST_CLASS 00002 #define SAFE_LIST_CLASS 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : safe_list * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 1998-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "node_dll.h" 00019 00020 #include <basis/object_base.h> 00021 00022 // forward. 00023 class reader_writer_lock; 00024 00025 namespace nodes { 00026 00027 // forward. 00028 class list; 00029 class safe_list_read_iterator; 00030 class safe_list_write_iterator; 00031 class safe_node; 00032 00034 00053 class NODES_CLASS_STYLE safe_list : public virtual object_base 00054 { 00055 public: 00056 safe_list(); 00058 ~safe_list(); 00059 00060 IMPLEMENT_CLASS_NAME("safe_list"); 00061 00062 // the iterators can be created at the head or the tail of the list. the 00063 // following provide notational convenience but are based on the list 00064 // positions from common (in basis/definitions). 00065 typedef common::list_positions iterator_positions; 00066 static const iterator_positions HEAD; 00067 static const iterator_positions TAIL; 00068 00069 safe_list_read_iterator *open_reader(iterator_positions where = HEAD); 00071 00074 safe_list_write_iterator *open_writer(iterator_positions where = HEAD); 00076 00077 void close_reader(safe_list_read_iterator * &to_close); 00079 void close_writer(safe_list_write_iterator * &to_close); 00081 00082 bool empty(safe_list_read_iterator &hook); 00084 00086 bool empty(safe_list_write_iterator &hook); 00088 00089 int elements(safe_list_read_iterator &hook); 00091 00094 int elements(safe_list_write_iterator &hook); 00096 00097 void zap(safe_list_write_iterator &writer); 00099 00103 void insert(safe_list_write_iterator &writer, safe_node *to_insert); 00105 00110 safe_node *remove(safe_list_write_iterator &writer); 00112 00115 private: 00116 friend class safe_list_read_iterator; 00117 friend class safe_list_write_iterator; 00118 list *_storage; 00119 reader_writer_lock *_gate_keeper; 00120 00121 // not permitted. 00122 safe_list(const safe_list &); 00123 safe_list &operator =(const safe_list &); 00124 }; 00125 00127 00129 00138 class NODES_CLASS_STYLE safe_list_read_iterator 00139 { 00140 public: 00141 void next(); 00142 void previous(); 00143 00144 const safe_node *observe() const; 00145 00146 bool is_head(); 00147 bool is_tail(); 00148 00149 void jump_head(); 00150 void jump_tail(); 00151 00152 ~safe_list_read_iterator(); 00154 00156 protected: 00157 safe_list_read_iterator(const safe_list &mgr, 00158 safe_list::iterator_positions where); 00160 00161 private: 00162 friend class safe_list; 00163 const safe_list &_manager; 00164 void *_hidden_iterator; 00165 00166 // disallowed functions. 00167 safe_list_read_iterator(const safe_list_read_iterator &to_copy); 00168 safe_list_read_iterator &operator =(const safe_list_read_iterator &to_copy); 00169 }; 00170 00172 00174 00183 class NODES_CLASS_STYLE safe_list_write_iterator { 00184 public: 00185 void next(); 00186 void previous(); 00187 00188 safe_node *access(); 00189 00190 bool is_head(); 00191 bool is_tail(); 00192 00193 void jump_head(); 00194 void jump_tail(); 00195 00196 ~safe_list_write_iterator(); 00198 00200 protected: 00201 safe_list_write_iterator(const safe_list &mgr, 00202 safe_list::iterator_positions where); 00204 00205 private: 00206 friend class safe_list; 00207 const safe_list &_manager; 00208 void *_hidden_iterator; 00209 00210 // disallowed functions. 00211 safe_list_write_iterator(const safe_list_write_iterator &to_copy); 00212 safe_list_write_iterator &operator =(const safe_list_write_iterator &to_copy); 00213 }; 00214 00215 } // namespace. 00216 00217 #endif 00218
1.5.1