JASSv2
instream.h
Go to the documentation of this file.
1 /*
2  INSTREAM.H
3  ----------
4  Copyright (c) 2016 Andrew Trotman
5  Released under the 2-clause BSD license (See:https://en.wikipedia.org/wiki/BSD_licenses)
6 */
14 #pragma once
15 
16 #include <vector>
17 #include <memory>
18 
19 #include "document.h"
20 #include "allocator_memory.h"
21 
22 namespace JASS
23  {
24  /*
25  CLASS INSTREAM()
26  ----------------
27  */
45  class instream
46  {
47  protected:
48  std::shared_ptr<instream> source;
49  std::shared_ptr<allocator> memory;
50 
51  public:
52  /*
53  INSTREAM::INSTREAM()
54  --------------------
55  */
62  instream(std::shared_ptr<instream> &source, std::shared_ptr<allocator> &memory) :
63  source(source), // store the instream
64  memory(memory) // store the memory pointer
65  {
66  /* Nothing */
67  }
68 
73  instream(std::shared_ptr<instream> &source) :
74  source(source) // store the instream
75  {
76  /* Nothing */
77  }
78 
79  /*
80  INSTREAM::INSTREAM()
81  --------------------
82  */
86  instream(void)
87  {
88  /* Nothing */
89  }
90 
91  /*
92  INSTREAM::~INSTREAM()
93  ---------------------
94  */
100  virtual ~instream()
101  {
102  /* Nothing */
103  }
104 
105  /*
106  INSTREAM::READ()
107  ----------------
108  */
113  virtual void read(document &buffer) = 0;
114 
115  /*
116  INSTREAM::FETCH()
117  -----------------
118  */
125  size_t fetch(void *buffer, size_t bytes)
126  {
127  allocator_memory provider(buffer, bytes);
128  document into(provider);
129 
130  into.contents = slice(buffer, bytes);
131  read(into);
132  return into.contents.size();
133  }
134  } ;
135  }
136 
virtual void read(document &buffer)=0
Read at most buffer.contents.size() bytes of data into buffer, resizing on eof.
std::shared_ptr< instream > source
If this object is reading from another instream then this is that instream.
Definition: instream.h:48
Read data from an input stream.
Definition: instream.h:45
C++ slices (string-descriptors)
Definition: slice.h:27
Container class representing a document through the indexing pipeline.
Definition: document.h:31
std::shared_ptr< allocator > memory
Any and all memory allocation must happen using this object.
Definition: instream.h:49
instream(std::shared_ptr< instream > &source, std::shared_ptr< allocator > &memory)
Constructor.
Definition: instream.h:62
slice contents
The contents of the document (or likewise).
Definition: document.h:43
virtual ~instream()
Destructor.
Definition: instream.h:100
A document withing the indexing pipeline.
instream(std::shared_ptr< instream > &source)
Constructor.
Definition: instream.h:73
instream(void)
Constructor.
Definition: instream.h:86
Simple block-allocator that internally uses a single non-growable fixed-sized buffer.
Definition: compress_integer_elias_delta_simd.c:23
size_t size(void) const
Return the length of this slice.
Definition: slice.h:256
Memory allocator out of a single non-growable fixed-sized buffer.
Definition: allocator_memory.h:25
size_t fetch(void *buffer, size_t bytes)
fetch() generates a document object, sets its contents to the passed buffer, calls read() and returns...
Definition: instream.h:125