UniqueList.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : LevelEdit *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/LevelEdit/UniqueList.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 12/14/98 11:09a $*
  29. * *
  30. * $Revision:: 1 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __UNIQUELIST_H
  39. #define __UNIQUELIST_H
  40. #include "Vector.H"
  41. /////////////////////////////////////////////////////////////////////
  42. //
  43. // UniqueListClass
  44. //
  45. template<class T>
  46. class UniqueListClass : public DynamicVectorClass<T>
  47. {
  48. public:
  49. UniqueListClass (void)
  50. : DynamicVectorClass<T> () {}
  51. virtual ~UniqueListClass (void) {}
  52. UniqueListClass<T> & operator += (const UniqueListClass<T> &reference);
  53. bool Add_Unique (T const & object);
  54. void Remove (T const & object);
  55. bool Is_Item_In_List (T const & object);
  56. };
  57. /////////////////////////////////////////////////////////////////////
  58. //
  59. // Is_Item_In_List
  60. //
  61. template<class T>
  62. bool
  63. UniqueListClass<T>::Is_Item_In_List (T const & object)
  64. {
  65. // Assume failure
  66. bool bfound = false;
  67. // Loop through all the objects in this list and see
  68. // if any of them match the provided object
  69. for (int index = 0; (index < Count ()) && !bfound; index ++) {
  70. if (object == Vector[index]) {
  71. bfound = true;
  72. }
  73. }
  74. // Return the true/false result code
  75. return bfound;
  76. }
  77. /////////////////////////////////////////////////////////////////////
  78. //
  79. // Add_Unique
  80. //
  81. template<class T>
  82. UniqueListClass<T> &
  83. UniqueListClass<T>::operator += (const UniqueListClass<T> &reference)
  84. {
  85. for (int index = 0; index < reference.Count (); index ++) {
  86. Add_Unique (reference[index]);
  87. }
  88. return *this;
  89. }
  90. /////////////////////////////////////////////////////////////////////
  91. //
  92. // Add_Unique
  93. //
  94. template<class T>
  95. bool
  96. UniqueListClass<T>::Add_Unique (T const & object)
  97. {
  98. // Assume sucess
  99. bool retval = true;
  100. // If the object isn't already in the list, then add it
  101. if (!Is_Item_In_List (object)) {
  102. retval = Add (object);
  103. }
  104. // Return the true/false result code
  105. return retval;
  106. }
  107. /////////////////////////////////////////////////////////////////////
  108. //
  109. // Remove
  110. //
  111. template<class T>
  112. void
  113. UniqueListClass<T>::Remove (T const & object)
  114. {
  115. // Loop through all the objects in this list and see
  116. // if any of them match the provided object
  117. bool bfound = false;
  118. for (int index = 0; (index < Count ()) && !bfound; index ++) {
  119. if (object == Vector[index]) {
  120. Delete (index);
  121. bfound = true;
  122. }
  123. }
  124. return ;
  125. }
  126. #endif //__UNIQUELIST_H