1 #ifndef LIBGEODECOMP_IO_MEMORYWRITER_H
2 #define LIBGEODECOMP_IO_MEMORYWRITER_H
3 
4 #include <libgeodecomp/io/writer.h>
5 #include <libgeodecomp/misc/clonable.h>
6 #include <libgeodecomp/misc/stdcontaineroverloads.h>
7 #include <libgeodecomp/storage/grid.h>
8 
9 namespace LibGeoDecomp {
10 
11 /**
12  * The MemoryWriter is good for debugging a Simulator. As it name
13  * says, it will simply store all grids in memory for later inspection.
14  */
15 template<typename CELL_TYPE>
16 class MemoryWriter : public Clonable<Writer<CELL_TYPE>, MemoryWriter<CELL_TYPE> >
17 {
18 
19 public:
20     typedef typename Writer<CELL_TYPE>::GridType GridType;
21     typedef typename APITraits::SelectTopology<CELL_TYPE>::Value Topology;
22     typedef Grid<CELL_TYPE, Topology> StorageGrid;
23     using Writer<CELL_TYPE>::period;
24 
25     explicit MemoryWriter(unsigned period = 1) :
26         Clonable<Writer<CELL_TYPE>, MemoryWriter<CELL_TYPE> >("", period)
27     {}
28 
stepFinished(const GridType & grid,unsigned step,WriterEvent event)29     virtual void stepFinished(const GridType& grid, unsigned step, WriterEvent event)
30     {
31         if ((event == WRITER_STEP_FINISHED) && (step % period != 0)) {
32             return;
33         }
34 
35         grids.push_back(StorageGrid(grid));
36     }
37 
getGrid(int i)38     GridType& getGrid(int i)
39     {
40         return grids[i];
41     }
42 
getGrids()43     std::vector<StorageGrid>& getGrids()
44     {
45         return grids;
46     }
47 
48 private:
49     std::vector<StorageGrid> grids;
50 };
51 
52 }
53 
54 #endif
55