2 ===========================================================================
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
22 In addition, the Doom 3 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 Source Code. If not, please request a copy in writing from id Software at the address below.
24 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.
26 ===========================================================================
33 ===============================================================================
37 ===============================================================================
40 typedef idList<idStr> idStrList;
41 typedef idList<idStr*> idStrPtrList;
42 typedef idStr *idStrPtr;
46 idListSortCompare<idStrPtr>
48 Compares two pointers to strings. Used to sort a list of string pointers alphabetically in idList<idStr>::Sort.
52 ID_INLINE int idListSortCompare<idStrPtr>( const idStrPtr *a, const idStrPtr *b ) {
53 return ( *a )->Icmp( **b );
60 Sorts the list of strings alphabetically. Creates a list of pointers to the actual strings and sorts the
61 pointer list. Then copies the strings into another list using the ordered list of pointers.
65 ID_INLINE void idStrList::Sort( cmp_t *compare ) {
73 idList<idStrPtr> pointerList;
75 pointerList.SetNum( num );
76 for( i = 0; i < num; i++ ) {
77 pointerList[ i ] = &( *this )[ i ];
83 other.SetGranularity( granularity );
84 for( i = 0; i < other.Num(); i++ ) {
85 other[ i ] = *pointerList[ i ];
93 idStrList::SortSubSection
95 Sorts a subsection of the list of strings alphabetically.
99 ID_INLINE void idStrList::SortSubSection( int startIndex, int endIndex, cmp_t *compare ) {
105 if ( startIndex < 0 ) {
108 if ( endIndex >= num ) {
111 if ( startIndex >= endIndex ) {
116 idList<idStrPtr> pointerList;
118 s = endIndex - startIndex + 1;
120 pointerList.SetNum( s );
121 for( i = 0; i < s; i++ ) {
122 other[ i ] = ( *this )[ startIndex + i ];
123 pointerList[ i ] = &other[ i ];
128 for( i = 0; i < s; i++ ) {
129 (*this)[ startIndex + i ] = *pointerList[ i ];
139 ID_INLINE size_t idStrList::Size( void ) const {
144 for( i = 0; i < Num(); i++ ) {
145 s += ( *this )[ i ].Size();
152 ===============================================================================
154 idStrList path sorting
156 ===============================================================================
161 idListSortComparePaths
163 Compares two pointers to strings. Used to sort a list of string pointers alphabetically in idList<idStr>::Sort.
166 template<class idStrPtr>
167 ID_INLINE int idListSortComparePaths( const idStrPtr *a, const idStrPtr *b ) {
168 return ( *a )->IcmpPath( **b );
175 Sorts the list of path strings alphabetically and makes sure folders come first.
178 ID_INLINE void idStrListSortPaths( idStrList &list ) {
186 idList<idStrPtr> pointerList;
188 pointerList.SetNum( list.Num() );
189 for( i = 0; i < list.Num(); i++ ) {
190 pointerList[ i ] = &list[ i ];
193 pointerList.Sort( idListSortComparePaths<idStrPtr> );
195 other.SetNum( list.Num() );
196 other.SetGranularity( list.GetGranularity() );
197 for( i = 0; i < other.Num(); i++ ) {
198 other[ i ] = *pointerList[ i ];
204 #endif /* !__STRLIST_H__ */