From 6e4e12826fd144c874c93c2efb669fbb119b831a Mon Sep 17 00:00:00 2001 From: Andreas Sturmlechner Date: Tue, 30 Jan 2024 23:56:14 +0100 Subject: [PATCH] Import boost_string_file.hpp from boost-1.83 and put it to use immediately string_file.hpp was deprecated in boost-1.79.0 and removed in 1.84.0 Signed-off-by: Andreas Sturmlechner --- common/boost_string_file.hpp | 59 ++++++++++++++++++++++++++++++++++ lang/LangSource/PyrLexer.cpp | 2 +- server/scsynth/SC_GraphDef.cpp | 2 +- 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 common/boost_string_file.hpp diff --git a/common/boost_string_file.hpp b/common/boost_string_file.hpp new file mode 100644 index 000000000..1ccb63de6 --- /dev/null +++ b/common/boost_string_file.hpp @@ -0,0 +1,59 @@ +// filesystem/string_file.hpp --------------------------------------------------------// + +// Copyright Beman Dawes 2015 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Library home page: http://www.boost.org/libs/filesystem + +#ifndef BOOST_FILESYSTEM_STRING_FILE_HPP +#define BOOST_FILESYSTEM_STRING_FILE_HPP + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include // must be the last #include + +namespace boost { +namespace filesystem { + +inline void save_string_file(path const& p, std::string const& str) +{ + filesystem::ofstream file; + file.exceptions(std::ios_base::failbit | std::ios_base::badbit); + file.open(p, std::ios_base::binary); + const std::size_t sz = str.size(); + if (BOOST_UNLIKELY(sz > static_cast< boost::uintmax_t >((std::numeric_limits< std::streamsize >::max)()))) + BOOST_FILESYSTEM_THROW(std::length_error("String size exceeds max write size")); + file.write(str.c_str(), static_cast< std::streamsize >(sz)); +} + +inline void load_string_file(path const& p, std::string& str) +{ + filesystem::ifstream file; + file.exceptions(std::ios_base::failbit | std::ios_base::badbit); + file.open(p, std::ios_base::binary); + const boost::uintmax_t sz = filesystem::file_size(p); + if (BOOST_UNLIKELY(sz > static_cast< boost::uintmax_t >((std::numeric_limits< std::streamsize >::max)()))) + BOOST_FILESYSTEM_THROW(std::length_error("File size exceeds max read size")); + str.resize(static_cast< std::size_t >(sz), '\0'); + if (sz > 0u) + file.read(&str[0], static_cast< std::streamsize >(sz)); +} + +} // namespace filesystem +} // namespace boost + +#include + +#endif // BOOST_FILESYSTEM_STRING_FILE_HPP diff --git a/lang/LangSource/PyrLexer.cpp b/lang/LangSource/PyrLexer.cpp index 7ebe3d726..06c1454ca 100644 --- a/lang/LangSource/PyrLexer.cpp +++ b/lang/LangSource/PyrLexer.cpp @@ -38,7 +38,7 @@ #include #include -#include +#include "boost_string_file.hpp" #include "PyrParseNode.h" #include "Bison/lang11d_tab.h" diff --git a/server/scsynth/SC_GraphDef.cpp b/server/scsynth/SC_GraphDef.cpp index 957aca193..5f8f15741 100644 --- a/server/scsynth/SC_GraphDef.cpp +++ b/server/scsynth/SC_GraphDef.cpp @@ -46,7 +46,7 @@ #include #include // recursive_directory_iterator -#include // load_string_file +#include "boost_string_file.hpp" // load_string_file namespace bfs = boost::filesystem; -- 2.43.0