_slist_base.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. *
  3. *
  4. * Copyright (c) 1994
  5. * Hewlett-Packard Company
  6. *
  7. * Copyright (c) 1996,1997
  8. * Silicon Graphics Computer Systems, Inc.
  9. *
  10. * Copyright (c) 1997
  11. * Moscow Center for SPARC Technology
  12. *
  13. * Copyright (c) 1999
  14. * Boris Fomitchev
  15. *
  16. * This material is provided "as is", with absolutely no warranty expressed
  17. * or implied. Any use is at your own risk.
  18. *
  19. * Permission to use or copy this software for any purpose is hereby granted
  20. * without fee, provided the above notices are retained on all copies.
  21. * Permission to modify the code and to distribute modified code is granted,
  22. * provided the above notices are retained, and a notice that the code was
  23. * modified is included with the above copyright notice.
  24. *
  25. */
  26. #ifndef _STLP_SLIST_BASE_C
  27. #define _STLP_SLIST_BASE_C
  28. #ifndef _STLP_INTERNAL_SLIST_BASE_H
  29. # include <stl/_slist_base.h>
  30. #endif
  31. _STLP_BEGIN_NAMESPACE
  32. _STLP_MOVE_TO_PRIV_NAMESPACE
  33. template <class _Dummy>
  34. _Slist_node_base* _STLP_CALL
  35. _Sl_global<_Dummy>::__previous(_Slist_node_base* __head,
  36. const _Slist_node_base* __node) {
  37. while (__head && __head->_M_next != __node)
  38. __head = __head->_M_next;
  39. return __head;
  40. }
  41. template <class _Dummy>
  42. void _STLP_CALL
  43. _Sl_global<_Dummy>::__splice_after(_Slist_node_base* __pos, _Slist_node_base* __head) {
  44. _Slist_node_base* __before_last = __previous(__head, 0);
  45. if (__before_last != __head) {
  46. _Slist_node_base* __after = __pos->_M_next;
  47. __pos->_M_next = __head->_M_next;
  48. __head->_M_next = 0;
  49. __before_last->_M_next = __after;
  50. }
  51. }
  52. template <class _Dummy>
  53. void _STLP_CALL
  54. _Sl_global<_Dummy>::__splice_after(_Slist_node_base* __pos,
  55. _Slist_node_base* __before_first,
  56. _Slist_node_base* __before_last) {
  57. if (__pos != __before_first && __pos != __before_last) {
  58. _Slist_node_base* __first = __before_first->_M_next;
  59. _Slist_node_base* __after = __pos->_M_next;
  60. __before_first->_M_next = __before_last->_M_next;
  61. __pos->_M_next = __first;
  62. __before_last->_M_next = __after;
  63. }
  64. }
  65. template <class _Dummy>
  66. _Slist_node_base* _STLP_CALL
  67. _Sl_global<_Dummy>::__reverse(_Slist_node_base* __node) {
  68. _Slist_node_base* __result = __node;
  69. __node = __node->_M_next;
  70. __result->_M_next = 0;
  71. while(__node) {
  72. _Slist_node_base* __next = __node->_M_next;
  73. __node->_M_next = __result;
  74. __result = __node;
  75. __node = __next;
  76. }
  77. return __result;
  78. }
  79. template <class _Dummy>
  80. size_t _STLP_CALL
  81. _Sl_global<_Dummy>::size(_Slist_node_base* __node) {
  82. size_t __result = 0;
  83. for ( ; __node != 0; __node = __node->_M_next)
  84. ++__result;
  85. return __result;
  86. }
  87. _STLP_MOVE_TO_STD_NAMESPACE
  88. _STLP_END_NAMESPACE
  89. #endif /* _STLP_SLIST_BASE_C */
  90. // Local Variables:
  91. // mode:C++
  92. // End: