| 452 | typename mem_manager |
| 453 | > |
| 454 | void array2d<T,mem_manager>:: |
| 455 | set_size ( |
| 456 | long rows, |
| 457 | long cols |
| 458 | ) |
| 459 | { |
| 460 | // make sure requires clause is not broken |
| 461 | DLIB_ASSERT((cols >= 0 && rows >= 0) , |
| 462 | "\tvoid array2d::set_size(long rows, long cols)" |
| 463 | << "\n\tThe array2d can't have negative rows or columns." |
| 464 | << "\n\tthis: " << this |
| 465 | << "\n\tcols: " << cols |
| 466 | << "\n\trows: " << rows |
| 467 | ); |
| 468 | |
| 469 | // set the enumerator back at the start |
| 470 | at_start_ = true; |
| 471 | cur = 0; |
| 472 | |
| 473 | // don't do anything if we are already the right size. |
| 474 | if (nc_ == cols && nr_ == rows) |
| 475 | { |
| 476 | return; |
| 477 | } |
| 478 | |
| 479 | nc_ = cols; |
| 480 | nr_ = rows; |
| 481 | |
| 482 | // free any existing memory |
| 483 | if (data != 0) |
| 484 | { |
| 485 | pool.deallocate_array(data); |
| 486 | data = 0; |
| 487 | } |
| 488 | |
| 489 | // now setup this object to have the new size |
| 490 | try |
| 491 | { |
| 492 | if (nr_ > 0) |
| 493 | { |
| 494 | data = pool.allocate_array(nr_*nc_); |
| 495 | last = data + nr_*nc_ - 1; |
| 496 | } |
| 497 | } |
| 498 | catch (...) |
| 499 | { |
| 500 | if (data) |
| 501 | pool.deallocate_array(data); |
| 502 | |
| 503 | data = 0; |
| 504 | nc_ = 0; |
| 505 | nr_ = 0; |
| 506 | last = 0; |
| 507 | throw; |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | // ---------------------------------------------------------------------------------------- |
nothing calls this directly
no test coverage detected