| 393 | typename T |
| 394 | > |
| 395 | typename enable_if_c<std::numeric_limits<T>::is_signed,bool>::type unpack_int ( |
| 396 | T& item, |
| 397 | std::istream& in |
| 398 | ) |
| 399 | /*! |
| 400 | requires |
| 401 | - T is a signed integral type |
| 402 | ensures |
| 403 | - if (there are no problems deserializing item) then |
| 404 | - returns false |
| 405 | - #item == the value stored in in |
| 406 | - else |
| 407 | - returns true |
| 408 | |
| 409 | !*/ |
| 410 | { |
| 411 | COMPILE_TIME_ASSERT(sizeof(T) <= 8); |
| 412 | |
| 413 | |
| 414 | unsigned char buf[8]; |
| 415 | unsigned char size; |
| 416 | bool is_negative; |
| 417 | |
| 418 | std::streambuf* sbuf = in.rdbuf(); |
| 419 | |
| 420 | item = 0; |
| 421 | int ch = sbuf->sbumpc(); |
| 422 | if (ch != EOF) |
| 423 | { |
| 424 | size = static_cast<unsigned char>(ch); |
| 425 | } |
| 426 | else |
| 427 | { |
| 428 | in.setstate(std::ios::badbit); |
| 429 | return true; |
| 430 | } |
| 431 | |
| 432 | if (size&0x80) |
| 433 | is_negative = true; |
| 434 | else |
| 435 | is_negative = false; |
| 436 | size &= 0x0F; |
| 437 | |
| 438 | // check if the serialized object is too big |
| 439 | if (size > (unsigned long)tmin<sizeof(T),8>::value || size == 0) |
| 440 | { |
| 441 | return true; |
| 442 | } |
| 443 | |
| 444 | if (sbuf->sgetn(reinterpret_cast<char*>(&buf),size) != size) |
| 445 | { |
| 446 | in.setstate(std::ios::badbit); |
| 447 | return true; |
| 448 | } |
| 449 | |
| 450 | |
| 451 | for (unsigned char i = size-1; true; --i) |
| 452 | { |
nothing calls this directly
no outgoing calls
no test coverage detected