list.h

Go to the documentation of this file.
00001 //  Copyright (c) 1996-2006 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 
00024 
00026 class WHIPTK_API WT_Item
00027 {
00028     friend class WT_Item_List;
00029 
00030 private:
00031     WT_Item* m_next;
00032     WT_Item* m_prev;
00033 
00034     virtual void _deleteObject (void *) {
00035         WD_Complain ("object not deleted");
00036     } // prohibited, must be implemented in subclass
00037 
00038     WT_Item (WT_Item const &)
00039         : m_next (WD_Null)
00040         , m_prev (WD_Null)
00041     {
00042         WD_Complain ("cannot copy WT_Item");
00043     } // prohibited
00044 
00045     WT_Item & operator= (WT_Item const &)
00046     {
00047         WD_Complain ("cannot assign WT_Item");
00048         return *this;
00049     } // prohibited
00050 
00051 protected:
00053     WT_Item()
00054         : m_next(WD_Null)
00055         , m_prev(WD_Null)
00056     { };
00057 
00059     virtual ~WT_Item() { m_next = m_prev = WD_Null; };
00060 
00061 public:
00063     WT_Item* next() { return m_next; };
00064 
00066     WT_Item* prev() { return m_prev; };
00067 
00069     void set_next(
00070         WT_Item *item 
00071         )
00072     { m_next = item; };
00073 
00075     void set_prev(
00076         WT_Item *item 
00077         )
00078     { m_prev = item; };
00079 
00080 };
00081 
00083 class WHIPTK_API WT_Item_List
00084 {
00085 
00086 private:
00087     WT_Item *m_head;
00088     WT_Item *m_tail;
00089 
00090     WT_Item_List (WT_Item_List const &)
00091         : m_head (WD_Null)
00092         , m_tail (WD_Null)
00093     {
00094         WD_Complain ("cannot copy WT_Item_List");
00095     } // prohibited
00096 
00097     WT_Item_List operator= (WT_Item_List const &)
00098     {
00099         WD_Complain ("cannot assign WT_Item_List");
00100         return *this;
00101     } // prohibited
00102 
00103 protected:
00105     WT_Item_List()
00106     : m_head(WD_Null), m_tail(WD_Null) {}
00107 
00109     WT_Item_List(
00110         WT_Item* first 
00111         )
00112     : m_head(first), m_tail(first) {}
00113 
00115     virtual ~WT_Item_List() {}
00116 public:
00118     void add_front( WT_Item* item )
00119     {
00120         if (item)
00121         {
00122             item->set_prev(WD_Null);
00123             item->set_next(m_head);
00124             set_head(item);
00125         }
00126     }
00127 
00129     void add_tail(WT_Item *item)
00130     {
00131         if (item)
00132         {
00133             if (!m_head)
00134             {
00135                 set_head(item);
00136             }
00137             else
00138             {
00139                 item->set_prev(m_tail);
00140                 item->set_next(WD_Null);
00141                 m_tail->set_next(item);
00142                 m_tail = item;
00143             }
00144         }
00145     }
00146 
00148     WT_Integer32 count() const
00149     {
00150         WT_Item *current = m_head;
00151         WT_Integer32 count = 0;
00152         while (current)
00153         {   count++;
00154             current = current->next();
00155         }
00156         return count;
00157     }
00158 
00160     WT_Item*  get_head() const
00161     {
00162         return m_head;
00163     }
00164 
00166     WT_Item*  get_tail() const
00167     {
00168         return m_tail;
00169     }
00170 
00172     WT_Boolean is_empty() const
00173     {
00174         return ((m_head == WD_Null) && (m_head == m_tail)) ? WD_True : WD_False;
00175     }
00176 
00178     void remove_all()
00179     {
00180         WT_Item *head,*tail;
00181         while( !is_empty() )
00182         {
00183             head = get_head();
00184             tail = head->next();
00185             head->_deleteObject(head);
00186             set_head(tail);
00187             if (!tail)
00188                 set_tail(WD_Null);
00189         }
00190     }
00191 
00192 protected:
00194     void  set_head(WT_Item* item)
00195     {
00196         m_head = item;
00197         if (item && !m_tail) set_tail(item);
00198     }
00199 
00201     void  set_tail(WT_Item* item)
00202     {
00203         m_tail = item;
00204         if (item && !m_head) set_head(item);
00205     }
00206 };
00207 
00208 #endif // LIST_HEADER

Generated on Tue Jan 6 22:41:13 2009 for Autodesk DWF Whip 2D Toolkit by  doxygen 1.4.5