forked from kbinani/libvsq
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileOutputStream.hpp
More file actions
69 lines (58 loc) · 1.6 KB
/
FileOutputStream.hpp
File metadata and controls
69 lines (58 loc) · 1.6 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
/**
* FileOutputStream.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 __libvsq_FileOutputStream_hpp__
#define __libvsq_FileOutputStream_hpp__
#include "OutputStream.hpp"
#include <string>
#include <fstream>
VSQ_BEGIN_NAMESPACE
/**
* @brief ファイルへの出力を行う、OutputStream の実装
*/
class FileOutputStream : public OutputStream{
private:
/**
* @brief 出力先のストリーム
*/
std::ofstream stream;
public:
/**
* @brief 出力先のファイルパスを指定し、初期化する
*/
explicit FileOutputStream( const std::string &filePath ){
stream.open( filePath.c_str(), std::ios::binary );
if( !stream.is_open() ) throw OutputStream::IOException();
}
~FileOutputStream(){
if( stream.is_open() ) stream.close();
}
void write( const char *buffer, int64_t startIndex, int64_t length ){
stream.write( buffer + sizeof( char ) * startIndex, length );
}
void write( int value ){
char c = 0xFF & value;
stream.write( &c, 1 );
}
void seek( int64_t position ){
stream.seekp( position, std::ios::beg );
}
int64_t getPointer(){
return (int64_t)stream.tellp();
}
void close(){
stream.close();
}
};
VSQ_END_NAMESPACE
#endif