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

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OList.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/OList.inl 1.50 1996/08/11 23:47:19 B.STEIN Release $
  31.  
  32.  
  33. #ifndef OLIST_INLINED
  34.   #define OLIST_INLINED
  35.  
  36.  
  37. template <class T>
  38. OList<T>::OList(BOOL copyElements)
  39.   : OCollection(copyElements)
  40.   {}
  41.  
  42. template <class T>
  43. OList<T>::OList(OList<T>& list, BOOL copyElements)
  44.   : OCollection(copyElements)
  45. {
  46.  T* temp = list.getFirst();
  47.  
  48.  while (temp) {
  49.    add((T*)temp);
  50.    temp = list.getNext(); }
  51. }
  52.  
  53. template <class T>
  54. OList<T>::~OList()
  55.   {}
  56.  
  57. template <class T>
  58. PSZ OList<T>::isOfType() const
  59.  return("OList<T>"); 
  60. }
  61.  
  62. template <class T>
  63. void OList<T>::freeItem(PVOID elem)
  64.  delete (T*) elem; 
  65. }
  66.  
  67. template <class T>
  68. T* OList<T>::getFirst()
  69.  return((T*) OCollection::_getFirst()); 
  70. }
  71.  
  72. template <class T>
  73. T* OList<T>::getLast()
  74.  return((T*) OCollection::_getLast()); 
  75. }
  76.  
  77. template <class T>
  78. T* OList<T>::get()
  79.  return((T*) OCollection::_getNext()); 
  80. }
  81.  
  82. template <class T>
  83. T* OList<T>::getNext()         
  84.  return((T*) OCollection::_getNext()); 
  85. }
  86.  
  87. template <class T>
  88. T* OList<T>::getNext(T *elem)
  89.  return((T*) OCollection::_getNext(elem)); 
  90. }
  91.  
  92. template <class T>
  93. T* OList<T>::getPrev()          
  94.  return((T*) OCollection::_getPrev()); 
  95. }
  96.  
  97. template <class T>
  98. T* OList<T>::getPrev(T *elem)
  99.  return((T*) OCollection::_getPrev(elem)); 
  100. }
  101.  
  102. template <class T>
  103. T* OList<T>::getItem(ULONG itemNum)
  104.  return((T*) OCollection::_getItem(itemNum)); 
  105. }
  106.  
  107.  
  108. template <class T>
  109. OListItem<T>* OList<T>::first() const
  110. {
  111.  return((OListItem<T>*)OCollection::first);
  112. }
  113.  
  114. template <class T>
  115. OListItem<T>* OList<T>::actual() const
  116. {
  117.  return((OListItem<T>*)OCollection::actual);
  118. }
  119.  
  120. template <class T>
  121. OListItem<T>* OList<T>::last() const
  122. {
  123.  return((OListItem<T>*)OCollection::last);
  124. }
  125.  
  126. template <class T>
  127. OListItem<T>* OList<T>::getNextListItem(T *elem)
  128.  return((OListItem<T>*) OCollection::_getNextListItem(elem)); 
  129. }
  130.  
  131. template <class T>
  132. OListItem<T>* OList<T>::getPrevListItem(T *elem)
  133.  return((OListItem<T>*) OCollection::_getPrevListItem(elem)); 
  134. }
  135.  
  136. template <class T>
  137. void OList<T>::add(T& elem)
  138.  isCopyCollection() ? addLast(new T(elem)) : addLast(&elem);
  139. }
  140.  
  141. template <class T>
  142. void OList<T>::add(T* elem)
  143.  isCopyCollection() ? addLast(new T(*elem)) : addLast((T*)elem);
  144. }
  145.  
  146. template <class T>
  147. OList<T>& OList<T>::operator << (T* elem)
  148. {
  149.  if (elem) add(elem);
  150.  return(*this);
  151. }
  152.  
  153. template <class T>
  154. OList<T>& OList<T>::operator << (T& elem)
  155. {
  156.  add(&elem);
  157.  return(*this);
  158. }
  159.  
  160. template <class T>
  161. OList<T>& OList<T>::operator >> (T& elem)
  162. {
  163.  T* temp = getNext();
  164.  
  165.  if (temp)
  166.    elem = *temp;
  167.  
  168.  return(*this);
  169. }
  170.  
  171. template <class T>
  172. OList<T>& OList<T>::operator >> (T* elem)
  173. {
  174.  elem = getNext();
  175.  return(*this);
  176. }
  177.  
  178.  
  179. template <class T>
  180. void OList<T>::allElementsDo(void (*function)(const T* elem)) const
  181. {
  182.  OListItem<T> *temp = first();
  183.  
  184.  while(temp) {
  185.    if (temp->item)
  186.      function(temp->item);
  187.    temp = temp->next; }
  188. }
  189.  
  190. template <class T>
  191. void OList<T>::allElementsDo(OConstIterator<T>& iter) const
  192. {
  193.  OListItem<T> *temp = first();
  194.  
  195.  while(temp) {
  196.    if (temp->item)
  197.      iter.applyToElement(temp->item);
  198.    temp = temp->next; }
  199. }
  200.  
  201.  
  202. template <class T>
  203. void OList<T>::allElementsDo(void (*function)(T* elem))
  204. {
  205.  T *temp = getFirst();
  206.  
  207.  while(temp) {
  208.    function(temp);
  209.    temp = getNext(); }
  210. }
  211.  
  212. template <class T>
  213. void OList<T>::allElementsDo(OIterator<T>& iter)
  214. {
  215.  T *temp = getFirst();
  216.  
  217.  while(temp) {
  218.    iter.applyToElement(temp);
  219.    temp = getNext(); }
  220. }
  221.  
  222.  
  223. #endif // OLIST_INLINED
  224.  
  225. // end of source
  226.