28 #ifndef YSL_INC_Core_yfile_h_
29 #define YSL_INC_Core_yfile_h_ 1
31 #include "../Core/ycutil.h"
33 #include "../Adaptor/YTextBase.h"
66 File(
const String&, std::ios_base::openmode);
93 DefGetter(const ynothrow, ptrdiff_t, Position, std::ftell(fp))
100 PDefH(
int, Seek, ptrdiff_t offset,
int whence) const
101 ImplRet(std::fseek(fp, offset, whence))
149 Open(const_path_t, std::ios_base::openmode);
151 Open(const String&, const
ucs2_t* = u"rb");
153 Open(const String&, std::ios_base::openmode);
163 PDefH(
size_t, Read,
void* ptr,
size_t size = 1U,
size_t nmemb = 1U) const
164 ImplRet(std::fread(ptr, size, nmemb, fp))
179 Truncate(
size_t) const;
188 PDefH(
size_t, Write,
void* ptr,
size_t size = 1U,
size_t nmemb = 1U) const
189 ImplRet(std::fwrite(ptr, size, nmemb, fp))
198 template<typename _tChar>
200 operator>>(
File& f, typename std::char_traits<_tChar>::char_type& c)
202 YAssert(
bool(f),
"Invalid file found.");
204 const auto fp(f.GetPtr());
215 template<
typename _tString>
219 YAssert(
bool(f),
"Invalid file found.");
221 const auto fp(f.
GetPtr());
224 while((c = std::fgetc(fp)) > 0 && !std::iswspace(c))
239 YAssert(
bool(f),
"Invalid file found.");
241 std::fputc(c, f.
GetPtr());
253 YAssert(
bool(f),
"Invalid file found.");
255 std::fputs(str, f.
GetPtr());
265 template<
typename _tString>
269 YAssert(
bool(f),
"Invalid file found.");
271 std::fputs(reinterpret_cast<const char*>(str.c_str()), f.
GetPtr());