Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
5.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: list.hxx
  8. //
  9. // Contents: Defines for list helper functions.
  10. //
  11. // History: 25-Oct-96 kevinr created
  12. //
  13. //--------------------------------------------------------------------------
  14. #ifndef __LIST_INCLUDED__
  15. #define __LIST_INCLUDED__
  16. //--------------------------------------------------------------------------
  17. //
  18. //--------------------------------------------------------------------------
  19. class CNode
  20. {
  21. public:
  22. inline CNode() { m_pnPrev = m_pnNext = NULL; };
  23. inline CNode * Prev() const { return m_pnPrev; };
  24. inline CNode * Next() const { return m_pnNext; };
  25. inline VOID SetPrev(CNode *pn) { m_pnPrev = pn; };
  26. inline VOID SetNext(CNode *pn) { m_pnNext = pn; };
  27. private:
  28. CNode *m_pnPrev;
  29. CNode *m_pnNext;
  30. };
  31. #define DEFINE_NODE_CLASS( class_name, data_type) \
  32. class class_name : public CNode \
  33. { \
  34. public: \
  35. inline class_name() { memset( &m_data, 0, sizeof(m_data)); }; \
  36. inline class_name(data_type *pData) { SetData( pData); }; \
  37. ~ ## class_name(); \
  38. inline class_name * Prev() const { \
  39. return (class_name *)CNode::Prev(); }; \
  40. inline class_name * Next() const { \
  41. return (class_name *)CNode::Next(); }; \
  42. inline VOID SetPrev(class_name *pn) { \
  43. CNode::SetPrev((CNode *)pn); }; \
  44. inline VOID SetNext(class_name *pn) { \
  45. CNode::SetNext((CNode *)pn); }; \
  46. inline data_type * Data() { return &m_data; }; \
  47. inline VOID SetData(data_type *pData) { m_data = *pData; }; \
  48. \
  49. private: \
  50. data_type m_data; \
  51. };
  52. //--------------------------------------------------------------------------
  53. //
  54. //--------------------------------------------------------------------------
  55. class CList
  56. {
  57. public:
  58. inline CList() { m_pnHead = m_pnTail = NULL; m_cNode = 0; };
  59. inline CNode * Head() const { return m_pnHead; };
  60. inline CNode * Tail() const { return m_pnTail; };
  61. inline DWORD Length() const { return m_cNode; };
  62. BOOL InsertHead(CNode *pn);
  63. BOOL InsertTail(CNode *pn);
  64. CNode * Nth( DWORD i);
  65. BOOL Remove( CNode *pn);
  66. private:
  67. CNode *m_pnHead;
  68. CNode *m_pnTail;
  69. DWORD m_cNode;
  70. };
  71. #define DEFINE_LIST_CLASS( class_name, node_class_name) \
  72. class class_name : public CList \
  73. { \
  74. public: \
  75. ~ ## class_name() { \
  76. node_class_name *pnPending; \
  77. for (node_class_name *pn=Head(); pn;) { \
  78. pnPending = pn; \
  79. pn = pn->Next(); \
  80. delete pnPending; \
  81. } \
  82. }; \
  83. inline node_class_name * Head() const { \
  84. return (node_class_name * )CList::Head(); }; \
  85. inline node_class_name * Tail() const { \
  86. return (node_class_name * )CList::Tail(); }; \
  87. inline BOOL InsertHead( node_class_name *pn) { \
  88. return CList::InsertHead( (CNode *)pn); }; \
  89. inline BOOL InsertTail( node_class_name *pn) { \
  90. return CList::InsertTail( (CNode *)pn); }; \
  91. inline node_class_name * Nth( DWORD i) { \
  92. return (node_class_name * )CList::Nth( i); }; \
  93. inline BOOL Remove( node_class_name *pn) { \
  94. return CList::Remove( (CNode *)pn); }; \
  95. };
  96. //--------------------------------------------------------------------------
  97. //
  98. //--------------------------------------------------------------------------
  99. #define DEFINE_LIST_AND_NODE_CLASS( class_name, node_class_name, data_type) \
  100. DEFINE_NODE_CLASS( node_class_name, data_type) \
  101. DEFINE_LIST_CLASS( class_name, node_class_name)
  102. #endif // __LIST_INCLUDED__