SerializedKernelObservationIO.cpp
Go to the documentation of this file.
1 // (C) Copyright Renaud Detry 2007-2015.
2 // Distributed under the GNU General Public License and under the
3 // BSD 3-Clause License (See accompanying file LICENSE.txt).
4 
5 /** @file */
6 
7 #include <fstream>
8 #include <cassert>
9 #include <algorithm>
10 #include <cmath>
11 #include <boost/tuple/tuple.hpp>
12 
15 #include <nuklei/Serial.h>
16 
17 namespace nuklei {
18 
19 
20 
21  KernelReader::KernelReader(const std::string &observationFileName) :
22  observationFileName_(observationFileName), idx_(-1)
23  {
24  NUKLEI_TRACE_BEGIN();
25  NUKLEI_TRACE_END();
26  }
27 
28  KernelReader::~KernelReader()
29  {
30  }
31 
32 
33  void KernelReader::init_()
34  {
35  NUKLEI_TRACE_BEGIN();
36  kc_.clear();
37  try {
38  Serial::readObject(kc_, observationFileName_);
39  } catch (SerialError& e) {
40  throw ObservationIOError(e.what());
41  }
42  idx_ = 0;
43  NUKLEI_TRACE_END();
44  }
45 
46  void KernelReader::reset()
47  {
48  NUKLEI_TRACE_BEGIN();
49  init();
50  NUKLEI_TRACE_END();
51  }
52 
53  NUKLEI_UNIQUE_PTR<Observation> KernelReader::readObservation_()
54  {
55  NUKLEI_TRACE_BEGIN();
56  if (idx_ < 0) NUKLEI_THROW("Reader does not seem inited.");
57  if (idx_ >= int(kc_.size())) return NUKLEI_UNIQUE_PTR<Observation>();
58  else return NUKLEI_UNIQUE_PTR<Observation>(new SerializedKernelObservation(kc_.at(idx_++)));
59  NUKLEI_TRACE_END();
60  }
61 
62  KernelWriter::KernelWriter(const std::string &observationFileName) :
63  observationFileName_(observationFileName)
64  {
65  NUKLEI_TRACE_BEGIN();
66  NUKLEI_TRACE_END();
67  }
68 
69  KernelWriter::~KernelWriter()
70  {
71  }
72 
73  void KernelWriter::init()
74  {
75  NUKLEI_TRACE_BEGIN();
76  kc_.clear();
77  NUKLEI_TRACE_END();
78  }
79 
80  void KernelWriter::reset()
81  {
82  NUKLEI_TRACE_BEGIN();
83  init();
84  NUKLEI_TRACE_END();
85  }
86 
87  void KernelWriter::writeBuffer()
88  {
89  NUKLEI_TRACE_BEGIN();
90  Serial::writeObject(kc_, observationFileName_);
91  NUKLEI_TRACE_END();
92  }
93 
94  void KernelWriter::writeObservation(const Observation &o)
95  {
96  NUKLEI_TRACE_BEGIN();
97  kc_.add(*o.getKernel());
98  NUKLEI_TRACE_END();
99  }
100 
101 }
Public namespace.
Definition: Color.cpp:9
#define NUKLEI_THROW(x)
Throws an Error.
Definition: Common.h:94
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:06.