| 1 |
// -*- related-file-name: "../../liblcdf/filename.cc" -*- |
| 2 |
#ifndef LCDF_FILENAME_HH |
| 3 |
#define LCDF_FILENAME_HH |
| 4 |
#include <lcdf/string.hh> |
| 5 |
#include <stdio.h> |
| 6 |
|
| 7 |
class Filename { public: |
| 8 |
|
| 9 |
Filename() : _dir("."), _actual(0) { } |
| 10 |
Filename(const String &); |
| 11 |
Filename(const String &dir, const String &name); |
| 12 |
Filename(FILE *, const String &fake_name); |
| 13 |
|
| 14 |
bool fake() const { return _actual != 0; } |
| 15 |
|
| 16 |
const String &directory() const { return _dir; } |
| 17 |
const String &name() const { return _name; } |
| 18 |
const String &path() const { return _path; } |
| 19 |
String base() const; |
| 20 |
String extension() const; |
| 21 |
|
| 22 |
operator bool() const { return _name; } |
| 23 |
bool operator!() const { return !_name; } |
| 24 |
|
| 25 |
FILE *open_read(bool binary = false) const; |
| 26 |
bool readable() const; |
| 27 |
|
| 28 |
FILE *open_write(bool binary = false) const; |
| 29 |
|
| 30 |
Filename from_directory(const String &n) const { return Filename(_dir, n);} |
| 31 |
|
| 32 |
private: |
| 33 |
|
| 34 |
mutable String _dir; // mutable for c_str() |
| 35 |
mutable String _name; |
| 36 |
mutable String _path; |
| 37 |
FILE *_actual; |
| 38 |
|
| 39 |
}; |
| 40 |
|
| 41 |
#endif |