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