YPC  0.2.0
block_data_source.h
1 #pragma once
2 #include "ypc/core/sealed_file.h"
3 #include "ypc/corecommon/data_source.h"
4 #include "ypc/corecommon/nt_cols.h"
5 #include <ff/net/middleware/ntpackage.h>
6 #include <glog/logging.h>
7 #include <hpda/extractor/extractor_base.h>
8 #include <hpda/extractor/raw_data.h>
9 
10 namespace ypc {
11 using data_source_output_t = ::ff::util::ntobject<nt<bytes>::data>;
12 
13 template <typename FT>
14 class block_data_source : public data_source<ypc::bytes> {
15 public:
17  block_data_source(FT *fh) : m_file(fh) { m_data_reach_end = false; }
18 
19  virtual ~block_data_source() {
20  if (m_ret.data()) {
21  m_ret.dealloc();
22  }
23  }
24 
25  virtual bool process() {
26  if (m_data_reach_end) {
27  return false;
28  }
29  if (m_ret.data()) {
30  m_ret.dealloc();
31  }
32  m_data_reach_end = !(m_file->next_item(m_ret));
33  return !m_data_reach_end;
34  }
35 
36  virtual data_source_output_t output_value() {
37  user_item_t ret;
38  ret.set<nt<bytes>::data>(ypc::bytes(m_ret.data(), m_ret.size()));
39  return ret;
40  }
41 
42 protected:
43  FT *m_file;
44  memref m_ret;
45  bool m_data_reach_end;
46 };
47 
48 } // namespace ypc
ypc::memref
Definition: memref.h:6
ypc::nt
Definition: nt_cols.h:6
ypc::block_data_source
Definition: block_data_source.h:14
ypc::data_source
Definition: data_source.h:8
ypc::utc::bytes< byte_t, ::ypc::utc::byte_encode::raw_bytes >