Rename openFromFileDescriptor() to open()
This commit is contained in:
parent
4449198711
commit
07a74d5fa8
|
@ -188,9 +188,8 @@ void NativeFileStream::open(const string &path, ios_base::openmode openMode)
|
|||
* \todo
|
||||
* - Maybe use setstate() instead of throwing exceptions directly for consistent error handling
|
||||
* with std::fstream::open(). However, that makes passing specific error messages difficult.
|
||||
* - Rename to open() in v5.
|
||||
*/
|
||||
void NativeFileStream::openFromFileDescriptor(int fileDescriptor, ios_base::openmode openMode)
|
||||
void NativeFileStream::open(int fileDescriptor, ios_base::openmode openMode)
|
||||
{
|
||||
setFileBuffer(makeFileBuffer(fileDescriptor, openMode));
|
||||
}
|
||||
|
@ -261,7 +260,7 @@ std::unique_ptr<std::basic_streambuf<char>> NativeFileStream::makeFileBuffer(con
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief Internally called by openFromFileDescriptor().
|
||||
* \brief Internally called by open().
|
||||
*/
|
||||
std::unique_ptr<std::basic_streambuf<char>> NativeFileStream::makeFileBuffer(int fileDescriptor, ios_base::openmode openMode)
|
||||
{
|
||||
|
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
bool is_open() const;
|
||||
void open(const std::string &path, std::ios_base::openmode openMode);
|
||||
void openFromFileDescriptor(int fileDescriptor, std::ios_base::openmode openMode);
|
||||
void open(int fileDescriptor, std::ios_base::openmode openMode);
|
||||
void close();
|
||||
|
||||
static std::unique_ptr<std::basic_streambuf<char>> makeFileBuffer(const std::string &path, ios_base::openmode openMode);
|
||||
|
@ -50,7 +50,7 @@ inline NativeFileStream::NativeFileStream(const std::string &path, ios_base::ope
|
|||
inline NativeFileStream::NativeFileStream(int fileDescriptor, ios_base::openmode openMode)
|
||||
: NativeFileStream()
|
||||
{
|
||||
openFromFileDescriptor(fileDescriptor, openMode);
|
||||
open(fileDescriptor, openMode);
|
||||
}
|
||||
|
||||
#else // CPP_UTILITIES_USE_NATIVE_FILE_BUFFER
|
||||
|
|
|
@ -516,7 +516,7 @@ void IoTests::testNativeFileStream()
|
|||
#ifndef PLATFORM_WINDOWS
|
||||
auto readWriteFileDescriptor = open(txtFilePath.data(), O_RDWR);
|
||||
CPPUNIT_ASSERT(readWriteFileDescriptor);
|
||||
fileStream.openFromFileDescriptor(readWriteFileDescriptor, ios_base::in | ios_base::out | ios_base::binary);
|
||||
fileStream.open(readWriteFileDescriptor, ios_base::in | ios_base::out | ios_base::binary);
|
||||
CPPUNIT_ASSERT(fileStream.is_open());
|
||||
CPPUNIT_ASSERT_EQUAL(static_cast<char>(fileStream.get()), 'f');
|
||||
fileStream.seekg(0, ios_base::end);
|
||||
|
@ -526,7 +526,7 @@ void IoTests::testNativeFileStream()
|
|||
CPPUNIT_ASSERT(!fileStream.is_open());
|
||||
#endif
|
||||
try {
|
||||
fileStream.openFromFileDescriptor(-1, ios_base::in | ios_base::out | ios_base::binary);
|
||||
fileStream.open(-1, ios_base::in | ios_base::out | ios_base::binary);
|
||||
fileStream.get();
|
||||
CPPUNIT_FAIL("expected exception");
|
||||
} catch (...) {
|
||||
|
@ -564,7 +564,7 @@ void IoTests::testNativeFileStream()
|
|||
const auto appendFileHandle = fopen(txtFilePath.data(), "a");
|
||||
#endif
|
||||
CPPUNIT_ASSERT(appendFileHandle);
|
||||
fileStream2.openFromFileDescriptor(fileno(appendFileHandle), ios_base::out | ios_base::app);
|
||||
fileStream2.open(fileno(appendFileHandle), ios_base::out | ios_base::app);
|
||||
CPPUNIT_ASSERT(fileStream2.is_open());
|
||||
fileStream2 << "foo";
|
||||
fileStream2.close();
|
||||
|
|
Loading…
Reference in New Issue