home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oclsrc15.zip / OCL / Include / OSortedList.inl < prev    next >
Text File  |  1996-08-12  |  5KB  |  244 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OSortedList.inl
  5.  
  6. /*
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  * 1. Redistributions of source code must retain the above copyright
  11.  *    notice, this list of conditions and the following disclaimer.
  12.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  13.  *    endorse or promote products derived from this software
  14.  *    without specific prior written permission.
  15.  * 3. See OCL.INF for a detailed copyright notice.
  16.  *
  17.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  18.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27.  * SUCH DAMAGE.
  28.  */
  29.  
  30. // $Header: W:/Projects/OCL/Include/rcs/OSortedList.inl 1.50 1996/08/11 23:47:30 B.STEIN Release $
  31.  
  32. #ifndef SORTEDLIST_INLINED
  33.   #define SORTEDLIST_INLINED
  34.  
  35. template <class T>
  36. OSortedList<T>::OSortedList(BOOL copyElements)
  37.   : OOrderedCollection(copyElements)
  38.   {}
  39.  
  40. template <class T>
  41. OSortedList<T>::OSortedList(OSortedList<T>& slist, BOOL copyElements)
  42.   : OOrderedCollection(copyElements)
  43. {
  44.  T* temp = slist.getFirst();
  45.  
  46.  while (temp) {
  47.    add((T*)temp);
  48.    temp = slist.getNext(); }
  49. }
  50.  
  51.  
  52. template <class T>
  53. OSortedList<T>::~OSortedList()
  54.   {}
  55.  
  56. template <class T>
  57. PSZ OSortedList<T>::isOfType() const
  58.  return("OSortedList<T>"); 
  59. }
  60.  
  61. template <class T>
  62. void OSortedList<T>::freeItem(PVOID elem)
  63.  delete (T*) elem; 
  64. }
  65.  
  66. template <class T>
  67. BOOL OSortedList<T>::_isLess(PVOID first, PVOID second)
  68.  return(isLess((T*)first, (T*)second)); 
  69. }
  70.  
  71. template <class T>
  72. T* OSortedList<T>::getFirst()
  73.  return((T*) OCollection::_getFirst()); 
  74. }
  75.  
  76. template <class T>
  77. T* OSortedList<T>::getLast()
  78.  return((T*) OCollection::_getLast()); 
  79. }
  80.  
  81. template <class T>
  82. T* OSortedList<T>::get()
  83.  return((T*) OCollection::_getNext()); 
  84. }
  85.  
  86. template <class T>
  87. T* OSortedList<T>::getNext()         
  88.  return((T*) OCollection::_getNext()); 
  89. }
  90.  
  91. template <class T>
  92. T* OSortedList<T>::getNext(T *elem)
  93.  return((T*) OCollection::_getNext(elem)); 
  94. }
  95.  
  96. template <class T>
  97. T* OSortedList<T>::getPrev()          
  98.  return((T*) OCollection::_getPrev()); 
  99. }
  100.  
  101. template <class T>
  102. T* OSortedList<T>::getPrev(T *elem)
  103.  return((T*) OCollection::_getPrev(elem)); 
  104. }
  105.  
  106. template <class T>
  107. T* OSortedList<T>::getItem(ULONG itemNum)
  108.  return((T*) OCollection::_getItem(itemNum)); 
  109. }
  110.  
  111.  
  112. template <class T>
  113. OListItem<T>* OSortedList<T>::first() const
  114. {
  115.  return((OListItem<T>*)OCollection::first);
  116. }
  117.  
  118. template <class T>
  119. OListItem<T>* OSortedList<T>::actual() const
  120. {
  121.  return((OListItem<T>*)OCollection::actual);
  122. }
  123.  
  124. template <class T>
  125. OListItem<T>* OSortedList<T>::last() const
  126. {
  127.  return((OListItem<T>*)OCollection::last);
  128. }
  129.  
  130. template <class T>
  131. OListItem<T>* OSortedList<T>::getNextListItem(T *elem)
  132.  return((OListItem<T>*) OCollection::_getNextListItem(elem)); 
  133. }
  134.  
  135. template <class T>
  136. OListItem<T>* OSortedList<T>::getPrevListItem(T *elem)
  137.  return((OListItem<T>*) OCollection::_getPrevListItem(elem)); 
  138. }
  139.  
  140. template <class T>
  141. void OSortedList<T>::add(T& elem)
  142.  isCopyCollection() ? addSorted(new T(elem)) : addSorted(&elem);
  143. }
  144.  
  145. template <class T>
  146. void OSortedList<T>::add(T* elem)
  147.  isCopyCollection() ? addSorted(new T(*elem)) : addSorted((T*)elem);
  148. }
  149.  
  150. template <class T>
  151. OSortedList<T>& OSortedList<T>::operator << (T* elem)
  152. {
  153.  if (elem) add(elem);
  154.  return(*this);
  155. }
  156.  
  157. template <class T>
  158. OSortedList<T>& OSortedList<T>::operator << (T& elem)
  159. {
  160.  add(&elem);
  161.  return(*this);
  162. }
  163.  
  164. template <class T>
  165. OSortedList<T>& OSortedList<T>::operator >> (T& elem)
  166. {
  167.  T* temp = getNext();
  168.  
  169.  if (temp)
  170.    elem = *temp;
  171.  
  172.  return(*this);
  173. }
  174.  
  175. template <class T>
  176. OSortedList<T>& OSortedList<T>::operator >> (T* elem)
  177. {
  178.  elem = getNext();
  179.  return(*this);
  180. }
  181.  
  182.  
  183. template <class T>
  184. void OSortedList<T>::allElementsDo(void (*function)(const T* elem)) const
  185. {
  186.  OListItem<T> *temp = first();
  187.  
  188.  while(temp) {
  189.    if (temp->item)
  190.      function(temp->item);
  191.    temp = temp->next; }
  192. }
  193.  
  194. template <class T>
  195. void OSortedList<T>::allElementsDo(OConstIterator<T>& iter) const
  196. {
  197.  OListItem<T> *temp = first();
  198.  
  199.  while(temp) {
  200.    if (temp->item)
  201.      iter.applyToElement(temp->item);
  202.    temp = temp->next; }
  203. }
  204.  
  205. template <class T>
  206. void OSortedList<T>::allElementsDo(void (*function)(T* elem))
  207. {
  208.  T *temp = getFirst();
  209.  
  210.  while(temp) {
  211.    function(temp);
  212.    temp = getNext(); }
  213. }
  214.  
  215. template <class T>
  216. void OSortedList<T>::allElementsDo(OIterator<T>& iter)
  217. {
  218.  T *temp = getFirst();
  219.  
  220.  while(temp) {
  221.    iter.applyToElement(temp);
  222.    temp = getNext(); }
  223. }
  224.  
  225.  
  226. #endif // OSORTEDLIST_INLINED
  227.  
  228. // end of source
  229.