sortlist.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //***************************************************************************
  2. //
  3. // Sortlist.h -- Sort List defines
  4. //
  5. // MechCommander II
  6. //
  7. //---------------------------------------------------------------------------//
  8. // Copyright (C) Microsoft Corporation. All rights reserved. //
  9. //===========================================================================//
  10. #ifndef SORTLIST_H
  11. #define SORTLIST_H
  12. //***************************************************************************
  13. //--------------
  14. // Include Files
  15. #ifndef DSTD_H
  16. #include "dstd.h"
  17. #endif
  18. //--------------------------------
  19. // Structure and Class Definitions
  20. typedef struct _SortListNode {
  21. float value; // sort value
  22. unsigned long id; // item
  23. } SortListNode;
  24. class SortList {
  25. protected:
  26. SortListNode* list;
  27. long numItems;
  28. public:
  29. void init (void) {
  30. list = NULL;
  31. numItems = 0;
  32. }
  33. SortList (void) {
  34. init();
  35. }
  36. long init (long numItems);
  37. void setId (long index, long id) {
  38. if ((index >= 0) && (index < numItems))
  39. list[index].id = id;
  40. }
  41. void setValue (long index, float value) {
  42. if ((index >= 0) && (index < numItems))
  43. list[index].value = value;
  44. }
  45. long getId (long index) {
  46. return(list[index].id);
  47. }
  48. float getValue (long index) {
  49. return(list[index].value);
  50. }
  51. void clear (bool setToMin = true);
  52. long getNumItems (void) {
  53. return(numItems);
  54. }
  55. void sort (bool descendingOrder = true);
  56. void destroy (void);
  57. ~SortList (void) {
  58. destroy();
  59. }
  60. };
  61. typedef SortList* SortListPtr;
  62. //***************************************************************************
  63. #endif