StrList.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #ifndef __STRLIST_H__
  21. #define __STRLIST_H__
  22. /*
  23. ===============================================================================
  24. idStrList
  25. ===============================================================================
  26. */
  27. typedef idList<idStr> idStrList;
  28. typedef idList<idStr*> idStrPtrList;
  29. typedef idStr *idStrPtr;
  30. ///*
  31. //================
  32. //idListSortCompare<idStrPtr>
  33. //
  34. //Compares two pointers to strings. Used to sort a list of string pointers alphabetically in idList<idStr>::Sort.
  35. //================
  36. //*/
  37. //template<>
  38. //ID_INLINE int idListSortCompare<idStrPtr, memTag_t _tag_ >( const idStrPtr *a, const idStrPtr *b ) {
  39. // return ( *a )->Icmp( **b );
  40. //}
  41. ///*
  42. //================
  43. //idStrList::Sort
  44. //
  45. //Sorts the list of strings alphabetically. Creates a list of pointers to the actual strings and sorts the
  46. //pointer list. Then copies the strings into another list using the ordered list of pointers.
  47. //================
  48. //*/
  49. //template<>
  50. //ID_INLINE void idStrList::Sort( cmp_t *compare ) {
  51. // int i;
  52. //
  53. // if ( !num ) {
  54. // return;
  55. // }
  56. //
  57. // idList<idStr> other;
  58. // idList<idStrPtr> pointerList;
  59. //
  60. // pointerList.SetNum( num );
  61. // for( i = 0; i < num; i++ ) {
  62. // pointerList[ i ] = &( *this )[ i ];
  63. // }
  64. //
  65. // pointerList.Sort();
  66. //
  67. // other.SetNum( num );
  68. // other.SetGranularity( granularity );
  69. // for( i = 0; i < other.Num(); i++ ) {
  70. // other[ i ] = *pointerList[ i ];
  71. // }
  72. //
  73. // this->Swap( other );
  74. //}
  75. ///*
  76. //================
  77. //idStrList::SortSubSection
  78. //
  79. //Sorts a subsection of the list of strings alphabetically.
  80. //================
  81. //*/
  82. //template<>
  83. //ID_INLINE void idStrList::SortSubSection( int startIndex, int endIndex, cmp_t *compare ) {
  84. // int i, s;
  85. //
  86. // if ( !num ) {
  87. // return;
  88. // }
  89. // if ( startIndex < 0 ) {
  90. // startIndex = 0;
  91. // }
  92. // if ( endIndex >= num ) {
  93. // endIndex = num - 1;
  94. // }
  95. // if ( startIndex >= endIndex ) {
  96. // return;
  97. // }
  98. //
  99. // idList<idStr> other;
  100. // idList<idStrPtr> pointerList;
  101. //
  102. // s = endIndex - startIndex + 1;
  103. // other.SetNum( s );
  104. // pointerList.SetNum( s );
  105. // for( i = 0; i < s; i++ ) {
  106. // other[ i ] = ( *this )[ startIndex + i ];
  107. // pointerList[ i ] = &other[ i ];
  108. // }
  109. //
  110. // pointerList.Sort();
  111. //
  112. // for( i = 0; i < s; i++ ) {
  113. // (*this)[ startIndex + i ] = *pointerList[ i ];
  114. // }
  115. //}
  116. /*
  117. ================
  118. idStrList::Size
  119. ================
  120. */
  121. template<>
  122. ID_INLINE size_t idStrList::Size() const {
  123. size_t s;
  124. int i;
  125. s = sizeof( *this );
  126. for( i = 0; i < Num(); i++ ) {
  127. s += ( *this )[ i ].Size();
  128. }
  129. return s;
  130. }
  131. /*
  132. ===============================================================================
  133. idStrList path sorting
  134. ===============================================================================
  135. */
  136. //
  137. ///*
  138. //================
  139. //idListSortComparePaths
  140. //
  141. //Compares two pointers to strings. Used to sort a list of string pointers alphabetically in idList<idStr>::Sort.
  142. //================
  143. //*/
  144. //template<class idStrPtr>
  145. //ID_INLINE int idListSortComparePaths( const idStrPtr *a, const idStrPtr *b ) {
  146. // return ( *a )->IcmpPath( **b );
  147. //}
  148. ///*
  149. //================
  150. //idStrListSortPaths
  151. //
  152. //Sorts the list of path strings alphabetically and makes sure folders come first.
  153. //================
  154. //*/
  155. //ID_INLINE void idStrListSortPaths( idStrList &list ) {
  156. // int i;
  157. //
  158. // if ( !list.Num() ) {
  159. // return;
  160. // }
  161. //
  162. // idList<idStr> other;
  163. // idList<idStrPtr> pointerList;
  164. //
  165. // pointerList.SetNum( list.Num() );
  166. // for( i = 0; i < list.Num(); i++ ) {
  167. // pointerList[ i ] = &list[ i ];
  168. // }
  169. //
  170. // pointerList.Sort( idListSortComparePaths<idStrPtr> );
  171. //
  172. // other.SetNum( list.Num() );
  173. // other.SetGranularity( list.GetGranularity() );
  174. // for( i = 0; i < other.Num(); i++ ) {
  175. // other[ i ] = *pointerList[ i ];
  176. // }
  177. //
  178. // list.Swap( other );
  179. //}
  180. #endif /* !__STRLIST_H__ */