[352] | 1 | #include <nv/core/logger.hh>
|
---|
| 2 | #include <nv/core/handle.hh>
|
---|
| 3 | #include <nv/core/math.hh>
|
---|
| 4 | #include <nv/core/string.hh>
|
---|
| 5 | #include <nv/core/random.hh>
|
---|
| 6 |
|
---|
| 7 | int main(int, char* [])
|
---|
| 8 | {
|
---|
| 9 | nv::random& r = nv::random::get();
|
---|
| 10 | r.randomize();
|
---|
| 11 |
|
---|
| 12 | nv::logger log(nv::LOG_TRACE);
|
---|
| 13 | log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
|
---|
| 14 | log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
|
---|
| 15 |
|
---|
| 16 | NV_LOG( nv::LOG_NOTICE, "Logging started" );
|
---|
| 17 |
|
---|
| 18 | {
|
---|
| 19 | nv::handle_manager< nv::handle<> > manager;
|
---|
| 20 | std::vector< nv::handle<> > created;
|
---|
| 21 |
|
---|
| 22 | for ( int i = 0; i < 32000; ++i )
|
---|
| 23 | {
|
---|
| 24 | if ( created.size() > 0 && r.urange( 0, 2 ) == 2 )
|
---|
| 25 | {
|
---|
| 26 | nv::uint32 roll = r.urange( 0, created.size() - 1 );
|
---|
| 27 | nv::handle<> h = created[roll];
|
---|
| 28 | NV_ASSERT( manager.is_valid( h ), "handle not valid!" );
|
---|
| 29 | created.erase( created.begin() + roll );
|
---|
| 30 | manager.free_handle( h );
|
---|
| 31 | }
|
---|
| 32 | else
|
---|
| 33 | {
|
---|
| 34 | created.push_back( manager.create_handle() );
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | for ( const nv::handle<>& h : created )
|
---|
| 39 | {
|
---|
| 40 | NV_ASSERT( manager.is_valid( h ), "handle not valid!" );
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | for ( int i = 0; i < 32000; ++i )
|
---|
| 45 | {
|
---|
| 46 | if ( created.size() > 0 && r.urange( 0, 1 ) == 1 )
|
---|
| 47 | {
|
---|
| 48 | nv::uint32 roll = r.urange( 0, created.size() - 1 );
|
---|
| 49 | nv::handle<> h = created[roll];
|
---|
| 50 | created.erase( created.begin() + roll );
|
---|
| 51 | manager.free_handle( h );
|
---|
| 52 | }
|
---|
| 53 | else
|
---|
| 54 | {
|
---|
| 55 | created.push_back( manager.create_handle() );
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | for ( const nv::handle<>& h : created )
|
---|
| 60 | {
|
---|
| 61 | NV_ASSERT( manager.is_valid( h ), "handle not valid!" );
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | while ( created.size() > 0 )
|
---|
| 65 | {
|
---|
| 66 | nv::uint32 roll = r.urange( 0, created.size() - 1 );
|
---|
| 67 | nv::handle<> h = created[roll];
|
---|
| 68 | created.erase( created.begin() + roll );
|
---|
| 69 | manager.free_handle( h );
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | for ( const nv::handle<>& h : created )
|
---|
| 73 | {
|
---|
| 74 | NV_ASSERT( manager.is_valid( h ), "handle not valid!" );
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | for ( int i = 0; i < 32000; ++i )
|
---|
| 78 | {
|
---|
| 79 | if ( created.size() > 0 && r.urange( 0, 1 ) == 1 )
|
---|
| 80 | {
|
---|
| 81 | nv::uint32 roll = r.urange( 0, created.size() - 1 );
|
---|
| 82 | nv::handle<> h = created[roll];
|
---|
| 83 | created.erase( created.begin() + roll );
|
---|
| 84 | manager.free_handle( h );
|
---|
| 85 | }
|
---|
| 86 | else
|
---|
| 87 | {
|
---|
| 88 | created.push_back( manager.create_handle() );
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | for ( const nv::handle<>& h : created )
|
---|
| 93 | {
|
---|
| 94 | NV_ASSERT( manager.is_valid( h ), "handle not valid!" );
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | while ( created.size() > 0 )
|
---|
| 98 | {
|
---|
| 99 | nv::uint32 roll = r.urange( 0, created.size() - 1 );
|
---|
| 100 | nv::handle<> h = created[roll];
|
---|
| 101 | created.erase( created.begin() + roll );
|
---|
| 102 | manager.free_handle( h );
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | NV_LOG( nv::LOG_NOTICE, "Done" );
|
---|
| 106 |
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
|
---|
| 110 |
|
---|
| 111 | return 0;
|
---|
| 112 | }
|
---|
| 113 |
|
---|