Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | Related Pages | Examples

list.h

00001 //  Copyright (c) 1996-2001 by Autodesk, Inc.
00002 //
00003 //  By using this code, you are agreeing to the terms and conditions of
00004 //  the License Agreement included in the documentation for this code.
00005 //
00006 //  AUTODESK MAKES NO WARRANTIES, EXPRESS OR IMPLIED, AS TO THE CORRECTNESS
00007 //  OF THIS CODE OR ANY DERIVATIVE WORKS WHICH INCORPORATE IT. AUTODESK
00008 //  PROVIDES THE CODE ON AN "AS-IS" BASIS AND EXPLICITLY DISCLAIMS ANY
00009 //  LIABILITY, INCLUDING CONSEQUENTIAL AND INCIDENTAL DAMAGES FOR ERRORS,
00010 //  OMISSIONS, AND OTHER PROBLEMS IN THE CODE.
00011 //
00012 //  Use, duplication, or disclosure by the U.S. Government is subject to
00013 //  restrictions set forth in FAR 52.227-19 (Commercial Computer Software
00014 //  Restricted Rights) and DFAR 252.227-7013(c)(1)(ii) (Rights in Technical
00015 //  Data and Computer Software), as applicable.
00016 //
00017 
00018 #if !defined LIST_HEADER
00019 #define LIST_HEADER
00020 
00022 class WHIPTK_API WT_Item
00023 {
00024     friend class WT_Item_List;
00025 private:
00026     WT_Item* m_next;
00027     WT_Item* m_prev;
00028 
00029     virtual void _deleteObject (void *) {
00030         WD_Complain ("object not deleted");
00031     } // prohibited, must be implemented in subclass
00032 
00033     WT_Item (WT_Item const &)
00034         : m_next (WD_Null)
00035         , m_prev (WD_Null)
00036     {
00037         WD_Complain ("cannot copy WT_Item");
00038     } // prohibited
00039 
00040     WT_Item & operator= (WT_Item const &)
00041     {
00042         WD_Complain ("cannot assign WT_Item");
00043         return *this;
00044     } // prohibited
00045 
00046 public:
00048     WT_Item()
00049         : m_next(WD_Null)
00050         , m_prev(WD_Null)
00051     { };
00052 
00054     virtual ~WT_Item() { m_next = m_prev = WD_Null; };
00055 
00057     WT_Item* next() { return m_next; };
00058 
00060     WT_Item* prev() { return m_prev; };
00061 
00063     void set_next(
00064         WT_Item *item 
00065         )
00066     { m_next = item; };
00067 
00069     void set_prev(
00070         WT_Item *item 
00071         )
00072     { m_prev = item; };
00073 
00074 };
00075 
00077 class WHIPTK_API WT_Item_List
00078 {
00079 private:
00080     WT_Item *m_head;
00081     WT_Item *m_tail;
00082 
00083     WT_Item_List (WT_Item_List const &)
00084         : m_head (WD_Null)
00085         , m_tail (WD_Null)
00086     {
00087         WD_Complain ("cannot copy WT_Item_List");
00088     } // prohibited
00089 
00090     WT_Item_List operator= (WT_Item_List const &)
00091     {
00092         WD_Complain ("cannot assign WT_Item_List");
00093         return *this;
00094     } // prohibited
00095 
00096 public:
00098     WT_Item_List()
00099     : m_head(WD_Null), m_tail(WD_Null) {}
00100 
00102     WT_Item_List(
00103         WT_Item* first 
00104         )
00105     : m_head(first), m_tail(first) {}
00106 
00108     virtual ~WT_Item_List() {}
00109 
00111     void add_front( WT_Item* item )
00112     {
00113         if (item)
00114         {
00115             item->set_prev(WD_Null);
00116             item->set_next(m_head);
00117             set_head(item);
00118         }
00119     }
00120 
00122     void add_tail(WT_Item *item)
00123     {
00124         if (item)
00125         {
00126             if (!m_head)
00127             {
00128                 set_head(item);
00129             }
00130             else
00131             {
00132                 item->set_prev(m_tail);
00133                 item->set_next(WD_Null);
00134                 m_tail->set_next(item);
00135                 m_tail = item;
00136             }
00137         }
00138     }
00139 
00141     WT_Integer32 count() const
00142     {
00143         WT_Item *current = m_head;
00144         WT_Integer32 count = 0;
00145         while (current)
00146         {   count++;
00147             current = current->next();
00148         }
00149         return count;
00150     }
00151 
00153     WT_Item*  get_head() const
00154     {
00155         return m_head;
00156     }
00157 
00159     WT_Item*  get_tail() const
00160     {
00161         return m_tail;
00162     }
00163 
00165     WT_Boolean is_empty() const
00166     {
00167         return ((m_head == WD_Null) && (m_head == m_tail)) ? WD_True : WD_False;
00168     }
00169 
00171     void remove_all()
00172     {
00173         WT_Item *head,*tail;
00174         while( !is_empty() )
00175         {
00176             head = get_head();
00177             tail = head->next();
00178             head->_deleteObject(head);
00179             set_head(tail);
00180             if (!tail)
00181                 set_tail(WD_Null);
00182         }
00183     }
00184 
00185 protected:
00187     void  set_head(WT_Item* item)
00188     {
00189         m_head = item;
00190         if (item && !m_tail) set_tail(item);
00191     }
00192 
00194     void  set_tail(WT_Item* item)
00195     {
00196         m_tail = item;
00197         if (item && !m_head) set_head(item);
00198     }
00199 };
00200 
00201 #endif // LIST_HEADER

Generated on Tue May 17 12:07:44 2005 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.1