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.

157 lines
2.1 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "basicFIFO.h"
  2. inline bool basicFIFO::pushData(void * buffer)
  3. {
  4. if (head == NULL)
  5. {
  6. head = (pDataPackageFIFO) malloc(sizeof(DataPackageFIFO));
  7. if (head == NULL)
  8. {
  9. return false;
  10. };
  11. head->data = (void *) buffer;
  12. head->next = NULL;
  13. tale = head;
  14. nodeCount = 1;
  15. return true;
  16. }
  17. else
  18. {
  19. pDataPackageFIFO tNode;
  20. tNode = (pDataPackageFIFO) malloc(sizeof(DataPackageFIFO));
  21. if (tNode == NULL)
  22. {
  23. return false;
  24. };
  25. tNode->data = (void *) buffer;
  26. tNode->next = NULL;
  27. tale->next = tNode;
  28. tale = tNode;
  29. nodeCount++;
  30. return true;
  31. };
  32. }
  33. bool basicFIFO::pushNode(pDataPackageFIFO & node)
  34. {
  35. if (head == NULL)
  36. {
  37. head = node;
  38. tale = head;
  39. nodeCount = 1;
  40. if (tale->next != NULL)
  41. {
  42. return pushNode(tale->next);
  43. }
  44. else
  45. {
  46. return true;
  47. }
  48. }
  49. else
  50. {
  51. tale->next = node;
  52. tale = node;
  53. nodeCount++;
  54. if (tale->next != NULL)
  55. {
  56. return pushNode(tale->next);
  57. }
  58. else
  59. {
  60. return true;
  61. }
  62. };
  63. }
  64. pDataPackageFIFO basicFIFO::popNode(void)
  65. {
  66. if (head == NULL)
  67. {
  68. return NULL;
  69. };
  70. pDataPackageFIFO rVal;
  71. rVal = head;
  72. head = head->next;
  73. if (tale == rVal)
  74. {
  75. tale = head;
  76. };
  77. nodeCount--;
  78. return rVal;
  79. }
  80. void * basicFIFO::popData(void)
  81. {
  82. if (head == NULL)
  83. {
  84. return NULL;
  85. };
  86. void * rVal;
  87. pDataPackageFIFO tVal;
  88. rVal = head->data;
  89. tVal = head;
  90. head = head->next;
  91. if (tale == tVal)
  92. {
  93. tale = head;
  94. };
  95. nodeCount--;
  96. delete(tVal);
  97. return rVal;
  98. }
  99. bool basicFIFO::clear(void)
  100. {
  101. if (head == NULL)
  102. {
  103. nodeCount = 0;
  104. tale = head;
  105. return true;
  106. };
  107. pDataPackageFIFO tVal;
  108. tVal = head;
  109. head = head->next;
  110. tVal->next = NULL;
  111. removeNode(tVal);
  112. if (head != NULL)
  113. {
  114. this->clear();
  115. }
  116. else
  117. {
  118. tale = NULL;
  119. nodeCount = 0;
  120. };
  121. return true;
  122. }
  123. pDataPackageFIFO basicFIFO::touch(int index)
  124. {
  125. if (index < nodeCount)
  126. {
  127. pDataPackageFIFO rVal;
  128. rVal = head;
  129. while (index)
  130. {
  131. rVal = rVal->next;
  132. index--;
  133. };
  134. return rVal;
  135. };
  136. return NULL;
  137. }
  138. bool basicFIFO::removeNode(pDataPackageFIFO & node)
  139. {
  140. if (node->next == NULL)
  141. {
  142. free(node->data);
  143. delete(node);
  144. return true;
  145. };
  146. return false;
  147. }