OpenCPN Partial API docs
Loading...
Searching...
No Matches
chartdata_input_stream.h
Go to the documentation of this file.
1/**************************************************************************
2 * Copyright (C) 2016 David S. Register *
3 * Copyright (C) 2016 Sean D'Epagnier *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see <https://www.gnu.org/licenses/>. *
17 **************************************************************************/
18
25#ifndef CHARTDATA_INPUT_STREAM_H_
26#define CHARTDATA_INPUT_STREAM_H_
27
28#include <wx/ffile.h>
29#include <wx/string.h>
30#include <wx/wfstream.h>
31
32#include "config.h"
33
34#ifdef OCPN_USE_LZMA
35#include <lzma.h>
36
40class wxCompressedFFileInputStream : public wxInputStream {
41public:
42 wxCompressedFFileInputStream(const wxString &fileName);
43 virtual ~wxCompressedFFileInputStream();
44
45 virtual bool IsOk() const {
46 return wxStreamBase::IsOk() && m_file->IsOpened();
47 }
48 bool IsSeekable() const { return false; }
49
50protected:
51 size_t OnSysRead(void *buffer, size_t size);
52 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
53 wxFileOffset OnSysTell() const;
54
55 wxFFile *m_file;
56 lzma_stream strm;
57
58private:
59 void init_lzma();
60
61 uint8_t inbuf[BUFSIZ];
62
63 wxDECLARE_NO_COPY_CLASS(wxCompressedFFileInputStream);
64};
65
66// non-seekable stream for either non-compressed or compressed files
67class ChartDataNonSeekableInputStream : public wxInputStream {
68public:
69 ChartDataNonSeekableInputStream(const wxString &fileName);
70 virtual ~ChartDataNonSeekableInputStream();
71
72 virtual bool IsOk() const { return m_stream->IsOk(); }
73 bool IsSeekable() const { return false; }
74
75protected:
76 size_t OnSysRead(void *buffer, size_t size);
77 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
78 wxFileOffset OnSysTell() const;
79
80private:
81 wxInputStream *m_stream;
82
83 wxDECLARE_NO_COPY_CLASS(ChartDataNonSeekableInputStream);
84};
85
86// seekable stream for either non-compressed or compressed files
87// it must decompress the file to a temporary file to make it seekable
88class ChartDataInputStream : public wxInputStream {
89public:
90 ChartDataInputStream(const wxString &fileName);
91 virtual ~ChartDataInputStream();
92
93 virtual bool IsOk() const { return m_stream->IsOk(); }
94 bool IsSeekable() const { return m_stream->IsSeekable(); }
95
96 wxString TempFileName() const { return m_tempfilename; }
97
98protected:
99 size_t OnSysRead(void *buffer, size_t size);
100 wxFileOffset OnSysSeek(wxFileOffset pos, wxSeekMode mode);
101 wxFileOffset OnSysTell() const;
102
103private:
104 wxString m_tempfilename;
105 wxInputStream *m_stream;
106
107 wxDECLARE_NO_COPY_CLASS(ChartDataInputStream);
108};
109
110#else
111
112typedef wxFFileInputStream ChartDataInputStream;
113typedef wxFFileInputStream ChartDataNonSeekableInputStream;
114
115#endif // OCPN_USE_LZMA
116
117bool DecompressXZFile(const wxString &input_path, const wxString &output_path);
118
119#endif // CHARTDATA_INPUT_STREAM_H_