diff options
author | Oz Linden <oz@lindenlab.com> | 2015-04-07 17:28:05 -0400 |
---|---|---|
committer | Oz Linden <oz@lindenlab.com> | 2015-04-07 17:28:05 -0400 |
commit | 3a57b18896eacb6fea6680d0eccaaeddb0b700b0 (patch) | |
tree | 70ca4bccbb2fe28ab5232d920a94fd0246f1b8ad /indra/llcommon | |
parent | 66bc5107863e8226e91818cd9d3c075d0514dbe5 (diff) |
convert llifstream and llofstream to std::ifstream and std::ofstream respectively
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-x | indra/llcommon/llerror.cpp | 4 | ||||
-rwxr-xr-x | indra/llcommon/llfile.cpp | 85 | ||||
-rwxr-xr-x | indra/llcommon/llfile.h | 99 | ||||
-rwxr-xr-x | indra/llcommon/llliveappconfig.cpp | 2 | ||||
-rwxr-xr-x | indra/llcommon/llstring.cpp | 2 |
5 files changed, 37 insertions, 155 deletions
diff --git a/indra/llcommon/llerror.cpp b/indra/llcommon/llerror.cpp index 8119b14887..2100989316 100755 --- a/indra/llcommon/llerror.cpp +++ b/indra/llcommon/llerror.cpp @@ -113,7 +113,7 @@ namespace { public: RecordToFile(const std::string& filename) { - mFile.open(filename, llofstream::out | llofstream::app); + mFile.open(filename.c_str(), std::ios_base::out | std::ios_base::app); if (!mFile) { LL_INFOS() << "Error setting log file to " << filename << LL_ENDL; @@ -335,7 +335,7 @@ namespace LLSD configuration; { - llifstream file(filename()); + llifstream file(filename().c_str()); if (file.is_open()) { LLSDSerialize::fromXML(configuration, file); diff --git a/indra/llcommon/llfile.cpp b/indra/llcommon/llfile.cpp index 304d702979..77a9657306 100755 --- a/indra/llcommon/llfile.cpp +++ b/indra/llcommon/llfile.cpp @@ -865,6 +865,7 @@ int llstdio_filebuf::sync() } #endif +#if 0 // @TBDeleted /************** input file stream ********************************/ @@ -919,32 +920,6 @@ llifstream::llifstream(const char* _Filename, #endif -#if llstream_LLFILE -// explicit -llifstream::llifstream(_Filet *_File, - ios_base::openmode _Mode, size_t _Size) : - _M_filebuf(_File, _Mode, _Size), -#if LL_WINDOWS - std::istream(&_M_filebuf) {} -#else - std::istream() -{ - this->init(&_M_filebuf); -} -#endif - -#if !LL_WINDOWS -// explicit -llifstream::llifstream(int __fd, - ios_base::openmode _Mode, size_t _Size) : - _M_filebuf(__fd, _Mode, _Size), - std::istream() -{ - this->init(&_M_filebuf); -} -#endif -#endif // llstream_LLFILE - bool llifstream::is_open() const { // test if C stream has been opened return _M_filebuf.is_open(); @@ -993,9 +968,9 @@ void llifstream::close() llofstream::llofstream() : _M_filebuf(), #if LL_WINDOWS - std::ostream(&_M_filebuf) {} + std::ofstream(&_M_filebuf) {} #else - std::ostream() + std::ofstream() { this->init(&_M_filebuf); } @@ -1005,7 +980,7 @@ llofstream::llofstream() : _M_filebuf(), llofstream::llofstream(const std::string& _Filename, ios_base::openmode _Mode) : _M_filebuf(), #if LL_WINDOWS - std::ostream(&_M_filebuf) + std::ofstream(&_M_filebuf) { llutf16string wideName = utf8str_to_utf16str( _Filename ); if (_M_filebuf.open( wideName.c_str(), _Mode | ios_base::out) == 0) @@ -1014,7 +989,7 @@ llofstream::llofstream(const std::string& _Filename, } } #else - std::ostream() + std::ofstream() { this->init(&_M_filebuf); this->open(_Filename.c_str(), _Mode | ios_base::out); @@ -1025,7 +1000,7 @@ llofstream::llofstream(const std::string& _Filename, llofstream::llofstream(const char* _Filename, ios_base::openmode _Mode) : _M_filebuf(), #if LL_WINDOWS - std::ostream(&_M_filebuf) + std::ofstream(&_M_filebuf) { llutf16string wideName = utf8str_to_utf16str( _Filename ); if (_M_filebuf.open( wideName.c_str(), _Mode | ios_base::out) == 0) @@ -1034,39 +1009,13 @@ llofstream::llofstream(const char* _Filename, } } #else - std::ostream() + std::ofstream() { this->init(&_M_filebuf); this->open(_Filename, _Mode | ios_base::out); } #endif -#if llstream_LLFILE -// explicit -llofstream::llofstream(_Filet *_File, - ios_base::openmode _Mode, size_t _Size) : - _M_filebuf(_File, _Mode, _Size), -#if LL_WINDOWS - std::ostream(&_M_filebuf) {} -#else - std::ostream() -{ - this->init(&_M_filebuf); -} -#endif - -#if !LL_WINDOWS -// explicit -llofstream::llofstream(int __fd, - ios_base::openmode _Mode, size_t _Size) : - _M_filebuf(__fd, _Mode, _Size), - std::ostream() -{ - this->init(&_M_filebuf); -} -#endif -#endif // llstream_LLFILE - bool llofstream::is_open() const { // test if C stream has been opened return _M_filebuf.is_open(); @@ -1108,6 +1057,25 @@ void llofstream::close() } } +void llofstream::~llofstream() +{ + try: + { + if ( is_open() ) + { + flush(); + } + } + catch (std::exception& e) + { + LL_WARNS() << "llofstream std::exception: " << e.what() << LL_ENDL; + } + catch (...) + { + LL_WARNS() << "llofstream non-std exception" << LL_ENDL; + } +} + /************** helper functions ********************************/ std::streamsize llifstream_size(llifstream& ifstr) @@ -1135,3 +1103,4 @@ std::streamsize llofstream_size(llofstream& ofstr) } +#endif // @TBDeleted diff --git a/indra/llcommon/llfile.h b/indra/llcommon/llfile.h index 44a1e42fa5..bd750b8c3c 100755 --- a/indra/llcommon/llfile.h +++ b/indra/llcommon/llfile.h @@ -86,12 +86,6 @@ public: static const char * tmpdir(); }; -// Remove ll[io]fstream support for [LL]FILE*, preparing to remove dependency -// on GNU's standard library. -#if ! defined(llstream_LLFILE) -#define llstream_LLFILE 0 -#endif - /** * @brief Provides a layer of compatibility for C/POSIX. * @@ -198,7 +192,9 @@ protected: #endif }; - +typedef std::ifstream llifstream; +typedef std::ofstream llofstream; +#if 0 /* @TBDeleted */ /** * @brief Controlling input for files. * @@ -234,34 +230,6 @@ public: explicit llifstream(const char* _Filename, ios_base::openmode _Mode = ios_base::in); -#if llstream_LLFILE - /** - * @brief Create a stream using an open c file stream. - * @param File An open @c FILE*. - @param Mode Same meaning as in a standard filebuf. - @param Size Optimal or preferred size of internal buffer, in chars. - Defaults to system's @c BUFSIZ. - */ - explicit llifstream(_Filet *_File, - ios_base::openmode _Mode = ios_base::in, - //size_t _Size = static_cast<size_t>(BUFSIZ)); - size_t _Size = static_cast<size_t>(1)); - - /** - * @brief Create a stream using an open file descriptor. - * @param fd An open file descriptor. - @param Mode Same meaning as in a standard filebuf. - @param Size Optimal or preferred size of internal buffer, in chars. - Defaults to system's @c BUFSIZ. - */ -#if !LL_WINDOWS - explicit llifstream(int __fd, - ios_base::openmode _Mode = ios_base::in, - //size_t _Size = static_cast<size_t>(BUFSIZ)); - size_t _Size = static_cast<size_t>(1)); -#endif -#endif // llstream_LLFILE - /** * @brief The destructor does nothing. * @@ -271,17 +239,6 @@ public: virtual ~llifstream() {} // Members: -#if llstream_LLFILE - /** - * @brief Accessing the underlying buffer. - * @return The current basic_filebuf buffer. - * - * This hides both signatures of std::basic_ios::rdbuf(). - */ - llstdio_filebuf* rdbuf() const - { return const_cast<llstdio_filebuf*>(&_M_filebuf); } -#endif // llstream_LLFILE - /** * @brief Wrapper to test for an open file. * @return @c rdbuf()->is_open() @@ -324,7 +281,7 @@ private: * which allows construction using a pre-exisintg file stream buffer. * We refer to this std::basic_filebuf (or derivative) as @c sb. */ -class LL_COMMON_API llofstream : public std::ostream +class LL_COMMON_API llofstream : public std::ofstream { public: // Constructors: @@ -350,60 +307,15 @@ public: explicit llofstream(const char* _Filename, ios_base::openmode _Mode = ios_base::out|ios_base::trunc); -#if llstream_LLFILE - /** - * @brief Create a stream using an open c file stream. - * @param File An open @c FILE*. - @param Mode Same meaning as in a standard filebuf. - @param Size Optimal or preferred size of internal buffer, in chars. - Defaults to system's @c BUFSIZ. - */ - explicit llofstream(_Filet *_File, - ios_base::openmode _Mode = ios_base::out, - //size_t _Size = static_cast<size_t>(BUFSIZ)); - size_t _Size = static_cast<size_t>(1)); - - /** - * @brief Create a stream using an open file descriptor. - * @param fd An open file descriptor. - @param Mode Same meaning as in a standard filebuf. - @param Size Optimal or preferred size of internal buffer, in chars. - Defaults to system's @c BUFSIZ. - */ -#if !LL_WINDOWS - explicit llofstream(int __fd, - ios_base::openmode _Mode = ios_base::out, - //size_t _Size = static_cast<size_t>(BUFSIZ)); - size_t _Size = static_cast<size_t>(1)); -#endif -#endif // llstream_LLFILE - /** * @brief The destructor does nothing. * * The file is closed by the filebuf object, not the formatting * stream. */ - virtual ~llofstream() {} + virtual ~llofstream(); // Members: -#if llstream_LLFILE - /** - * @brief Accessing the underlying buffer. - * @return The current basic_filebuf buffer. - * - * This hides both signatures of std::basic_ios::rdbuf(). - */ - llstdio_filebuf* rdbuf() const - { return const_cast<llstdio_filebuf*>(&_M_filebuf); } -#endif // llstream_LLFILE - - /** - * @brief Wrapper to test for an open file. - * @return @c rdbuf()->is_open() - */ - bool is_open() const; - /** * @brief Opens an external file. * @param Filename The name of the file. @@ -440,5 +352,6 @@ private: */ std::streamsize LL_COMMON_API llifstream_size(llifstream& fstr); std::streamsize LL_COMMON_API llofstream_size(llofstream& fstr); +#endif /* @TBDeleted */ #endif // not LL_LLFILE_H diff --git a/indra/llcommon/llliveappconfig.cpp b/indra/llcommon/llliveappconfig.cpp index 7c87c5a1a0..a9b1cdf4f6 100755 --- a/indra/llcommon/llliveappconfig.cpp +++ b/indra/llcommon/llliveappconfig.cpp @@ -49,7 +49,7 @@ bool LLLiveAppConfig::loadFile() { LL_INFOS() << "LLLiveAppConfig::loadFile(): reading from " << filename() << LL_ENDL; - llifstream file(filename()); + llifstream file(filename().c_str()); LLSD config; if (file.is_open()) { diff --git a/indra/llcommon/llstring.cpp b/indra/llcommon/llstring.cpp index 617969ab2a..f3b8999883 100755 --- a/indra/llcommon/llstring.cpp +++ b/indra/llcommon/llstring.cpp @@ -107,7 +107,7 @@ bool iswindividual(llwchar elem) bool _read_file_into_string(std::string& str, const std::string& filename) { - llifstream ifs(filename, llifstream::binary); + llifstream ifs(filename.c_str(), llifstream::binary); if (!ifs.is_open()) { LL_INFOS() << "Unable to open file " << filename << LL_ENDL; |