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.

120 lines
2.2 KiB

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