PetaVision  Alpha
CheckpointEntryData.hpp
1 /*
2  * CheckpointEntryData.hpp
3  *
4  * Created on Sep 27, 2016
5  * Author: Pete Schultz
6  */
7 
8 #ifndef CHECKPOINTENTRYDATA_HPP_
9 #define CHECKPOINTENTRYDATA_HPP_
10 
11 #include "CheckpointEntry.hpp"
12 #include "io/PrintStream.hpp"
13 #include <string>
14 
15 namespace PV {
16 
17 template <typename T>
19  public:
21  std::string const &name,
22  MPIBlock const *mpiBlock,
23  T *dataPtr,
24  size_t numValues,
25  bool broadcastingFlag)
26  : CheckpointEntry(name, mpiBlock),
27  mDataPointer(dataPtr),
28  mNumValues(numValues),
29  mBroadcastingFlag(broadcastingFlag) {}
31  std::string const &objName,
32  std::string const &dataName,
33  MPIBlock const *mpiBlock,
34  T *dataPtr,
35  size_t numValues,
36  bool broadcastingFlag)
37  : CheckpointEntry(objName, dataName, mpiBlock),
38  mDataPointer(dataPtr),
39  mNumValues(numValues),
40  mBroadcastingFlag(broadcastingFlag) {}
41  virtual void write(std::string const &checkpointDirectory, double simTime, bool verifyWritesFlag)
42  const override;
43  virtual void read(std::string const &checkpointDirectory, double *simTimePtr) const override;
44  virtual void remove(std::string const &checkpointDirectory) const override;
45 
46  private:
47  void broadcast();
48 
49  private:
50  T *mDataPointer;
51  size_t mNumValues;
52  bool mBroadcastingFlag;
53 };
54 
55 namespace TextOutput {
56 
57 template <typename T>
58 void print(T const *dataPointer, size_t numValues, PrintStream &stream) {
59  for (size_t n = 0; n < numValues; n++) {
60  stream << dataPointer[n] << "\n";
61  }
62 } // end print()
63 
64 } // end namespace TextOutput
65 
66 } // end namespace PV
67 
68 #include "CheckpointEntryData.tpp"
69 
70 #endif // CHECKPOINTENTRYDATA_HPP_