00001 #ifndef LIBGEODECOMP_IO_WRITER_H 00002 #define LIBGEODECOMP_IO_WRITER_H 00003 00004 #include <libgeodecomp/config.h> 00005 00006 #ifdef LIBGEODECOMP_WITH_MPI 00007 #include <mpi.h> 00008 #endif 00009 00010 #include <libgeodecomp/parallelization/monolithicsimulator.h> 00011 00012 #include <string> 00013 #include <stdexcept> 00014 00015 namespace LibGeoDecomp { 00016 00017 enum WriterEvent { 00018 WRITER_INITIALIZED, 00019 WRITER_STEP_FINISHED, 00020 WRITER_ALL_DONE 00021 }; 00022 00023 template <class CELL_TYPE> class MonolithicSimulator; 00024 00032 template<typename CELL_TYPE> 00033 class Writer 00034 { 00035 public: 00036 friend class Serialization; 00037 friend class WriterTest; 00038 00039 typedef typename MonolithicSimulator<CELL_TYPE>::GridType GridType; 00040 typedef typename APITraits::SelectTopology<CELL_TYPE>::Value Topology; 00041 const static int DIM = Topology::DIM; 00042 static const unsigned NANO_STEPS = APITraits::SelectNanoSteps<CELL_TYPE>::VALUE; 00043 00052 Writer( 00053 const std::string& prefix, 00054 const unsigned period) : 00055 prefix(prefix), 00056 period(period) 00057 { 00058 if (period == 0) { 00059 throw std::invalid_argument("period must be positive"); 00060 } 00061 } 00062 00063 virtual ~Writer() 00064 {} 00065 00076 virtual Writer *clone() const = 0; 00077 00084 virtual void stepFinished(const GridType& grid, unsigned step, WriterEvent event) = 0; 00085 00086 const unsigned& getPeriod() const 00087 { 00088 return period; 00089 } 00090 00091 const std::string& getPrefix() const 00092 { 00093 return prefix; 00094 } 00095 00096 protected: 00097 std::string prefix; 00098 unsigned period; 00099 }; 00100 00101 } 00102 00103 #endif