Utility.hxx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. ** Copyright (C) 1996, 1997 Microsoft Corporation. All Rights Reserved.
  3. **
  4. ** File: utility.hxx
  5. **
  6. ** Author:
  7. **
  8. ** Description:
  9. ** Source for templated methods in the llo library. See llo.h.
  10. **
  11. ** History:
  12. */
  13. /*
  14. ** Definitions for the Slist_utl class:
  15. */
  16. template<class T, class Sink> void Slist_utl<T, Sink>::purge(bool deleteF)
  17. {
  18. //Note ... do the test for deleteF outside the loop for speed reasons
  19. if (deleteF)
  20. {
  21. //Nuking an item updates the list's first pointer,
  22. //so this works even if it looks funny.
  23. Slink_utl<T, Sink>* f;
  24. while (f = first()) //not ==
  25. {
  26. delete f;
  27. }
  28. }
  29. else
  30. {
  31. //ditto for unlinking.
  32. Slink_utl<T, Sink>* f;
  33. while (f = first()) //not ==
  34. {
  35. f->unlink();
  36. }
  37. }
  38. sink();
  39. }
  40. template<class T, class Sink> bool Slist_utl<T, Sink>::first(const T& t)
  41. {
  42. Slink_utl<T,Sink>* l = new Slink_utl<T,Sink>(t);
  43. if (l)
  44. {
  45. first(l);
  46. return true;
  47. }
  48. else
  49. return false;
  50. }
  51. template<class T, class Sink> bool Slist_utl<T, Sink>::last(const T& t)
  52. {
  53. Slink_utl<T,Sink>* l = new Slink_utl<T,Sink>(t);
  54. if (l)
  55. {
  56. last(l);
  57. return true;
  58. }
  59. else
  60. return false;
  61. }
  62. /*
  63. ** Definitions for the Slink_utl class:
  64. */
  65. template<class T, class Sink> bool Slink_utl<T, Sink>::next(const T& t)
  66. {
  67. if (m_list)
  68. return next(new Slink_utl<T,Sink>(t));
  69. else
  70. return false;
  71. }
  72. template<class T, class Sink> bool Slink_utl<T, Sink>::txen(const T& t)
  73. {
  74. if (m_list)
  75. return txen(new Slink_utl<T,Sink>(t));
  76. else
  77. return false;
  78. }
  79. /*
  80. ** Definitions for the Mlist_utl class:
  81. */
  82. template<class T> void Mlist_utl<T>::purge(bool deleteF)
  83. {
  84. lock();
  85. //Note ... do the test for deleteF outside the loop for speed reasons
  86. if (deleteF)
  87. {
  88. //Nuking an item updates the list's first pointer,
  89. //so this works even if it looks funny.
  90. Mlink_utl<T>* f;
  91. while (f = first()) //not ==
  92. {
  93. delete f;
  94. }
  95. }
  96. else
  97. {
  98. //ditto for unlinking.
  99. Mlink_utl<T>* f;
  100. while (f = first()) //not ==
  101. {
  102. f->unlink();
  103. }
  104. }
  105. unlock();
  106. }
  107. template<class T> bool Mlist_utl<T>::first(const T& t)
  108. {
  109. Mlink_utl<T>* l = new Mlink_utl<T>(t);
  110. if (l)
  111. {
  112. first(l);
  113. return true;
  114. }
  115. else
  116. return false;
  117. }
  118. template<class T> bool Mlist_utl<T>::last(const T& t)
  119. {
  120. Mlink_utl<T>* l = new Mlink_utl<T>(t);
  121. if (l)
  122. {
  123. last(l);
  124. return true;
  125. }
  126. else
  127. return false;
  128. }
  129. template<class T> void Mlist_utl<T>::first(Mlink_utl<T>* l)
  130. {
  131. lock();
  132. List_utl::first(l);
  133. unlock();
  134. }
  135. template<class T> Mlink_utl<T>* Mlist_utl<T>::first(void) const
  136. {
  137. lock();
  138. Mlink_utl<T>* l = (Mlink_utl<T>*)List_utl::first();
  139. unlock();
  140. return l;
  141. }
  142. template<class T> void Mlist_utl<T>::last(Mlink_utl<T>* l)
  143. {
  144. lock();
  145. List_utl::last(l);
  146. unlock();
  147. }
  148. template<class T> Mlink_utl<T>* Mlist_utl<T>::last(void) const
  149. {
  150. lock();
  151. Mlink_utl<T>* l = (Mlink_utl<T>*)List_utl::last();
  152. unlock();
  153. return l;
  154. }
  155. template<class T> Mlink_utl<T>* Mlist_utl<T>::operator [] (int index) const
  156. {
  157. lock();
  158. Mlink_utl<T>* l = (Mlink_utl<T>*)List_utl::operator [](index);
  159. unlock();
  160. return l;
  161. }
  162. /*
  163. ** Definitions for the Mlink_utl class:
  164. */
  165. template<class T> inline bool Mlink_utl<T>::next(const T& t)
  166. {
  167. if (m_list)
  168. return next(new Mlink_utl<T>(t));
  169. else
  170. return false;
  171. }
  172. template<class T> inline bool Mlink_utl<T>::txen(const T& t)
  173. {
  174. if (m_list)
  175. return txen(new Mlink_utl<T>(t));
  176. else
  177. return false;
  178. }