SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BinaryInputDevice.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // Encapsulates binary reading operations on a file
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
11 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <string>
33 #include "BinaryInputDevice.h"
34 
35 #ifdef CHECK_MEMORY_LEAKS
36 #include <foreign/nvwa/debug_new.h>
37 #endif // CHECK_MEMORY_LEAKS
38 
39 // ===========================================================================
40 // constants definitions
41 // ===========================================================================
42 #define BUF_MAX 1000
43 
44 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
48 BinaryInputDevice::BinaryInputDevice(const std::string& name)
49  : myStream(name.c_str(), std::fstream::in | std::fstream::binary) {}
50 
51 
53 
54 
55 bool
57  return myStream.good();
58 }
59 
60 
63  os.myStream.read((char*) &i, sizeof(int));
64  return os;
65 }
66 
67 
69 operator>>(BinaryInputDevice& os, unsigned int& i) {
70  os.myStream.read((char*) &i, sizeof(unsigned int));
71  return os;
72 }
73 
74 
77  os.myStream.read((char*) &f, sizeof(SUMOReal));
78  return os;
79 }
80 
81 
84  b = 0;
85  os.myStream.read((char*) &b, sizeof(char));
86  return os;
87 }
88 
89 
91 operator>>(BinaryInputDevice& os, std::string& s) {
92  unsigned int size;
93  os >> size;
94  if (size < BUF_MAX) {
95  os.myStream.read((char*) &os.myBuffer, sizeof(char)*size);
96  os.myBuffer[size] = 0;
97  s = std::string(os.myBuffer);
98  return os;
99  }
100  return os;
101 }
102 
103 
106  os.myStream.read((char*) &l, sizeof(long));
107  return os;
108 }
109 
110 
111 
112 /****************************************************************************/
113