forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInputStream.hpp
More file actions
87 lines (76 loc) · 2.05 KB
/
FileInputStream.hpp
File metadata and controls
87 lines (76 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* FileInputStream.hpp
* Copyright © 2012 kbinani
*
* This file is part of libvsq.
*
* libvsq is free software; you can redistribute it and/or
* modify it under the terms of the BSD License.
*
* libvsq is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#ifndef __FileInputStream_hpp__
#define __FileInputStream_hpp__
#include "vsqglobal.hpp"
#include "InputStream.hpp"
#include <fstream>
#include <string>
VSQ_BEGIN_NAMESPACE
/**
* @brief ファイルからの読み込みストリーム
*/
class FileInputStream : public InputStream{
private:
std::ifstream stream;
public:
explicit FileInputStream( const std::string &filePath )
: stream( filePath.c_str(), std::ios::binary )
{
}
/**
* @brief 1 バイトを読み込む
* @return 読み込んだバイト値
*/
int read(){
int result = stream.get();
if( stream.eof() ){
return -1;
}else{
return result;
}
}
/**
* @brief バッファーに読み込む
* @param buffer 読み込んだデータを格納するバッファー
* @param startIndex 読み込んだデータを格納するオフセット
* @param length 読み込む長さ
*/
int read( char *buffer, int64_t startIndex, int64_t length ){
return stream.read( buffer + sizeof( char ) * startIndex, length ).gcount();
}
/**
* @brief ファイルポインターを移動する
* @param position ファイルポインター
*/
void seek( int64_t position ){
stream.clear();
stream.seekg( position );
}
/**
* @brief ファイルポインターを取得する
* @return ファイルポインター
*/
int64_t getPointer(){
return (int64_t)stream.tellg();
}
/**
* @brief ストリームを閉じる
*/
void close(){
stream.close();
}
};
VSQ_END_NAMESPACE
#endif // __FileInputStream_hpp__