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

155 lines
5.0 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;
class ACL_CPP_API fstream
: public istream
, public ostream
{
public:
fstream(void);
virtual ~fstream(void);
/**
* ,
* @param path {const char*}
* @param oflags {unsigned int} , 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} (: 0600)
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool open(const char* path, unsigned int oflags, int mode);
/**
* /
* , 0700
* @param path {const char*}
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool open_trunc(const char* path);
/**
* / 0700,
*
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool create(const char* path);
/**
*
*
* @return {bool}
*/
bool remove(void);
/**
* WINDOWS
*
* @param from_path {const char*}
* @param to_path {const char*}
* @return {bool}
*/
bool rename(const char* from_path, const char* to_path);
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
* fstream
* @param fh
* @param oflags
* @param path {const char*} NULL
* 便 file_path, remove 使
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
/**
*
* @param offset {__int64}
* @param whence {int} SEEK_SET,
* SEEK_CUR(), SEEK_END()
* @return {acl_off_t} >= 0 -1
2014-11-19 00:25:21 +08:00
*/
__int64 fseek(__int64 offset, int whence);
/**
*
* @return {acl_off_t} >= 0 -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
/**
*
* @param length {acl_off_t}
* @return {bool}
2014-11-19 00:25:21 +08:00
*/
bool ftruncate(__int64 length);
/**
*
* @return {acl_off_t} >= 0 -1
2014-11-19 00:25:21 +08:00
*/
__int64 fsize(void) const;
/**
*
* @param path {const char*}
* @return {__int64} >= 0 -1
*/
static __int64 fsize(const char* path);
2014-11-19 00:25:21 +08:00
/**
*
* @return 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
/**
*
* @return {const char*}
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
/**
*
* @param exclude {bool}
* false,
* @return {bool} false acl::last_serror
*
2018-07-05 13:56:10 +08:00
*/
bool lock(bool exclude = true);
/**
* true
* false
* @param exclude {bool}
* false,
* @return {bool} false acl::last_serror
*
2018-07-05 13:56:10 +08:00
*/
bool try_lock(bool exclude = true);
/**
* lock try_lock
* @return {bool}
2018-07-05 13:56:10 +08:00
*/
bool unlock(void);
2014-11-19 00:25:21 +08:00
};
} // namespace acl