ders::file Class Reference
Provides file I/O operations.
More...
#include <file.hpp>
List of all members.
|
Public Types |
enum | mode { rdo,
wro,
rdwr
} |
| file open modes More...
|
enum | flags { app = 1,
crt = 2,
excl = 4,
trnc = 8
} |
| file open flags More...
|
enum | whence { set,
cur,
end
} |
| seek whence More...
|
Public Member Functions |
| file (mem_pool &m) |
| file (mem_pool &m, const ch_rng &path, mode md, int fls) |
| file (mem_pool &m, int fd) |
| ~file () |
virtual void | destroy (mem_pool &mp2) |
mem_pool & | pool () const |
bool | is_ok () const |
bool | is_opened () const |
bool | is_owned () const |
int | get_fd () const |
const sh_text & | get_name () const |
error | get_err () const |
bool | open (const ch_rng &path, mode md, int fls) |
bool | close () |
bool | attach (int fd) |
bool | detach () |
virtual int | read (void *buf, int n) |
int | read (sh_text &buf, int n) |
virtual int | write (const void *buf, int n) |
int | write (const ch_rng &r) |
int | tell () |
int | seek (int off, whence wh) |
void | ex_is_ok () const |
void | ex_open (const ch_rng &path, mode md, int fls) |
void | ex_close () |
void | ex_attach (int fd) |
void | ex_detach () |
int | ex_read (void *buf, int n) |
int | ex_read (sh_text &buf, int n) |
int | ex_write (const void *buf, int n) |
int | ex_write (const ch_rng &r) |
int | ex_tell () |
int | ex_seek (int off, whence wh) |
Protected Member Functions |
void | operator delete (void *ptr, size_t size) |
Static Protected Member Functions |
template<class T> |
static void | destroy_this (T *ptr, mem_pool &mp2) |
Detailed Description
Provides file I/O operations.
Definition at line 31 of file file.hpp.
Member Enumeration Documentation
seek whence
- Enumerator:
-
Definition at line 38 of file file.hpp.
Constructor & Destructor Documentation
Definition at line 33 of file file.cpp.
00033 : mp(m), name(nt(m))
00034 {
00035 init();
00036 }
Definition at line 38 of file file.cpp.
00038 :
00039 mp(m), name(nt(m))
00040 {
00041 init();
00042 ex_open(path, md, fls);
00043 }
ders::file::file |
( |
mem_pool & |
m, |
|
|
int |
fd | |
|
) |
| | |
Member Function Documentation
virtual void ders::file::destroy |
( |
mem_pool & |
mp2 |
) |
[inline, virtual] |
mem_pool& ders::file::pool |
( |
|
) |
const [inline] |
bool ders::file::is_ok |
( |
|
) |
const [inline] |
bool ders::file::is_opened |
( |
|
) |
const [inline] |
bool ders::file::is_owned |
( |
|
) |
const [inline] |
int ders::file::get_fd |
( |
|
) |
const [inline] |
const sh_text& ders::file::get_name |
( |
|
) |
const [inline] |
error ders::file::get_err |
( |
|
) |
const [inline] |
bool ders::file::open |
( |
const ch_rng & |
path, |
|
|
mode |
md, |
|
|
int |
fls | |
|
) |
| | |
Definition at line 56 of file file.cpp.
00057 {
00058 assert(!is_opened());
00059
00060 fdr=fd::open(nt(mp, path)->c_str(), md, fls, err);
00061 if (fdr==-1) return false;
00062
00063 own=true;
00064 *name=path;
00065
00066 return true;
00067 }
bool ders::file::close |
( |
|
) |
|
Definition at line 69 of file file.cpp.
00070 {
00071 assert(is_owned());
00072
00073 bool rc=fd::close(fdr, err);
00074 if (!rc) return false;
00075
00076 init();
00077 return true;
00078 }
bool ders::file::attach |
( |
int |
fd |
) |
|
Definition at line 80 of file file.cpp.
00081 {
00082 assert(!is_opened());
00083
00084 if (fd<0) {
00085 err=ebadf;
00086 return false;
00087 }
00088
00089 fdr=fd;
00090 own=false;
00091 *name=text_buf(mp)+"(attached to "+fdr+')';
00092 err=ezero;
00093
00094 return true;
00095 }
bool ders::file::detach |
( |
|
) |
|
Definition at line 97 of file file.cpp.
00098 {
00099 assert(is_opened());
00100
00101 init();
00102 return true;
00103 }
int ders::file::read |
( |
void * |
buf, |
|
|
int |
n | |
|
) |
| | [virtual] |
Implements ders::readable.
Definition at line 105 of file file.cpp.
00106 {
00107 assert(n>=0);
00108
00109 if (n==0) {
00110 err=ezero;
00111 return 0;
00112 }
00113
00114 return fd::read(fdr, buf, n, err);
00115 }
int ders::file::read |
( |
sh_text & |
buf, |
|
|
int |
n | |
|
) |
| | |
Definition at line 117 of file file.cpp.
00118 {
00119 assert(n>=0);
00120
00121 buf->clear();
00122 buf->reserve(n);
00123
00124 int rc=read(buf->begin(), n);
00125 assert(rc<=n);
00126 if (rc!=-1) buf->uninitialized_resize(rc);
00127
00128 return rc;
00129 }
int ders::file::write |
( |
const void * |
buf, |
|
|
int |
n | |
|
) |
| | [virtual] |
Implements ders::writable.
Definition at line 131 of file file.cpp.
00132 {
00133 assert(n>=0);
00134
00135 if (n==0) {
00136 err=ezero;
00137 return 0;
00138 }
00139
00140 return fd::write(fdr, buf, n, err);
00141 }
int ders::file::write |
( |
const ch_rng & |
r |
) |
[inline] |
Definition at line 80 of file file.hpp.
00080 { return write(r.beg, r.size()); }
int ders::file::tell |
( |
|
) |
[inline] |
int ders::file::seek |
( |
int |
off, |
|
|
whence |
wh | |
|
) |
| | |
Definition at line 143 of file file.cpp.
00144 {
00145 return fd::seek(fdr, off, wh, err);
00146 }
void ders::file::ex_is_ok |
( |
|
) |
const |
void ders::file::ex_open |
( |
const ch_rng & |
path, |
|
|
mode |
md, |
|
|
int |
fls | |
|
) |
| | |
void ders::file::ex_close |
( |
|
) |
|
void ders::file::ex_attach |
( |
int |
fd |
) |
|
void ders::file::ex_detach |
( |
|
) |
|
int ders::file::ex_read |
( |
void * |
buf, |
|
|
int |
n | |
|
) |
| | |
int ders::file::ex_read |
( |
sh_text & |
buf, |
|
|
int |
n | |
|
) |
| | |
int ders::file::ex_write |
( |
const void * |
buf, |
|
|
int |
n | |
|
) |
| | |
int ders::file::ex_write |
( |
const ch_rng & |
r |
) |
[inline] |
int ders::file::ex_tell |
( |
|
) |
|
int ders::file::ex_seek |
( |
int |
off, |
|
|
whence |
wh | |
|
) |
| | |
template<class T>
void ders::destroyable::destroy_this |
( |
T * |
ptr, |
|
|
mem_pool & |
mp2 | |
|
) |
| | [inline, static, protected, inherited] |
Definition at line 47 of file destroy.hpp.
00048 {
00049 assert(typeid(*ptr)==typeid(T));
00050
00051 ptr->~T();
00052 mp2.deallocate(ptr, sizeof(T));
00053 }
void ders::destroyable::operator delete |
( |
void * |
ptr, |
|
|
size_t |
size | |
|
) |
| | [inline, protected, inherited] |
The documentation for this class was generated from the following files: