acl/lib_acl_cpp/include/acl_cpp/stream/fstream.hpp

152 lines
4.3 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include "istream.hpp"
#include "ostream.hpp"
2014-11-19 00:25:21 +08:00
namespace acl {
class string;
2022-08-19 10:28:04 +08:00
class ACL_CPP_API fstream : public istream , public ostream {
2014-11-19 00:25:21 +08:00
public:
fstream(void);
virtual ~fstream(void);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ķ<EFBFBD>ʽ
* @param path {const char*} <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param oflags {unsigned int} <EFBFBD><EFBFBD>־λ, We're assuming that
* O_RDONLY: 0x0000, O_WRONLY: 0x0001, O_RDWR: 0x0002,
* O_APPEND: 0x0008, O_CREAT: 0x0100, O_TRUNC: 0x0200,
* O_EXCL: 0x0400; just for win32, O_TEXT: 0x4000,
* O_BINARY: 0x8000, O_RAW: O_BINARY, O_SEQUENTIAL: 0x0020,
* O_RANDOM: 0x0010.
* @param mode {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>ģʽ(<EFBFBD><EFBFBD>: 0600)
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2014-11-19 00:25:21 +08:00
*/
bool open(const char* path, unsigned int oflags, int mode);
/**
* <EFBFBD>Զ<EFBFBD>/д<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>򴴽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 0700
* @param path {const char*} <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2014-11-19 00:25:21 +08:00
*/
bool open_trunc(const char* path);
/**
* <EFBFBD>Զ<EFBFBD>/д<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ 0700, <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򴴽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򿪾<EFBFBD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EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>´<EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
* @param from_path {const char*} Դ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param to_path {const char*} Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
*/
bool rename(const char* from_path, const char* to_path);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> fstream <EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param fh ϵͳ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param oflags <EFBFBD>򿪱<EFBFBD>־λ
* @param path {const char*} <EFBFBD><EFBFBD> NULL ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD> file_path, remove ʹ<EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
void open(void* fh, unsigned int oflags, const char* path = NULL);
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD>ƶ<EFBFBD><EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
* @param offset {__int64} ƫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param whence {int} <EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SEEK_SET<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ʼλ<EFBFBD>ú<EFBFBD><EFBFBD>ƶ<EFBFBD><EFBFBD><EFBFBD>,
* SEEK_CUR(<EFBFBD>ӵ<EFBFBD>ǰ<EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD>), SEEK_END(<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>β<EFBFBD><EFBFBD>ǰ<EFBFBD>ƶ<EFBFBD>)
* @return {acl_off_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ >= 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1
2014-11-19 00:25:21 +08:00
*/
__int64 fseek(__int64 offset, int whence);
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰϵͳ<EFBFBD>ļ<EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>е<EFBFBD>ƫ<EFBFBD><EFBFBD>λ<EFBFBD><EFBFBD>
* @return {acl_off_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ >= 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1
2014-11-19 00:25:21 +08:00
*/
2019-07-07 11:00:12 +08:00
__int64 ftell(void);
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>ߴ<EFBFBD><EFBFBD>ض<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
* @param length {acl_off_t} <EFBFBD>ļ<EFBFBD><EFBFBD>ضϺ<EFBFBD><EFBFBD>Ĵ<EFBFBD>С<EFBFBD>ߴ<EFBFBD>
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2014-11-19 00:25:21 +08:00
*/
bool ftruncate(__int64 length);
/**
* <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ǰ<EFBFBD>ļ<EFBFBD><EFBFBD>Ĵ<EFBFBD>С
* @return {acl_off_t} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ >= 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1
2014-11-19 00:25:21 +08:00
*/
__int64 fsize(void) const;
/**
* <EFBFBD><EFBFBD>̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ȡָ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>С
* @param path {const char*} <EFBFBD>ǿ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>·<EFBFBD><EFBFBD>
* @return {__int64} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ >= 0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> -1
*/
static __int64 fsize(const char* path);
2014-11-19 00:25:21 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵͳ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return ϵͳ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ACL_FILE_INVALID
2014-11-19 00:25:21 +08:00
*/
2019-07-07 11:00:12 +08:00
void* file_handle(void) const;
2014-11-19 00:25:21 +08:00
#else
void open(int fh, unsigned int oflags, const char* path = NULL);
2014-11-19 00:25:21 +08:00
long long int fseek(long long int offset, int whence);
2019-07-07 11:00:12 +08:00
long long int ftell(void);
2014-11-19 00:25:21 +08:00
bool ftruncate(long long int length);
long long int fsize(void) const;
static long long int fsize(const char* path);
2019-07-07 11:00:12 +08:00
int file_handle(void) const;
2014-11-19 00:25:21 +08:00
#endif
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ȫ·<EFBFBD><EFBFBD>
* @return {const char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>δ<EFBFBD>򿪻<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
*/
2019-07-07 11:00:12 +08:00
const char* file_path(void) const;
2018-07-05 13:56:10 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>򿪺󣬸÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param exclude {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD>Ƕ<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* Ϊ false, <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> acl::last_serror <EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>
2018-07-05 13:56:10 +08:00
*/
bool lock(bool exclude = true);
/**
* <EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>򿪺󣬸÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD>򷵻<EFBFBD> true<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD> false
* @param exclude {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ƿ<EFBFBD><EFBFBD>Ƕ<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>ռ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
* Ϊ false, <EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> acl::last_serror <EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD><EFBFBD>
2018-07-05 13:56:10 +08:00
*/
bool try_lock(bool exclude = true);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> lock <EFBFBD><EFBFBD> try_lock <EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ե<EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2018-07-05 13:56:10 +08:00
*/
bool unlock(void);
2014-11-19 00:25:21 +08:00
};
} // namespace acl