Disable all code related to libXp
[oweals/cde.git] / cde / programs / dtinfo / DtMmdb / dti_cc / CC_Dlist.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 // $XConsortium: CC_Dlist.cc /main/5 1996/08/06 09:27:22 rcs $
24 #ifndef __CC_Dlist_cc
25 #define __CC_Dlist_cc
26
27 #include "Exceptions.hh"
28 #include "cc_exceptions.h"
29 #include "CC_Dlist.h"
30
31
32 //---------------------------------------------------------------------
33 template <class T>
34 CC_Boolean CC_TPtrDlistIterator<T>::operator+=(size_t n)
35 {
36   for ( size_t i = 0; i < n ; i++ ) {
37     if ( !(++(*this)) ) {
38       return (FALSE);
39     }
40   }
41
42   return (TRUE);
43 }
44
45 //---------------------------------------------------------------------
46 template <class T>
47 CC_TPtrDlist<T>::CC_TPtrDlist(const CC_TPtrDlist<T>&adlist)
48 {
49   CC_TPtrDlistIterator<T> dlist_iter( *(CC_TPtrDlist<T> *)&adlist );
50   while ( dlist_iter() ) {
51     insert ( dlist_iter.key() );
52   }
53 }
54
55 //---------------------------------------------------------------------
56 template <class T>
57 void CC_TPtrDlist<T>::clear()
58 {
59   if ( !this->get_destructed() ) {
60     CC_TPtrSlistIterator<T> iter(*this);
61     if (++iter) {
62       while (1) {
63         CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( (CC_List_Iterator_base &)iter );
64         if ( elem ) {
65           delete elem;
66         }
67         else { break; }
68       }
69     }
70   }
71 }
72
73 //---------------------------------------------------------------------
74 template <class T>
75 CC_TPtrDlist<T>::~CC_TPtrDlist()
76 {
77   clear();
78 }
79
80 //---------------------------------------------------------------------
81 template <class T>
82 void CC_TPtrDlist<T>::clearAndDestroy()
83 {
84     
85     this->set_destructed(TRUE);
86     CC_TPtrDlistIterator<T> iter(*this);
87     if ( ++iter ) {
88         while (1) {
89             CC_Link<T> *elem = (CC_Link<T> *)CC_Listbase::remove( (CC_List_Iterator_base &)iter );
90             if ( elem ) { 
91                 T *temp_elem = elem->f_element;
92                 delete temp_elem;
93                 elem->f_element = NULL; // prevent further destruction on this pointer
94                 delete elem; 
95             }
96             else { break; }
97         }
98     }
99 }      
100 #endif  
101