Changeset View
Standalone View
source/blender/blenlib/BLI_fileops.hh
- This file was added.
| /* | |||||
| * This program is free software; you can redistribute it and/or | |||||
| * modify it under the terms of the GNU General Public License | |||||
| * as published by the Free Software Foundation; either version 2 | |||||
| * of the License, or (at your option) any later version. | |||||
| * | |||||
| * This program 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. See the | |||||
| * GNU General Public License for more details. | |||||
| * | |||||
| * You should have received a copy of the GNU General Public License | |||||
| * along with this program; if not, write to the Free Software Foundation, | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||||
| * | |||||
| * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | |||||
JacquesLucke: Outdated license header. | |||||
| * All rights reserved. | |||||
| */ | |||||
| /** \file | |||||
| * \ingroup bli | |||||
| * \brief File and directory operations. | |||||
| */ | |||||
| #pragma once | |||||
| #ifndef __cplusplus | |||||
| # error This is a C++ header | |||||
| #endif | |||||
| #include "BLI_fileops.h" | |||||
| #include <fstream> | |||||
| #include <string> | |||||
| namespace blender { | |||||
| /** | |||||
| * std::fstream subclass that handles UTF-16 encoding on Windows. | |||||
| * | |||||
| * For documentation, see https://en.cppreference.com/w/cpp/io/basic_fstream | |||||
| */ | |||||
| class fstream : public std::fstream { | |||||
| public: | |||||
| fstream(); | |||||
| explicit fstream(const char *filename, | |||||
JacquesLuckeUnsubmitted Done Inline ActionsIs this filename or filepath, or are these synonym in this context? JacquesLucke: Is this `filename` or `filepath`, or are these synonym in this context? | |||||
sybrenAuthorUnsubmitted Done Inline ActionsSynonym, these declarations were copied verbatim from https://en.cppreference.com/w/cpp/io/basic_fstream sybren: Synonym, these declarations were copied verbatim from https://en.cppreference. | |||||
sybrenAuthorUnsubmitted Done Inline ActionsI like filepath more though, so I'll update the code for that. sybren: I like `filepath` more though, so I'll update the code for that. | |||||
| std::ios_base::openmode mode = ios_base::in | ios_base::out); | |||||
| explicit fstream(const std::string &filename, | |||||
| std::ios_base::openmode mode = ios_base::in | ios_base::out); | |||||
| fstream(const fstream &rhs) = delete; | |||||
JacquesLuckeUnsubmitted Done Inline ActionsWhy do you delete this explicitly? Looks like std::fstream deletes the copy constructor already. JacquesLucke: Why do you delete this explicitly? Looks like `std::fstream` deletes the copy constructor… | |||||
| void open(const char *filename, ios_base::openmode mode = ios_base::in | ios_base::out); | |||||
JacquesLuckeUnsubmitted Done Inline ActionsBoth open functions could be merged by using StringRef. JacquesLucke: Both `open` functions could be merged by using `StringRef`. | |||||
sybrenAuthorUnsubmitted Done Inline ActionsThat could be done, but would remove the symmetry with what's declared on https://en.cppreference.com/w/cpp/io/basic_fstream Is there a guarantee that the compiler will choose our StringRef override over the (then not overridden) const char * and const std::string & functions of std::fstream? sybren: That could be done, but would remove the symmetry with what's declared on https://en. | |||||
sybrenAuthorUnsubmitted Done Inline ActionsNever mind, C++ is being C++. I added an override keyword and the compiler puked at me. At least the VS2019 implementation of STL uses different arguments than documented at https://en.cppreference.com/w/cpp/io/basic_fstream/open, so I'll just embrace the "fluid standard" and have one StringRef implementation. sybren: Never mind, C++ is being C++. I added an `override` keyword and the compiler puked at me. At… | |||||
| void open(const std::string &filename, ios_base::openmode mode = ios_base::in | ios_base::out); | |||||
| }; | |||||
| } // namespace blender | |||||
Outdated license header.