ReactOS 0.4.15-dev-5669-g09dde2c
test_insert.h File Reference
#include "Prefix.h"
#include <utility>
#include <vector>
#include <cassert>
#include <climits>
#include "random_number.h"
#include "nc_alloc.h"
#include "ThrowCompare.h"
Include dependency graph for test_insert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  container_tag
 
struct  sequence_container_tag
 
struct  associative_container_tag
 
struct  set_tag
 
struct  multiset_tag
 
struct  map_tag
 
struct  multimap_tag
 
struct  identity< _Tp >
 
struct  select1st< _Pair >
 
struct  test_insert_one< C >
 
struct  test_insert_n< C >
 
struct  test_insert_value< C >
 
struct  test_insert_noresize< C >
 
struct  test_insert_range< C, Iter >
 

Functions

template<class C , class Iter >
size_t CountNewItems (const C &, const Iter &firstNew, const Iter &lastNew, sequence_container_tag)
 
template<class C , class Iter >
size_t CountNewItems (const C &c, const Iter &firstNew, const Iter &lastNew, multimap_tag)
 
template<class C , class Iter >
size_t CountNewItems (const C &c, const Iter &firstNew, const Iter &lastNew, multiset_tag)
 
template<class C , class Iter , class KeyOfValue >
size_t CountUniqueItems_Aux (const C &original, Iter firstNew, Iter lastNew, const KeyOfValue &keyOfValue)
 
template<class C , class Iter >
EH_END_NAMESPACE size_t CountUniqueItems (const C &original, const Iter &firstNew, const Iter &lastNew, set_tag)
 
template<class C , class Iter >
size_t CountUniqueItems (const C &original, const Iter &firstNew, const Iter &lastNew, map_tag)
 
template<class C , class Iter >
size_t CountNewItems (const C &original, const Iter &firstNew, const Iter &lastNew, map_tag)
 
template<class C , class Iter >
size_t CountNewItems (const C &original, const Iter &firstNew, const Iter &lastNew, set_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t, associative_container_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t, set_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t, multiset_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t, map_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t, multimap_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t insPos, sequence_container_tag)
 
template<class C , class SrcIter >
void VerifyInsertion (const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t insPos)
 
template<class C , class Value >
void VerifyInsertN (const C &original, const C &result, size_t insCnt, const Value &val, size_t insPos)
 
template<class C >
void prepare_insert_n (C &, size_t)
 
void MakeRandomValue (bool &b)
 
template<class T >
void MakeRandomValue (T &)
 
template<class C , class Position , class Iter >
void do_insert_range (C &c_inst, Position offset, Iter first, Iter last, sequence_container_tag)
 
template<class C , class Position , class Iter >
void do_insert_range (C &c, Position, Iter first, Iter last, associative_container_tag)
 
template<class C , class Position , class Iter >
void do_insert_range (C &c, Position, Iter first, Iter last, multiset_tag)
 
template<class C , class Position , class Iter >
void do_insert_range (C &c, Position, Iter first, Iter last, multimap_tag)
 
template<class C , class Position , class Iter >
void do_insert_range (C &c, Position, Iter first, Iter last, set_tag)
 
template<class C , class Position , class Iter >
void do_insert_range (C &c, Position, Iter first, Iter last, map_tag)
 
template<class C , class Iter >
test_insert_range< C, Iter > insert_range_tester (const C &orig, const Iter &first, const Iter &last)
 
template<class C , class Iter >
test_insert_range< C, Iter > insert_range_at_begin_tester (const C &orig, const Iter &first, const Iter &last)
 
template<class C , class Iter >
test_insert_range< C, Iter > insert_range_at_end_tester (const C &orig, const Iter &first, const Iter &last)
 

Function Documentation

◆ CountNewItems() [1/5]

template<class C , class Iter >
size_t CountNewItems ( const C ,
const Iter &  firstNew,
const Iter &  lastNew,
sequence_container_tag   
)

Definition at line 45 of file test_insert.h.

47{
48 size_t dist = 0;
49#if 0 //def __SUNPRO_CC
50 EH_DISTANCE( firstNew, lastNew, dist );
51#else
52 EH_DISTANCE( Iter(firstNew), Iter(lastNew), dist );
53#endif
54 return dist;
55}
#define EH_DISTANCE(a, b, result)
Definition: Prefix.h:98

Referenced by CountNewItems(), and VerifyInsertion().

◆ CountNewItems() [2/5]

template<class C , class Iter >
size_t CountNewItems ( const C c,
const Iter &  firstNew,
const Iter &  lastNew,
multimap_tag   
)

Definition at line 58 of file test_insert.h.

60{
61 return CountNewItems( c, firstNew, lastNew, sequence_container_tag() );
62}
const GLubyte * c
Definition: glext.h:8905
size_t CountNewItems(const C &, const Iter &firstNew, const Iter &lastNew, sequence_container_tag)
Definition: test_insert.h:45

◆ CountNewItems() [3/5]

template<class C , class Iter >
size_t CountNewItems ( const C c,
const Iter &  firstNew,
const Iter &  lastNew,
multiset_tag   
)

Definition at line 65 of file test_insert.h.

67{
68 return CountNewItems( c, firstNew, lastNew, sequence_container_tag() );
69}

◆ CountNewItems() [4/5]

template<class C , class Iter >
size_t CountNewItems ( const C original,
const Iter &  firstNew,
const Iter &  lastNew,
map_tag   
)

Definition at line 149 of file test_insert.h.

151{
152 return CountUniqueItems( original, firstNew, lastNew,
153 container_category( original ) );
154}
sequence_container_tag container_category(const BitVector &)
EH_END_NAMESPACE size_t CountUniqueItems(const C &original, const Iter &firstNew, const Iter &lastNew, set_tag)
Definition: test_insert.h:126

◆ CountNewItems() [5/5]

template<class C , class Iter >
size_t CountNewItems ( const C original,
const Iter &  firstNew,
const Iter &  lastNew,
set_tag   
)

Definition at line 157 of file test_insert.h.

159{
160 return CountUniqueItems( original, firstNew, lastNew,
161 container_category( original ) );
162}

◆ CountUniqueItems() [1/2]

template<class C , class Iter >
size_t CountUniqueItems ( const C original,
const Iter &  firstNew,
const Iter &  lastNew,
map_tag   
)

Definition at line 135 of file test_insert.h.

137{
138#ifdef EH_MULTI_CONST_TEMPLATE_ARG_BUG
139 return CountUniqueItems_Aux( original, firstNew, lastNew,
140 EH_SELECT1ST_HINT<C::value_type, C::key_type>() );
141#else
142 typedef typename C::value_type value_type;
143 return CountUniqueItems_Aux( original, firstNew, lastNew,
144 EH_STD::select1st<value_type>() );
145#endif
146}
size_t CountUniqueItems_Aux(const C &original, Iter firstNew, Iter lastNew, const KeyOfValue &keyOfValue)
Definition: test_insert.h:76

◆ CountUniqueItems() [2/2]

template<class C , class Iter >
EH_END_NAMESPACE size_t CountUniqueItems ( const C original,
const Iter &  firstNew,
const Iter &  lastNew,
set_tag   
)

Definition at line 126 of file test_insert.h.

128{
129 typedef typename C::value_type value_type;
130 return CountUniqueItems_Aux( original, firstNew, lastNew,
131 EH_STD::identity<value_type>() );
132}

Referenced by CountNewItems().

◆ CountUniqueItems_Aux()

template<class C , class Iter , class KeyOfValue >
size_t CountUniqueItems_Aux ( const C original,
Iter  firstNew,
Iter  lastNew,
const KeyOfValue &  keyOfValue 
)

Definition at line 76 of file test_insert.h.

79{
80 typedef typename C::key_type key;
81 typedef typename C::const_iterator const_iter;
82 typedef EH_STD::vector<key> key_list;
83 typedef typename key_list::iterator key_iterator;
84 key_list keys;
85 size_t dist = 0;
86#ifdef __SUNPRO_CC
87 EH_DISTANCE( firstNew, lastNew, dist );
88#else
89 EH_DISTANCE( Iter(firstNew), Iter(lastNew), dist );
90#endif
91 keys.reserve( dist );
92 for ( Iter x = firstNew; x != lastNew; ++x )
93 keys.push_back( keyOfValue(*x) );
94
95 EH_STD::sort( keys.begin(), keys.end() );
96 key_iterator last = EH_STD::unique( keys.begin(), keys.end() );
97
98 size_t cnt = 0;
99 for ( key_iterator tmp = keys.begin(); tmp != last; ++tmp )
100 {
101 if ( const_iter(original.find( *tmp )) == const_iter(original.end()) )
102 ++cnt;
103 }
104 return cnt;
105}
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
POINT last
Definition: font.c:46
Definition: copy.c:22

Referenced by CountUniqueItems().

◆ do_insert_range() [1/6]

template<class C , class Position , class Iter >
void do_insert_range ( C c,
Position  ,
Iter  first,
Iter  last,
associative_container_tag   
)

Definition at line 461 of file test_insert.h.

463{
464 c.insert( first, last );
465}
const GLint * first
Definition: glext.h:5794

◆ do_insert_range() [2/6]

template<class C , class Position , class Iter >
void do_insert_range ( C c,
Position  ,
Iter  first,
Iter  last,
map_tag   
)

Definition at line 486 of file test_insert.h.

487{
488 c.insert( first, last );
489}

◆ do_insert_range() [3/6]

template<class C , class Position , class Iter >
void do_insert_range ( C c,
Position  ,
Iter  first,
Iter  last,
multimap_tag   
)

Definition at line 474 of file test_insert.h.

475{
476 c.insert( first, last );
477}

◆ do_insert_range() [4/6]

template<class C , class Position , class Iter >
void do_insert_range ( C c,
Position  ,
Iter  first,
Iter  last,
multiset_tag   
)

Definition at line 468 of file test_insert.h.

469{
470 c.insert( first, last );
471}

◆ do_insert_range() [5/6]

template<class C , class Position , class Iter >
void do_insert_range ( C c,
Position  ,
Iter  first,
Iter  last,
set_tag   
)

Definition at line 480 of file test_insert.h.

481{
482 c.insert( first, last );
483}

◆ do_insert_range() [6/6]

template<class C , class Position , class Iter >
void do_insert_range ( C c_inst,
Position  offset,
Iter  first,
Iter  last,
sequence_container_tag   
)

Definition at line 451 of file test_insert.h.

453{
454 typedef typename C::iterator CIter;
455 CIter pos = c_inst.begin();
456 EH_STD::advance( pos, offset );
457 c_inst.insert( pos, first, last );
458}
GLintptr offset
Definition: glext.h:5920

Referenced by test_insert_range< C, Iter >::operator()().

◆ insert_range_at_begin_tester()

template<class C , class Iter >
test_insert_range< C, Iter > insert_range_at_begin_tester ( const C orig,
const Iter &  first,
const Iter &  last 
)

Definition at line 541 of file test_insert.h.

542{
543 return test_insert_range<C, Iter>( orig, first, last , 0);
544}

Referenced by test_bit_vector(), test_deque(), test_list(), test_rope(), test_string(), and test_vector().

◆ insert_range_at_end_tester()

template<class C , class Iter >
test_insert_range< C, Iter > insert_range_at_end_tester ( const C orig,
const Iter &  first,
const Iter &  last 
)

Definition at line 547 of file test_insert.h.

548{
549 return test_insert_range<C, Iter>( orig, first, last , (int)orig.size());
550}

Referenced by test_bit_vector(), test_deque(), test_list(), test_rope(), test_string(), and test_vector().

◆ insert_range_tester()

template<class C , class Iter >
test_insert_range< C, Iter > insert_range_tester ( const C orig,
const Iter &  first,
const Iter &  last 
)

◆ MakeRandomValue() [1/2]

void MakeRandomValue ( bool b)
inline

Definition at line 322 of file test_insert.h.

322{ b = bool(random_number(2) != 0); }
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
#define bool
Definition: nsiface.idl:72
unsigned random_number(size_t range)

Referenced by test_insert_n< C >::test_insert_n(), test_insert_noresize< C >::test_insert_noresize(), test_insert_one< C >::test_insert_one(), and test_insert_value< C >::test_insert_value().

◆ MakeRandomValue() [2/2]

template<class T >
void MakeRandomValue ( T )
inline

Definition at line 325 of file test_insert.h.

325{}

◆ prepare_insert_n()

template<class C >
void prepare_insert_n ( C ,
size_t   
)

Definition at line 318 of file test_insert.h.

318{}

Referenced by test_insert_one< C >::operator()(), and test_insert_n< C >::operator()().

◆ VerifyInsertion() [1/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  insPos 
)
inline

Definition at line 281 of file test_insert.h.

284{
285 EH_ASSERT( result.size() == original.size() +
286 CountNewItems( original, firstNew, lastNew,
287 container_category(original) ) );
288 VerifyInsertion( original, result, firstNew, lastNew, insPos,
289 container_category(original) );
290}
#define EH_ASSERT
Definition: Prefix.h:37
GLuint64EXT * result
Definition: glext.h:11304
void VerifyInsertion(const C &original, const C &result, const SrcIter &firstNew, const SrcIter &lastNew, size_t, associative_container_tag)
Definition: test_insert.h:165

◆ VerifyInsertion() [2/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  insPos,
sequence_container_tag   
)

Definition at line 254 of file test_insert.h.

262{
263 typename C::const_iterator p1 = original.begin();
264 typename C::const_iterator p2 = result.begin();
265 SrcIter tmp(firstNew);
266
267 for ( size_t n = 0; n < insPos; n++, ++p1, ++p2)
268 EH_ASSERT( *p1 == *p2 );
269
270 for (; tmp != lastNew; ++p2, ++tmp ) {
271 EH_ASSERT(p2 != result.end());
272 EH_ASSERT(*p2 == *tmp);
273 }
274
275 for (; p2 != result.end(); ++p1, ++p2 )
276 EH_ASSERT( *p1 == *p2 );
277 EH_ASSERT( p1 == original.end() );
278}
GLdouble n
Definition: glext.h:7729

◆ VerifyInsertion() [3/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  ,
associative_container_tag   
)
inline

Definition at line 165 of file test_insert.h.

168{
169 typedef typename C::const_iterator DstIter;
170 DstIter first1 = original.begin();
171 DstIter first2 = result.begin();
172
173 DstIter* from_orig = new DstIter[original.size()];
174 DstIter* last_from_orig = from_orig;
175
176 // fbp : for hashed containers, the following is needed :
177 while ( first2 != result.end() )
178 {
179 EH_STD::pair<DstIter, DstIter> p = EH_STD::mismatch( first1, original.end(), first2 );
180 if ( p.second != result.end() )
181 {
182 SrcIter srcItem = EH_STD::find( SrcIter(firstNew), SrcIter(lastNew), *p.second );
183
184 if (srcItem == lastNew)
185 {
186 // not found in input range, probably re-ordered from the orig
187 DstIter* tmp;
188 tmp = EH_STD::find( from_orig, last_from_orig, p.first );
189
190 // if already here, exclude
191 if (tmp != last_from_orig)
192 {
193 EH_STD::copy(tmp+1, last_from_orig, tmp);
194 last_from_orig--;
195 }
196 else
197 {
198 // register re-ordered element
199 DstIter dstItem;
200 dstItem = EH_STD::find( first1, original.end(), *p.first );
201 EH_ASSERT( dstItem != original.end() );
202 *last_from_orig = dstItem;
203 last_from_orig++;
204 ++p.first;
205 }
206 }
207 ++p.second;
208 }
209 first1 = p.first;
210 first2 = p.second;
211 }
212
213 delete [] from_orig;
214}
GLfloat GLfloat p
Definition: glext.h:8902

Referenced by test_insert_one< C >::operator()(), test_insert_value< C >::operator()(), test_insert_noresize< C >::operator()(), test_insert_range< C, Iter >::operator()(), and VerifyInsertion().

◆ VerifyInsertion() [4/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  ,
map_tag   
)
inline

Definition at line 236 of file test_insert.h.

239{
240 VerifyInsertion( original, result, firstNew, lastNew,
241 size_t(0), associative_container_tag() );
242}

◆ VerifyInsertion() [5/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  ,
multimap_tag   
)
inline

Definition at line 245 of file test_insert.h.

248{
249 VerifyInsertion( original, result, firstNew, lastNew,
250 size_t(0), associative_container_tag() );
251}

◆ VerifyInsertion() [6/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  ,
multiset_tag   
)
inline

Definition at line 227 of file test_insert.h.

230{
231 VerifyInsertion( original, result, firstNew, lastNew,
232 size_t(0), associative_container_tag() );
233}

◆ VerifyInsertion() [7/7]

template<class C , class SrcIter >
void VerifyInsertion ( const C original,
const C result,
const SrcIter &  firstNew,
const SrcIter &  lastNew,
size_t  ,
set_tag   
)
inline

Definition at line 218 of file test_insert.h.

221{
222 VerifyInsertion( original, result, firstNew, lastNew,
223 size_t(0), associative_container_tag() );
224}

◆ VerifyInsertN()

template<class C , class Value >
void VerifyInsertN ( const C original,
const C result,
size_t  insCnt,
const Value val,
size_t  insPos 
)

Definition at line 293 of file test_insert.h.

295{
296 typename C::const_iterator p1 = original.begin();
297 typename C::const_iterator p2 = result.begin();
298 (void)val; //*TY 02/06/2000 - to suppress unused variable warning under nondebug build
299
300 for ( size_t n = 0; n < insPos; n++ )
301 EH_ASSERT( *p1++ == *p2++ );
302
303 while ( insCnt-- > 0 )
304 {
305 EH_ASSERT(p2 != result.end());
306 EH_ASSERT(*p2 == val );
307 ++p2;
308 }
309
310 while ( p2 != result.end() ) {
311 EH_ASSERT( *p1 == *p2 );
312 ++p1; ++p2;
313 }
314 EH_ASSERT( p1 == original.end() );
315}
GLuint GLfloat * val
Definition: glext.h:7180

Referenced by test_insert_n< C >::operator()().