| 450 | |
| 451 | template<typename Vector> |
| 452 | Vector XMLLoader::loadBinary(const Ref<XML>& xml) |
| 453 | { |
| 454 | if (!binFile) |
| 455 | THROW_RUNTIME_ERROR("cannot open file "+binFileName.str()+" for reading"); |
| 456 | |
| 457 | size_t ofs = atol(xml->parm("ofs").c_str()); |
| 458 | fseek(binFile,long(ofs),SEEK_SET); |
| 459 | |
| 460 | /* read size of array */ |
| 461 | size_t size = atol(xml->parm("size").c_str()); |
| 462 | if (size == 0) size = atol(xml->parm("num").c_str()); // version for BGF format |
| 463 | |
| 464 | /* perform security check that we stay in the file */ |
| 465 | if (ofs + size*sizeof(typename Vector::value_type) > binFileSize) |
| 466 | THROW_RUNTIME_ERROR("error reading from binary file: "+binFileName.str()); |
| 467 | |
| 468 | /* read data from file */ |
| 469 | Vector data(size); |
| 470 | if (size != fread(data.data(), sizeof(typename Vector::value_type), data.size(), binFile)) |
| 471 | THROW_RUNTIME_ERROR("error reading from binary file: "+binFileName.str()); |
| 472 | |
| 473 | return data; |
| 474 | } |
| 475 | |
| 476 | std::vector<float> XMLLoader::loadFloatArray(const Ref<XML>& xml) |
| 477 | { |