SHORE API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
stream_slicer.hpp
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2008,2009,2010,2011,2012 Stephan Ossowski, Korbinian Schneeberger,
4  * Felix Ott, Joerg Hagmann, Alf Scotland, Sebastian Bender
5  *
6  * This file is part of SHORE.
7  *
8  * SHORE is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * SHORE is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with SHORE. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
25 
26 #ifndef SHORE_STREAM_STREAM_SLICER_HPP__
27 #define SHORE_STREAM_STREAM_SLICER_HPP__
28 
29 #include <string>
30 
31 #include "shore/base/memops.hpp"
32 #include "shore/stream/streams.hpp"
33 
34 namespace shore {
35 
38 {
39  public:
40 
41  struct slice
42  {
44  const char *data;
46  size_t size;
48  uint64_t offset;
49 
52  bool eof;
53  };
54 
55  private:
56 
57  slice m_slice;
58 
59  shore::istreams m_is;
60  shore::mmapping m_mmapping;
61 
62  size_t m_blocksize;
63 
64  char *m_readbuf;
65 
66  bool m_mmapok;
67 
68 
69  bool try_mmap(const std::string &fn);
70 
71 
72  stream_slicer(const stream_slicer &other);
73  stream_slicer &operator=(const stream_slicer &other);
74 
75  public:
76 
77  stream_slicer(const std::string &fn,const size_t bs,
78  const uint64_t startoff=0);
79 
80  stream_slicer(std::istream &is,const size_t bs,
81  const uint64_t startoff=0);
82 
83  ~stream_slicer();
84 
85  const slice &current() const;
86 
87  bool has_data() const;
88 
90  void move(const uint64_t n);
91 };
92 
93 } // namespace
94 
95 #endif // SHORE_STREAM_STREAM_SLICER_HPP__
96