1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- /*
- * NICE-Core - efficient algebra and computer vision methods
- * - libfbasics - library of some basic tools
- * See file License for license information.
- */
- /*****************************************************************************/
- #include "core/basics/BinStreamable.h"
- #include <stdexcept>
- #include <fstream>
- #include <core/basics/gzbinstream.h>
- #include "core/basics/Exception.h"
- namespace NICE {
- void BinStreamable::readFromBinFile(const char *filename, Format compression)
- {
- switch(compression) {
- case BIN: {
- ifbinstream file(filename);
- if (!file.good()) {
- fthrow(Exception, "readFromBinFile(): could not open file.");
- }
- readBin(file);
- file.close();
- break;
- }
- #ifdef NICE_USELIB_ZLIB
- case BIN_GZ: {
- igzbinstream file(filename);
- if (!file.good()) {
- fthrow(Exception, "readFromBinFile(): could not open file.");
- }
- readBin(file);
- file.close();
- break;
- }
- #endif
- default:
- fthrow(Exception,
- "File cannot be read! Compression method not supported.");
- break;
- }
- }
- void BinStreamable::writeToBinFile(const char *filename,
- Format compression) const
- {
- switch(compression) {
- case BIN: {
- ofbinstream file(filename);
- if (!file.good()) {
- fthrow(Exception, "writeToBinFile(): could not open file.");
- }
- writeBin(file);
- file.close();
- break;
- }
- #ifdef NICE_USELIB_ZLIB
- case BIN_GZ: {
- ogzbinstream file(filename);
- if (!file.good()) {
- fthrow(Exception, "writeToBinFile(): could not open file.");
- }
- writeBin(file);
- file.close();
- break;
- }
- #endif
- default:
- fthrow(Exception,
- "File cannot be written! Compression method not supported.");
- break;
- }
- }
- }; // namespace NICE
|