|
SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00007 // Encapsulates binary reading operations on a file 00008 /****************************************************************************/ 00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00010 // Copyright (C) 2001-2011 DLR (http://www.dlr.de/) and contributors 00011 /****************************************************************************/ 00012 // 00013 // This program is free software; you can redistribute it and/or modify 00014 // it under the terms of the GNU General Public License as published by 00015 // the Free Software Foundation; either version 2 of the License, or 00016 // (at your option) any later version. 00017 // 00018 /****************************************************************************/ 00019 00020 00021 // =========================================================================== 00022 // included modules 00023 // =========================================================================== 00024 #ifdef _MSC_VER 00025 #include <windows_config.h> 00026 #else 00027 #include <config.h> 00028 #endif 00029 00030 #include <string> 00031 #include "BinaryInputDevice.h" 00032 00033 #ifdef CHECK_MEMORY_LEAKS 00034 #include <foreign/nvwa/debug_new.h> 00035 #endif // CHECK_MEMORY_LEAKS 00036 00037 // =========================================================================== 00038 // constants definitions 00039 // =========================================================================== 00040 #define BUF_MAX 1000 00041 00042 00043 // =========================================================================== 00044 // method definitions 00045 // =========================================================================== 00046 BinaryInputDevice::BinaryInputDevice(const std::string& name) throw() 00047 : myStream(name.c_str(), std::fstream::in|std::fstream::binary) {} 00048 00049 00050 BinaryInputDevice::~BinaryInputDevice() throw() {} 00051 00052 00053 bool 00054 BinaryInputDevice::good() const throw() { 00055 return myStream.good(); 00056 } 00057 00058 00059 BinaryInputDevice& 00060 operator>>(BinaryInputDevice& os, int& i) throw() { 00061 os.myStream.read((char*) &i, sizeof(int)); 00062 return os; 00063 } 00064 00065 00066 BinaryInputDevice& 00067 operator>>(BinaryInputDevice& os, unsigned int& i) throw() { 00068 os.myStream.read((char*) &i, sizeof(unsigned int)); 00069 return os; 00070 } 00071 00072 00073 BinaryInputDevice& 00074 operator>>(BinaryInputDevice& os, SUMOReal& f) throw() { 00075 os.myStream.read((char*) &f, sizeof(SUMOReal)); 00076 return os; 00077 } 00078 00079 00080 BinaryInputDevice& 00081 operator>>(BinaryInputDevice& os, bool& b) throw() { 00082 b = 0; 00083 os.myStream.read((char*) &b, sizeof(char)); 00084 return os; 00085 } 00086 00087 00088 BinaryInputDevice& 00089 operator>>(BinaryInputDevice& os, std::string& s) throw() { 00090 unsigned int size; 00091 os >> size; 00092 if (size<BUF_MAX) { 00093 os.myStream.read((char*) &os.myBuffer, sizeof(char)*size); 00094 os.myBuffer[size] = 0; 00095 s = std::string(os.myBuffer); 00096 return os; 00097 } 00098 return os; 00099 } 00100 00101 00102 BinaryInputDevice& 00103 operator>>(BinaryInputDevice& os, long& l) throw() { 00104 os.myStream.read((char*) &l, sizeof(long)); 00105 return os; 00106 } 00107 00108 00109 00110 /****************************************************************************/ 00111