Stimfit @PACKAGE_VERSION@
Loading...
Searching...
No Matches
streams.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------------
2// streams.h
3// Downloaded from http://www.intantech.com/files/CLAMP_source_code_v1_0.zip
4// as of 2017-03-13
5//
6// Copyright information added according to license directory in the original
7// source code package:
8//
9// Intan Technologies
10//
11// Copyright (c) 2016 Intan Technologies LLC
12//
13// This is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// This file is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22
23// You should have received a copy of the GNU General Public License
24// along with this file. If not, see <http://www.gnu.org/licenses/>.
25//----------------------------------------------------------------------------------
26
27#ifndef STREAMS_H
28#define STREAMS_H
29
30#include <memory>
31#include <string>
32#if __cplusplus > 199711L
33#include <cstdint>
34using std::unique_ptr;
35using std::move;
36#else
37#include <boost/cstdint.hpp>
38#include <boost/move/unique_ptr.hpp>
39using boost::movelib::unique_ptr;
40using boost::move;
41#define nullptr NULL
42#endif
43#include <iosfwd>
44#include <istream>
45
46#include "./intanlib.h"
47
48#if defined(_WIN32) && defined(_UNICODE)
49 typedef std::wstring FILENAME;
50#else
51 typedef std::string FILENAME;
52#endif
53
54// ------------------------------------------------------------------------
55class InStream {
56public:
57 virtual ~InStream() {}
58
59 virtual int read(char* data, int len) = 0;
60 virtual uint64_t bytesRemaining() = 0;
61 virtual std::istream::pos_type currentPos() = 0;
62};
63
64// ------------------------------------------------------------------------
65class FileInStream : public InStream {
66public:
69
70 virtual bool open(const FILENAME& filename); // Opens with new name
71 virtual int read(char* data, int len) override;
72 uint64_t bytesRemaining() override;
73 std::istream::pos_type currentPos() override;
74
75private:
76 unique_ptr<std::ifstream> filestream;
77 std::istream::pos_type filesize;
78
79 virtual void close();
80};
81
82// ------------------------------------------------------------------------
84public:
85#if __cplusplus > 199711L
86 BinaryReader(unique_ptr<FileInStream>&& other_);
87#else
88 BinaryReader(BOOST_RV_REF(unique_ptr<FileInStream>) other_);
89#endif
90 virtual ~BinaryReader();
91
92 uint64_t bytesRemaining() { return other->bytesRemaining(); }
93 std::istream::pos_type currentPos() { return other->currentPos(); }
94
95protected:
96 friend BinaryReader& operator>>(BinaryReader& istream, int32_t& value);
97 friend BinaryReader& operator>>(BinaryReader& istream, uint32_t& value);
98 friend BinaryReader& operator>>(BinaryReader& istream, int16_t& value);
99 friend BinaryReader& operator>>(BinaryReader& istream, uint16_t& value);
100 friend BinaryReader& operator>>(BinaryReader& istream, int8_t& value);
101 friend BinaryReader& operator>>(BinaryReader& istream, uint8_t& value);
102 friend BinaryReader& operator>>(BinaryReader& istream, float& value);
103 friend BinaryReader& operator>>(BinaryReader& istream, double& value);
104 friend BinaryReader& operator>>(BinaryReader& istream, std::wstring& value);
105
106private:
107 unique_ptr<FileInStream> other;
108};
109
110FILENAME toFileName(const std::string& s);
111FILENAME toFileName(const std::wstring& ws);
112
113#endif // STREAMS_H
uint64_t bytesRemaining()
Definition streams.h:92
friend BinaryReader & operator>>(BinaryReader &istream, double &value)
std::istream::pos_type currentPos()
Definition streams.h:93
friend BinaryReader & operator>>(BinaryReader &istream, float &value)
virtual ~BinaryReader()
friend BinaryReader & operator>>(BinaryReader &istream, int8_t &value)
friend BinaryReader & operator>>(BinaryReader &istream, uint32_t &value)
friend BinaryReader & operator>>(BinaryReader &istream, int16_t &value)
friend BinaryReader & operator>>(BinaryReader &istream, int32_t &value)
friend BinaryReader & operator>>(BinaryReader &istream, uint16_t &value)
BinaryReader(BOOST_RV_REF(unique_ptr< FileInStream >) other_)
friend BinaryReader & operator>>(BinaryReader &istream, std::wstring &value)
friend BinaryReader & operator>>(BinaryReader &istream, uint8_t &value)
virtual int read(char *data, int len) override
virtual bool open(const FILENAME &filename)
std::istream::pos_type currentPos() override
uint64_t bytesRemaining() override
virtual uint64_t bytesRemaining()=0
virtual ~InStream()
Definition streams.h:57
virtual int read(char *data, int len)=0
virtual std::istream::pos_type currentPos()=0
Reads Intan Technologies CLAMP data file generated by controller GUI.
FILENAME toFileName(const std::string &s)
std::string FILENAME
Definition streams.h:51