1//
2// FileStream.cpp
3//
4// Library: Foundation
5// Package: Streams
6// Module: FileStream
7//
8// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
9// and Contributors.
10//
11// SPDX-License-Identifier: BSL-1.0
12//
13
14
15#include "Poco/FileStream.h"
16#include "Poco/Exception.h"
17#if defined(POCO_OS_FAMILY_WINDOWS)
18#include "FileStream_WIN32.cpp"
19#else
20#include "FileStream_POSIX.cpp"
21#endif
22
23
24namespace Poco {
25
26
27FileIOS::FileIOS(std::ios::openmode defaultMode):
28 _defaultMode(defaultMode)
29{
30 poco_ios_init(&_buf);
31}
32
33
34FileIOS::~FileIOS()
35{
36}
37
38
39void FileIOS::open(const std::string& path, std::ios::openmode mode)
40{
41 clear();
42 _buf.open(path, mode | _defaultMode);
43}
44
45
46void FileIOS::close()
47{
48 if (!_buf.close())
49 {
50 setstate(ios_base::badbit);
51 }
52}
53
54
55FileStreamBuf* FileIOS::rdbuf()
56{
57 return &_buf;
58}
59
60
61FileInputStream::FileInputStream():
62 FileIOS(std::ios::in),
63 std::istream(&_buf)
64{
65}
66
67
68FileInputStream::FileInputStream(const std::string& path, std::ios::openmode mode):
69 FileIOS(std::ios::in),
70 std::istream(&_buf)
71{
72 open(path, mode);
73}
74
75
76FileInputStream::~FileInputStream()
77{
78}
79
80
81FileOutputStream::FileOutputStream():
82 FileIOS(std::ios::out),
83 std::ostream(&_buf)
84{
85}
86
87
88FileOutputStream::FileOutputStream(const std::string& path, std::ios::openmode mode):
89 FileIOS(std::ios::out),
90 std::ostream(&_buf)
91{
92 open(path, mode);
93}
94
95
96FileOutputStream::~FileOutputStream()
97{
98}
99
100
101FileStream::FileStream():
102 FileIOS(std::ios::in | std::ios::out),
103 std::iostream(&_buf)
104{
105}
106
107
108FileStream::FileStream(const std::string& path, std::ios::openmode mode):
109 FileIOS(std::ios::in | std::ios::out),
110 std::iostream(&_buf)
111{
112 open(path, mode);
113}
114
115
116FileStream::~FileStream()
117{
118}
119
120
121} // namespace Poco
122