namespace detail {
-std::ostream* openOStream(const std::string& filename)
+std::unique_ptr<std::ostream> openOStream(const std::string& filename)
{
errno = 0;
- std::ostream* res;
- res = new std::ofstream(filename);
- if (res == nullptr || !*res)
+ std::unique_ptr<std::ostream> res = std::make_unique<std::ofstream>(filename);
+ if (!res || !*res)
{
std::stringstream ss;
ss << "Cannot open file: `" << filename << "': " << cvc5_errno_failreason();
}
return res;
}
-std::istream* openIStream(const std::string& filename)
+std::unique_ptr<std::istream> openIStream(const std::string& filename)
{
errno = 0;
- std::istream* res;
- res = new std::ifstream(filename);
- if (res == nullptr || !*res)
+ std::unique_ptr<std::istream> res = std::make_unique<std::ifstream>(filename);
+ if (!res || !*res)
{
std::stringstream ss;
ss << "Cannot open file: `" << filename << "': " << cvc5_errno_failreason();
* Open a file as an output stream and return it as a pointer. The caller
* assumes the ownership of the returned pointer.
*/
-std::ostream* openOStream(const std::string& filename);
+std::unique_ptr<std::ostream> openOStream(const std::string& filename);
/*
* Open a file as an input stream and return it as a pointer. The caller
* assumes the ownership of the returned pointer.
*/
-std::istream* openIStream(const std::string& filename);
+std::unique_ptr<std::istream> openIStream(const std::string& filename);
} // namespace detail
/**
if constexpr (std::is_same<Stream, std::ostream>::value)
{
d_nonowned = nullptr;
- d_owned.reset(detail::openOStream(value));
+ d_owned = detail::openOStream(value);
d_description = value;
}
else if constexpr (std::is_same<Stream, std::istream>::value)
{
d_nonowned = nullptr;
- d_owned.reset(detail::openIStream(value));
+ d_owned = detail::openIStream(value);
d_description = value;
}
}