33 #include <sys/types.h>
37 #include <type_traits>
43 #define O_BINARY _O_BINARY
52 inline int open(
const char *pathname,
int flags) {
53 return _open(pathname, flags);
55 inline int open(
const char *pathname,
int flags, mode_t mode) {
56 return _open(pathname, flags, mode);
71 template<
class T>
inline bool FileGetWrapper(FileRead& fr, T& data);
77 template<
class T>
inline void FilePutWrapper(FileWrite& fw,
const T& data);
86 enum WriteMode { TRUNCATE=0, KEEP, APPEND, NEWONLY };
106 last_was_read (
false),
107 last_was_write (
false) {
123 inline void Close() {
126 loc_fp = fp.exchange(NULL);
131 if (do_close && (loc_fp != NULL)) {
136 inline bool IsWriteBuf()
const {
137 return index > amnt_read;
140 inline bool IsReadBuf()
const {
141 return amnt_read > index;
145 std::atomic<FILE*> fp;
146 std::atomic<u64> cnt;
165 enum BaseMode { R_ONLY=0, W_TRUNC, W_KEEP, W_APP, W_NEW,
166 RW_TRUNC, RW_KEEP, RW_APP, RW_NEW };
168 inline bool BaseOpen(
const RStr& filename,
const BaseMode mode) {
171 helper =
new FileHelper();
173 helper->filename = filename;
176 int flags = O_BINARY;
179 case R_ONLY: mode_str =
"rb";
182 case W_TRUNC: mode_str =
"wb";
183 flags |= O_WRONLY | O_CREAT | O_TRUNC;
185 case W_KEEP: mode_str =
"wb";
186 flags |= O_WRONLY | O_CREAT;
188 case W_APP: mode_str =
"ab";
189 flags |= O_WRONLY | O_CREAT | O_APPEND;
191 case W_NEW: mode_str =
"wb";
192 flags |= O_WRONLY | O_CREAT | O_EXCL;
197 case RW_TRUNC: mode_str =
"wb+";
198 flags |= O_RDWR | O_CREAT | O_TRUNC;
200 case RW_KEEP: mode_str =
"rb+";
201 flags |= O_RDWR | O_CREAT;
203 case RW_APP: mode_str =
"ab+";
204 flags |= O_RDWR | O_CREAT | O_APPEND;
206 case RW_NEW: mode_str =
"wb+";
207 flags |= O_RDWR | O_CREAT | O_EXCL;
216 int create_mode = _S_IREAD | _S_IWRITE;
218 int create_mode = 0664;
220 int fd = open(filename.
c_str(), flags, create_mode);
222 helper->fp = fdopen(fd, mode_str.
c_str());
224 if (helper->fp == NULL) {
229 if (helper->fp == NULL) {
233 if ((mode == R_ONLY) || (mode == RW_TRUNC) ||
234 (mode == RW_APP) || (mode == RW_NEW)) {
235 helper->is_readable =
true;
238 if ((mode == W_TRUNC) || (mode == W_APP) || (mode == W_NEW) ||
239 (mode == RW_TRUNC) || (mode == RW_APP) || (mode == RW_NEW)) {
240 helper->is_writable =
true;
245 inline void BaseOpen(FILE *fp,
bool do_close) {
248 helper =
new FileHelper();
251 helper->do_close = do_close;
254 inline void BaseSwitchWrite()
const {
255 if (helper->last_was_read) {
256 BaseRelativePosition(0);
257 helper->last_was_read =
false;
259 helper->last_was_write =
true;
262 inline void BaseSwitchRead()
const {
263 if (helper->last_was_write) {
264 BaseRelativePosition(0);
265 helper->last_was_write =
false;
267 helper->last_was_read =
true;
271 inline void BaseWrite(
const Data1D<T> &data,
272 const size_t amnt_to_write)
const {
277 if (amnt_to_write == 0) {
280 data.
Assert(amnt_to_write-1);
284 amnt_written = fwrite(data.
Raw(), data.
TypeSize(), amnt_to_write,
287 if (amnt_written < amnt_to_write) {
288 if (ferror(helper->fp) != 0) {
294 inline void BaseRelativePosition(
const i64 amnt)
const {
295 if (fseek(helper->fp, amnt, SEEK_CUR) < 0) {
302 inline void BufFlush() {
303 if (helper->IsWriteBuf()) {
304 BaseWrite(helper->buf, helper->index);
311 static const size_t min_buf_size = 65536;
319 helper =
new FileHelper();
325 helper = other.helper;
333 helper = other.helper;
351 return (helper->filename);
357 helper->filename = newfilename;
370 return (helper->fp != NULL);
375 return (helper->fp == NULL);
380 return (
IsOpen() && (helper->is_readable));
385 return (
IsOpen() && (helper->is_writable));
390 inline FILE*
Raw()
const {
405 struct stat filestats;
409 if (fstat(fileno(helper->fp), &filestats) < 0) {
413 return (filestats.st_size);
422 if (fseek(helper->fp, pos, SEEK_SET) < 0) {
435 BaseRelativePosition(amnt);
446 if ( (pos = ftell(helper->fp)) < 0) {
447 if (quiet_fail) {
return 0; }
451 return size_t(pos) + helper->index - helper->amnt_read;
456 if (helper->IsReadBuf()) {
457 BaseRelativePosition(
i64(helper->index)-
i64(helper->amnt_read));
458 helper->amnt_read = 0;
465 if (helper->is_writable) {
467 if (fflush(helper->fp) != 0) {
487 inline void FillBuff(
size_t min_requested=0) {
488 if (helper->buf.size() < min_requested) {
489 if (min_requested < min_buf_size) {
490 helper->buf.Resize(min_buf_size);
493 helper->buf.Resize(min_requested);
496 if (helper->amnt_read > helper->index) {
497 std::copy(helper->buf.Raw()+helper->index,
498 helper->buf.Raw()+helper->amnt_read,
500 helper->buf.SetOffset(helper->amnt_read - helper->index);
501 helper->amnt_read +=
Read(helper->buf) - helper->index;
502 helper->buf.SetOffset(0);
505 helper->amnt_read =
Read(helper->buf);
521 if ( !
Open(filename)) {
546 return BaseOpen(filename, R_ONLY);
551 inline void Open(FILE *fp,
bool do_close) {
552 BaseOpen(fp, do_close);
553 helper->is_readable =
true;
559 Open(fp, (fp != stdin));
581 if (data.
size() < amnt_to_read) {
582 data.
Resize(amnt_to_read);
585 amnt_read = fread(data.
Raw(), data.
TypeSize(), amnt_to_read, helper->fp);
587 if (amnt_read == 0) {
588 if (ferror(helper->fp) != 0) {
617 size_t amnt_to_read = 1+65535/
sizeof(T);
628 size_t initial_offset = data.
GetOffset();
629 estimate = initial_offset + amnt_to_read;
632 size_t total_read = 0;
634 data.
Resize(amnt_to_read);
635 amnt_read =
Read(data);
636 if (amnt_read == 0) {
639 total_read += amnt_read;
640 data.
SetOffset(initial_offset + total_read);
671 for (partsread=0; readmore; partsread++) {
672 retv = fgets(str.
Raw(), str.
size(), helper->fp);
674 if (ferror(helper->fp) != 0) {
678 if (partsread == 0) {
688 amnt_read = strlen(str.
Raw());
689 if ( (amnt_read != (str.
size()-1)) || (str[amnt_read-1] ==
'\n') ) {
693 while (amnt_read >= 1) {
694 if ( (str[amnt_read-1] ==
'\n') || (str[amnt_read-1] ==
'\r') ) {
695 str[amnt_read-1] = 0;
712 inline bool Read(
RStr &line,
bool crop_newline =
true) {
713 return ReadLine(line, crop_newline);
733 while (
ReadLine(str, crop_newlines)) {
754 if (helper->IsWriteBuf()) {
757 if ( (helper->amnt_read - helper->index) <
sizeof(T) ) {
759 if (helper->amnt_read <
sizeof(T)) {
764 data = *
reinterpret_cast<T*
>(helper->buf.Raw()+helper->index);
765 helper->index +=
sizeof(T);
780 inline bool Get(
RStr& data,
bool crop_newline=
true) {
792 if ( ! crop_newline ) {
801 while (arr.
size() > 0 && arr[arr.
size()-1] ==
'\r') {
818 for (
size_t i=0; i<data.
size(); i++) {
819 retval =
Get(data[i], crop_newlines);
833 for (
size_t i=0; i<data.
size(); i++) {
834 retval =
Get(data[i]);
868 while(
Get(tmp, crop_newlines)) {
908 if ( !
Open(filename, mode) ) {
909 if (errno == EEXIST) {
939 return BaseOpen(filename, BaseMode(
int(mode)+1));
944 inline void Open(FILE *fp,
bool do_close) {
945 BaseOpen(fp, do_close);
946 helper->is_writable =
true;
952 Open(fp, (fp != stdout) && (fp != stderr));
963 BaseWrite(data, amnt_to_write);
983 if (fputs(str, helper->fp) < 0) {
984 if (ferror(helper->fp) != 0) {
1006 const bool add_newlines) {
1007 for (
size_t i=0; i<lines.
size(); i++) {
1010 if (fputc(
'\n', helper->fp) == EOF) {
1026 if (helper->IsReadBuf()) {
1029 if ( (helper->buf.size() - helper->index) <
sizeof(T) ) {
1031 if (helper->buf.size() <
sizeof(T)) {
1032 if (
sizeof(T) < min_buf_size) {
1033 helper->buf.Resize(min_buf_size);
1036 helper->buf.Resize(
sizeof(T));
1041 memcpy(helper->buf.Raw()+helper->index, &data,
sizeof(T));
1042 helper->index +=
sizeof(T);
1052 inline void Put(
const char* str) {
1053 const char* tmp = str;
1068 for (
size_t i=0; i<data.
size(); i++) {
1092 for (
size_t i=0; i<data.
size(); i++) {
1105 struct {
u64 a, b, c, d; } tmp;
1109 while (read.
Get(tmp)) {
1113 while (read.
Get(ch)) {
1137 if ( !
Open(filename, mode) ) {
1138 if (errno == EEXIST) {
1168 return BaseOpen(filename, BaseMode(
int(mode)+5));
1173 inline void Open(FILE *fp,
bool do_close) {
1174 BaseOpen(fp, do_close);
1175 helper->is_readable =
true;
1176 helper->is_writable =
true;
1182 Open(fp, (fp != stdin) && (fp != stdout) && (fp != stderr));
1198 template<>
inline bool FileGetWrapper<std::string>(
FileRead& fr,
1199 std::string& data) {
1201 bool retval = fr.
Get(tmp);
1207 template<>
inline void FilePutWrapper<std::string>(
FileWrite& fw,
1208 const std::string& data) {
1221 static const char divider =
'/';
1226 struct stat filestats;
1228 if (stat(pathname.
c_str(), &filestats) < 0) {
1229 if (errno == ENOENT) {
1237 return (filestats.st_size);
1243 struct stat filestats;
1245 if (stat(pathname.
c_str(), &filestats) < 0) {
1256 static inline bool Delete(
const RStr& pathname,
bool quiet_fail=
true) {
1257 if (remove(pathname.
c_str()) != 0) {
1258 if ( ! quiet_fail ) {
1271 bool overwrite=
true) {
1274 WriteMode mode = overwrite ? TRUNCATE : NEWONLY;
1288 bool overwrite=
true) {
1290 if (srcfile == destfile) {
return; }
1293 ren_ret = rename(srcfile.
c_str(), destfile.
c_str());
1294 if (overwrite && ren_ret != 0 && errno == EACCES) {
1296 ren_ret = rename(srcfile.
c_str(), destfile.
c_str());
1301 ren_ret = rename(srcfile.
c_str(), destfile.
c_str());
1304 ren_ret = link(srcfile.
c_str(), destfile.
c_str());
1306 unlink(srcfile.
c_str());
1312 Copy(srcfile, destfile, overwrite);
1325 bool return_true_if_exists=
true) {
1327 RStr tmpdir = dirname;
1328 if (CreateDirectory(tmpdir.
ToLPCTSTR(), NULL)==0) {
1329 if (return_true_if_exists &&
1330 (GetLastError() == ERROR_ALREADY_EXISTS)) {
1336 if (mkdir(dirname.
c_str(), 0777)) {
1337 if (return_true_if_exists && (errno == EEXIST)) {
1353 errchk = _getcwd(cwd, 65536);
1355 errchk = getcwd(cwd, 65536);
1357 if (errchk != NULL) {
1369 bool qualified=
false) {
1371 const char err_msg[] =
"Could not read directory";
1374 RStr path_appended = path +
"\\*";
1375 WIN32_FIND_DATA file_data;
1378 dir_handle = FindFirstFile(path_appended.
ToLPCTSTR(), &file_data);
1380 if (dir_handle == INVALID_HANDLE_VALUE) {
1389 dir_list +=
RStr(file_data.cFileName);
1391 }
while (FindNextFile(dir_handle, &file_data));
1393 struct dirent **namelist;
1395 int entries = scandir(path.
c_str(), &namelist, NULL, NULL);
1400 for (
int i=0; i<entries; i++) {
1401 RStr entry =
RStr(namelist[i]->d_name);
1402 if (entry !=
"." && entry !=
"..") {
1429 if (mid < filename.
length()) {
1432 return filename.
substr(0, mid);
1441 if (split[1].length() == 0) {
1454 return path + filename;
1457 return path +
divider + filename;
1464 if (filename.
size() == 0) {
return ""; }
1465 for (
size_t i=filename.
size()-1; i<filename.
size(); i--) {
1466 if (filename[i] ==
'.') {
1467 return filename.
substr(i+1);
1469 if (filename[i] ==
'\\' || filename[i] ==
'/') {
1479 if (filename.
size() == 0) {
return ""; }
1480 for (
size_t i=filename.
size()-1; i<filename.
size(); i--) {
1481 if (filename[i] ==
'.') {
1482 return filename.
substr(0,i);
1484 if (filename[i] ==
'\\' || filename[i] ==
'/') {
Provides a one-dimensional vector-like structure.
Provides informative exception handling.
#define Throw_RC_Type(Type, err)
Use this to throw an RC:ErrorMsg subtype exception.
Definition: Errors.h:282
Provides a safe pointer class which throws exceptions.
The version information and configuration settings for RC Lib.
Provides a robust value-added wrapper for std::string.
Provides typedefs and routines for working with primitives.
uint64_t u64
64-bit unsigned integer.
Definition: Types.h:31
int64_t i64
64-bit signed integer.
Definition: Types.h:30
A bounds-safe one-dimensional vector-like structure.
Definition: Data1D.h:49
void Append(const T &newT)
Add an element to the end, expanding if necessary.
Definition: Data1D.h:811
size_t TypeSize() const
Returns the size of this Data1D's type.
Definition: Data1D.h:361
size_t GetOffset() const
Returns the current offset for index 0.
Definition: Data1D.h:372
void Delete()
Delete all the elements and free all allocated memory.
Definition: Data1D.h:188
void Sort()
Sorts the elements according to T::operator< in N*log2(N) time.
Definition: Data1D.h:707
T * Raw() const
Access a raw unprotected C-pointer to the enclosed data.
Definition: Data1D.h:356
void Reserve(const size_t reserve_size)
Reserve storage without resizing the array.
Definition: Data1D.h:271
void SetOffset(const size_t new_offset)
Set a new offset position for index 0.
Definition: Data1D.h:314
size_t size() const
Returns the current number of elements.
Definition: Data1D.h:359
void Assert(const size_t x) const
Throws an ErrorMsgBounds exception if x is out of bounds.
Definition: Data1D.h:262
void Resize(const size_t resize_size)
Resize the array, reallocating if necessary.
Definition: Data1D.h:302
size_t reserved() const
Returns the number of elements for which space is reserved.
Definition: Data1D.h:365
A bounds-safe two-dimensional resizeable structure.
Definition: Data2D.h:32
Data1D< Data1D< T > > & RawData()
Access the underlying nested Data1D structure for this object.
Definition: Data2D.h:300
A bounds-safe three-dimensional resizeable structure.
Definition: Data3D.h:31
const Data1D< Data2D< T > > & RawData() const
Access the underlying nested Data1D/Data2D structure for this object.
Definition: Data3D.h:292
Provides the common methods for the FileRead/FileWrite/FileRW classes.
Definition: File.h:89
void SetPosition(const size_t pos)
Sets the reading and writing position to pos bytes into the file.
Definition: File.h:418
FileBase()
Default constructor.
Definition: File.h:318
void Close()
Flushes the buffers and closes the file.
Definition: File.h:362
FILE * Raw() const
Returns a raw FILE* which can be used with the C file functions.
Definition: File.h:390
void Assert() const
Throws ErrorMsgFile if the file is closed.
Definition: File.h:396
FileBase & operator=(const FileBase &other)
Assignment operator.
Definition: File.h:329
void SetFilename(const RStr &newfilename) const
Manually changes the associated filename.
Definition: File.h:356
size_t GetPosition(bool quiet_fail=false) const
Gets the position for the next read or write operation.
Definition: File.h:442
FileBase(const FileBase &other)
Copy constructor.
Definition: File.h:323
bool IsReadable() const
True if the file is open and readable.
Definition: File.h:379
bool IsOpen() const
True if the file is open.
Definition: File.h:369
void RelativePosition(const i64 amnt)
Sets the position for the next read or write operation.
Definition: File.h:431
bool IsClosed() const
True if the file is closed.
Definition: File.h:374
void ClearBuffer()
Processes the remaining data in the Put/Get buffer.
Definition: File.h:474
void Flush()
Flushes all unsaved data to the storage system.
Definition: File.h:464
RStr GetFilename() const
Returns the filename if one was given upon opening.
Definition: File.h:350
void Rewind()
Clears the read-ahead buffer used by FileRead::Get calls.
Definition: File.h:455
size_t Size() const
Returns the file size in bytes.
Definition: File.h:404
virtual ~FileBase()
Flushes the write buffer before destructing. This will close the file if it is the last FileBase shar...
Definition: File.h:340
bool IsWritable() const
True if the file is open and writable.
Definition: File.h:384
A file class for both reading and writing that provides buffered and unbuffered output to files.
Definition: File.h:1124
bool Open(const RStr &filename, const WriteMode mode=KEEP)
Opens the file specified by filename for reading and writing, using the WriteMode specified by mode.
Definition: File.h:1167
FileRW(const RStr &filename, const WriteMode mode=KEEP)
Opens the file specified by filename for reading and writing, using the WriteMode specified by mode.
Definition: File.h:1135
FileRW(const FileBase &other)
Base copy constructor.
Definition: File.h:1160
FileRW(FILE *fp)
Wraps the FILE* fp for reading and writing. It will close it when finished unless fp is stdin/stdout/...
Definition: File.h:1155
FileRW(FILE *fp, bool do_close)
Wraps the FILE* fp for reading and writing. It will close it when finished if do_close is true.
Definition: File.h:1149
void Open(FILE *fp, bool do_close)
Wraps the FILE* fp for reading and writing. It will close it when finished if do_close is true.
Definition: File.h:1173
void Open(FILE *fp)
Wraps the FILE* fp for reading and writing. It will close it when finished unless fp is stdin/stdout/...
Definition: File.h:1181
FileRW()
Default constructor.
Definition: File.h:1128
A file reading class that provides buffered and unbuffered access to files with support for non-POD c...
Definition: File.h:483
FileRead(const RStr &filename)
Opens the file specified by filename for reading.
Definition: File.h:520
bool Get(Data2D< T > &data)
Fill data with elements of type T, calling Get on each one.
Definition: File.h:847
void Open(FILE *fp, bool do_close)
Wraps the FILE* fp for reading. It will close it when finished if do_close is true.
Definition: File.h:551
bool GetAll(Data1D< T > &data)
Fill data with all elements of type T until the end of file, calling Get on each one.
Definition: File.h:880
bool Get(T &data)
Gets data of type T, after passing through FileGetWrapper.
Definition: File.h:774
bool Get(Data1D< T > &data)
Fill data with elements of type T, calling Get on each one.
Definition: File.h:831
void ReadAll(Data1D< RStr > &lines, bool crop_newlines=true)
Does ReadAllLines.
Definition: File.h:739
void ReadAllLines(Data1D< RStr > &lines, bool crop_newlines=true)
Reads all the lines found until the end of the file. If crop_newlines is true they are removed from e...
Definition: File.h:726
bool Get(Data1D< RStr > &data, bool crop_newlines=true)
Fill data with lines from the file, removing the newlines if crop_newlines is true.
Definition: File.h:816
FileRead(FILE *fp)
Wraps the FILE* fp for reading. It will close it when finished unless fp is stdin.
Definition: File.h:534
FileRead(const FileBase &other)
Base copy constructor.
Definition: File.h:539
void ReadAll(Data1D< T > &data)
Reads all data until the end of file into data as plain old data type T.
Definition: File.h:610
void Open(FILE *fp)
Wraps the FILE* fp for reading. It will close it when finished unless fp is stdin.
Definition: File.h:558
bool RawGet(T &data)
Performs a buffered read of sizeof(T) bytes and assigns them to data.
Definition: File.h:748
bool SkipLine()
Discards one line until newline, null, or end of file.
Definition: File.h:718
FileRead()
Default constructor.
Definition: File.h:514
bool GetAll(Data1D< RStr > &data, bool crop_newlines=true)
Fill data with all lines from the file until the end, removing the newlines if crop_newlines is true.
Definition: File.h:864
bool Get(Data3D< T > &data)
Fill data with elements of type T, calling Get on each one.
Definition: File.h:856
FileRead(FILE *fp, bool do_close)
Wraps the FILE* fp for reading. It will close it when finished if do_close is true.
Definition: File.h:528
size_t Read(Data1D< T > &data, const size_t amnt_to_read)
Reads amnt_to_read elements of plain old data type T into data without buffering, resizing if too sma...
Definition: File.h:569
bool Read(RStr &line, bool crop_newline=true)
Does ReadLine.
Definition: File.h:712
bool Get(RStr &data, bool crop_newline=true)
Gets one line into data, up to the newline, null, or end of file, removing the newline if crop_newlin...
Definition: File.h:780
bool Open(const RStr &filename)
Opens the file specified by filename for reading.
Definition: File.h:545
size_t Read(Data1D< T > &data)
Fills data with plain old data type T without buffering.
Definition: File.h:602
bool ReadLine(RStr &line, bool crop_newline=true)
Reads one line until newline, null, or end of file. The newline is removed if crop_newline is true.
Definition: File.h:657
A file writing class that provides buffered and unbuffered output to files with support for non-POD c...
Definition: File.h:895
FileWrite & operator<<(FileRead &read)
Get all the remaining data from the FileRead, and Put it to this FileWrite.
Definition: File.h:1103
void Put(const Data1D< RStr > &data, const bool add_newline)
Puts each RStr in data into the write buffer, adding newlines to each if add_newline is true.
Definition: File.h:1091
void RawPut(const T &data)
Performs a buffered write of sizeof(T) raw bytes extracted from data.
Definition: File.h:1020
void WriteStr(const RStr &str)
Writes the RStr str without buffering.
Definition: File.h:994
void Put(const RStr &str)
Puts the RStr str into the write buffer.
Definition: File.h:1061
void Write(const Data1D< T > &data)
Writes all of data's plain old data type T without buffering.
Definition: File.h:970
FileWrite()
Default constructor.
Definition: File.h:899
void WriteAllStr(const Data1D< RStr > &lines, const bool add_newlines)
Writes all lines without buffering, adding a newline after each if add_newlines is true.
Definition: File.h:1005
void Put(const Data1D< T > &data)
Calls Put for each element of data.
Definition: File.h:1067
void Put(const char *str)
Puts the null-terminated character data str into the write buffer, excluding the null.
Definition: File.h:1052
FileWrite(const FileBase &other)
Base copy constructor.
Definition: File.h:931
void Put(const Data3D< T > &data)
Calls Put for each element of data.
Definition: File.h:1085
FileWrite(const RStr &filename, const WriteMode mode=TRUNCATE)
Opens the file specified by filename for writing, using the WriteMode specified by mode.
Definition: File.h:906
void WriteStr(const char *str)
Writes the null-terminated contents of str without buffering.
Definition: File.h:978
void Write(const Data1D< T > &data, const size_t amnt_to_write)
Writes amnt_to_write elements of plain old data type T from data without buffering.
Definition: File.h:961
bool Open(const RStr &filename, const WriteMode mode=TRUNCATE)
Opens the file specified by filename for writing, using the WriteMode specified by mode.
Definition: File.h:938
void Put(const Data2D< T > &data)
Calls Put for each element of data.
Definition: File.h:1077
void Put(const T &data)
Puts data of type T into the write buffer, after passing through FilePutWrapper.
Definition: File.h:1048
FileWrite(FILE *fp, bool do_close)
Wraps the FILE* fp for writing. It will close it when finished if do_close is true.
Definition: File.h:920
FileWrite(FILE *fp)
Wraps the FILE* fp for writing. It will close it when finished unless fp is stdout.
Definition: File.h:926
void Open(FILE *fp, bool do_close)
Wraps the FILE* fp for writing. It will close it when finished if do_close is true.
Definition: File.h:944
void Open(FILE *fp)
Wraps the FILE* fp for writing. It will close it when finished unless fp is stdout or stderr.
Definition: File.h:951
A class with static methods for file and directory info and manipulation.
Definition: File.h:1214
static void Move(const RStr &srcfile, const RStr &destfile, bool overwrite=true)
Moves srcfile to destfile by copying the contents and then deleting srcfile.
Definition: File.h:1287
static RStr CurrentDir()
Returns the current working directory.
Definition: File.h:1348
static RStr FullPath(const RStr &path, const RStr &filename)
Merges path and filename into a path with a divider inserted if needed.
Definition: File.h:1452
static size_t Size(const RStr &pathname)
Returns the file size of pathname, or 0 if the file does not exist.
Definition: File.h:1225
static Data1D< RStr > DirList(const RStr &path, bool qualified=false)
Returns a list of entries in the directory path.
Definition: File.h:1368
static bool MakeDir(const RStr &dirname, bool return_true_if_exists=true)
Makes a new directory dirname.
Definition: File.h:1324
static RStr Extension(const RStr &filename)
Extracts the filename's extension.
Definition: File.h:1463
static bool Exists(const RStr &pathname)
Returns true if the file pathname exists.
Definition: File.h:1242
static void Copy(const RStr &srcfile, const RStr &destfile, bool overwrite=true)
Copies the contents of srcfile to destfile. It will overwrite an existing file only if overwrite is t...
Definition: File.h:1270
static bool Delete(const RStr &pathname, bool quiet_fail=true)
Deletes the file pathname, returning true if it succeeded.
Definition: File.h:1256
static RStr Dirname(const RStr &filename)
Extracts the directory portion of filename, or the current directory if filename has no directory.
Definition: File.h:1422
static const char divider
The OS-specific divider between directories in a pathname.
Definition: File.h:1219
static RStr NoExtension(const RStr &filename)
Extracts the filename without the extension.
Definition: File.h:1478
static RStr Basename(const RStr &filename)
Extracts the basename portion of filename, which excludes the directory.
Definition: File.h:1439
A bounds-safe string class which provides an identical interface to std::string plus many convenience...
Definition: RStr.h:110
size_t size() const
Returns the length of the string.
Definition: RStr.h:263
const char * c_str() const
Provides a null-terminated C style string corresponding to RStr.
Definition: RStr.h:622
Data1D< RStr > SplitLast(const RStr ÷rs) const
Return an array of 2 strings split at the last character from dividers.
Definition: RStr.h:1684
std::string & Raw()
Provides raw access to the std::string this RStr wraps.
Definition: RStr.h:1325
const char * ToLPCTSTR()
For Win32, provides an LPCTSTR to the string.
Definition: RStr.h:1317
size_t length() const
Returns the length of the string.
Definition: RStr.h:265
RStr substr(size_t pos=0, size_t n=npos) const
Creates a substring from n characters starting at position pos, or until the end of the string.
Definition: RStr.h:826
size_t find_last_of(const RStr &s, size_t pos=npos) const
Returns the highest index at pos or before which matches a character in s, or npos if none match.
Definition: RStr.h:739
static const size_t npos
The largest possible value of size_t.
Definition: RStr.h:2215
WriteMode
Valid write modes for a FileWrite or FileRW.
Definition: File.h:86
void FilePutWrapper(FileWrite &fw, const T &data)
Overload this with a specialization to support Put on a custom type.
Definition: File.h:1193
bool FileGetWrapper(FileRead &fr, T &data)
Overload this with a specialization to support Get on a custom type.
Definition: File.h:1188