list.h

Go to the documentation of this file.
00001 #ifndef LIST_CLASS
00002 #define LIST_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : 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 namespace nodes {
00021 
00022 class node;  // forward.
00023 
00025 
00036 class NODES_CLASS_STYLE list
00037 {
00038 public:
00039   list();
00041 
00042   ~list();
00044 
00045   int elements() const;
00047 
00049   bool empty() const;
00051 
00053 
00054 
00058   class NODES_CLASS_STYLE iterator {
00059   public:
00060     iterator(const list *mgr, node *start) : _cursor(start), _manager(mgr) {}
00062 
00065     void operator ++();  
00066     void operator --();  
00067     void operator ++(int) { ++(*this); }  
00068     void operator --(int) { --(*this); }  
00069 
00070   
00071     inline void next() { (*this)++; }  
00072     inline void previous() { (*this)--; }  
00073 
00074     bool operator ==(const iterator &to_compare) const;
00076     bool operator !=(const iterator &tc) const { return !(*this == tc); }
00078 
00079     bool is_head() const;
00081 
00090     bool is_tail() const;
00092 
00093     void jump_head();  
00094     void jump_tail();  
00095 
00096     const node *observe();  
00097 
00105     node *access();  
00106 
00107   private:
00108     node *_cursor;  
00109     friend class list;  
00110     const list *_manager;  
00111   };
00112 
00113   iterator head() const { return iterator(this, _head); }
00115   iterator tail() const { return iterator(this, _tail); }
00117 
00118   int index(const iterator &it) const { return items_from_head(it); }
00120 
00122   bool set_index(iterator &to_set, int new_index);
00124 
00125   // storage and retrieval actions.
00126   // Note: all of these methods shift the iterator onto the next valid node
00127   // if it is positioned at the beginning or end of the list.
00128 
00129   void append(iterator &where, node *new_node);
00131 
00135   void insert(iterator &where, node *new_node);
00137 
00142   node *remove(iterator &where);
00144 
00148   void zap(iterator &where);
00150 
00153   void zap_all();
00155 
00157   // the following positioning functions could fail if the request is out of
00158   // bounds.  for example, forward cannot go beyond the end of the list.  in
00159   // such cases, false is returned and the list pointer is not moved.
00160 
00161   bool forward(iterator &where, int count);
00163 
00166   bool backward(iterator &where, int count);
00168 
00169   int items_from_head(const iterator &where) const;
00171 
00172   int items_from_tail(const iterator &where) const;
00174 
00176 private:
00177   friend class iterator;
00178   node *_head;  
00179   node *_tail;  
00180 
00181   bool skip_or_ignore(iterator &where, int count);
00183 
00184   // not permitted.
00185   list(const list &);
00186   list &operator =(const list &);
00187 };
00188 
00189 } // namespace.
00190 
00191 #endif
00192 

Generated on Fri Nov 28 04:29:17 2008 for HOOPLE Libraries by  doxygen 1.5.1