Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SCBWriter.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright and trademark 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
44 #ifndef __SCB_WRITER_H__
45 #define __SCB_WRITER_H__
46 
47 #include <string>
48 #include <fstream>
49 #include "mengeCommon.h"
50 #include "FSM.h"
51 #include "BaseAgent.h"
52 
53 namespace Menge {
54 
55  namespace Agents {
56 
58 
62  class MENGE_API SCBException : public virtual Menge::MengeException {
63  public:
68 
74  SCBException( const std::string & s ): Menge::MengeException(s) {}
75  };
76 
80  class MENGE_API SCBFatalException : public SCBException, public Menge::MengeFatalException {
81  public:
86 
93  };
94 
96 
100  class MENGE_API SCBVersionException : public SCBFatalException {
101  public:
106 
112  SCBVersionException( const std::string & s ): SCBFatalException(s) {}
113  };
114 
116 
120  class MENGE_API SCBFileException : public SCBException {
121  public:
126 
132  SCBFileException( const std::string & s ): SCBException(s) {}
133  };
134 
135  // Forward declaration
136  class SCBFrameWriter;
137  class SimulatorInterface;
138 
140 
145  class SCBWriter {
146  public:
158  SCBWriter( const std::string & pathName, const std::string & version, SimulatorInterface * sim );
159 
163  ~SCBWriter();
164 
170  void writeFrame( BFSM::FSM * fsm );
171 
172  protected:
177 
182  int _version[2];
183 
188 
192  std::ofstream _file;
193 
202  bool validateVersion( const std::string & version );
203 
207  void writeHeader();
208 
212  void writeHeader1_0();
213 
217  void writeHeader2_0();
218  };
219 
221  // Implementation of SCBFrameWriters
223 
229  public:
233  static const int ZERO;
234 
242  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm ) = 0;
243  };
244 
245 
247 
257  public:
258  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm );
259  };
260 
262 
272  public:
273  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm );
274  };
275 
277 
289  public:
290  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm );
291  };
292 
294 
310  public:
311  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm );
312  };
313 
315 
328  public:
329  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm );
330  };
331 
333 
344  public:
345  virtual void writeFrame( std::ofstream & file, SimulatorInterface * sim, BFSM::FSM * fsm );
346  };
347 
348  } // namespace Agents
349 } // namespace Menge
350 #endif // __SCB_WRITER_H__
~SCBWriter()
Destructor.
Definition: SCBWriter.cpp:67
Base exception class for scb writers.
Definition: SCBWriter.h:62
Writer for version 2.1.
Definition: SCBWriter.h:288
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
int _version[2]
The version of the scb file to be written. Version is represented by the integer _verstion[0]._version[1].
Definition: SCBWriter.h:182
SCBVersionException()
Default constructor.
Definition: SCBWriter.h:105
std::ofstream _file
The file object for the scb stream to be written to.
Definition: SCBWriter.h:192
Exception raised for file I/O errors.
Definition: SCBWriter.h:120
The definition of the behavior finite state machine.
void writeHeader2_0()
Writes the header appropriate to major version 2 formats.
Definition: SCBWriter.cpp:132
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)
Function to write current frame's state to the file.
Definition: SCBWriter.cpp:241
SCBFatalException(const std::string &s)
Constructor with message.
Definition: SCBWriter.h:92
SCBVersionException(const std::string &s)
Constructor with message.
Definition: SCBWriter.h:112
SCBFileException()
Default constructor.
Definition: SCBWriter.h:125
Writer for version 1.0.
Definition: SCBWriter.h:256
SCBException(const std::string &s)
Constructor with message.
Definition: SCBWriter.h:74
The basic simulator interface required by the fsm.
Definition: SimulatorInterface.h:66
Writer for version 2.0.
Definition: SCBWriter.h:271
SCBException()
Default constructor.
Definition: SCBWriter.h:67
Base exception class for menge operations.
Definition: MengeException.h:58
SCBWriter(const std::string &pathName, const std::string &version, SimulatorInterface *sim)
Constructor for SCBWriter.
Definition: SCBWriter.cpp:51
Exception raised for invalid scb version.
Definition: SCBWriter.h:100
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)
Function to write current frame's state to the file.
Definition: SCBWriter.cpp:227
SimulatorInterface * _sim
A pointer to the simulator to write to the file.
Definition: SCBWriter.h:187
Writer for version 2.4.
Definition: SCBWriter.h:343
void writeHeader1_0()
Writes the header appropriate to major version 1 formats.
Definition: SCBWriter.cpp:125
Templated class for the behavior finite state machine.
Definition: FSM.h:126
Base class for fatal exceptions.
Definition: MengeException.h:99
Class responsible for writing the agent state of the simulator and fsm into a file.
Definition: SCBWriter.h:145
Contains the BaseAgent class - the underlying class which defines the basic functionality for all sha...
SCBFileException(const std::string &s)
Constructor with message.
Definition: SCBWriter.h:132
The fatal scb writers exception.
Definition: SCBWriter.h:80
Writer for version 2.3.
Definition: SCBWriter.h:327
This base class for writing a single frame of simulation data to the scb file.
Definition: SCBWriter.h:228
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)=0
Function to write current frame's state to the file.
void writeFrame(BFSM::FSM *fsm)
Writes the current frame of the stored simulator to the file.
Definition: SCBWriter.cpp:108
Writer for version 2.2.
Definition: SCBWriter.h:309
The namespace that contains the basic simulation mechanisms.
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)
Function to write current frame's state to the file.
Definition: SCBWriter.cpp:155
static const int ZERO
Simple static variable for writing binary zeros to the file.
Definition: SCBWriter.h:233
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)
Function to write current frame's state to the file.
Definition: SCBWriter.cpp:185
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)
Function to write current frame's state to the file.
Definition: SCBWriter.cpp:202
SCBFatalException()
Default constructor.
Definition: SCBWriter.h:85
bool validateVersion(const std::string &version)
Confirms that the given version is valid. Function has side-effects. This must be called for the SCBW...
Definition: SCBWriter.cpp:74
virtual void writeFrame(std::ofstream &file, SimulatorInterface *sim, BFSM::FSM *fsm)
Function to write current frame's state to the file.
Definition: SCBWriter.cpp:170
SCBFrameWriter * _frameWriter
The frame writer – defines the format of the frame's data.
Definition: SCBWriter.h:176
void writeHeader()
Writes the appropriate header to the open file.
Definition: SCBWriter.cpp:114