-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFile.hh
More file actions
104 lines (81 loc) · 2.76 KB
/
File.hh
File metadata and controls
104 lines (81 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* --- GSMP-COPYRIGHT-NOTE-BEGIN ---
*
* This copyright note is auto-generated by ./scripts/Create-CopyPatch.
* Please add additional copyright information _after_ the line containing
* the GSMP-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
* the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
*
* GSMP: utility/include/File.hh
* General Sound Manipulation Program is Copyright (C) 2000 - 2004
* Valentin Ziegler and René Rebe
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2. A copy of the GNU General
* Public License can be found in the file LICENSE.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANT-
* ABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* --- GSMP-COPYRIGHT-NOTE-END ---
*/
/* Short Description:
* A simple POSIX file abstraction.
*/
#ifndef UTILITY__FILE_HH__
#define UTILITY__FILE_HH__
#include <sys/stat.h>
#include <string>
namespace Utility
{
class FileType
{
private:
int type;
public:
FileType (int i_type = 0) {type = i_type;}
const FileType& operator= (int n_type) {type = n_type; return *this;}
bool IsUnknown () const {return (type & S_IFMT) == 0;}
bool IsFile () const {return S_ISREG(type);}
bool IsDirectory () const {return S_ISDIR(type);}
bool IsCharDevice () const {return S_ISCHR(type);}
bool IsBlockDevice () const {return S_ISBLK(type);}
bool IsFIFO () const {return S_ISFIFO(type);}
bool IsSymlink () const {return S_ISLNK(type);}
bool IsSocket () const {return S_ISSOCK(type);}
};
/* this is some wrapping around the (ugly) posix directory stuff
not really a perfectly crafted object */
class File
{
public:
File ();
File (const std::string& str);
~File ();
void SetFile (const std::string& str);
const std::string& Dirname ();
const std::string& Basename ();
std::string BasenameWOExtension ();
const std::string& Extension ();
const FileType Type ();
const std::string Name () const {
return filename;
}
// more to be done on demand
private:
inline bool updateStat ();
void updateDirBaseExt ();
void reset ();
std::string filename;
std::string dirname; // just cached
std::string basename; // just cached
std::string extension; // just cached
struct stat c_stat;
bool c_stat_valid;
};
std::ostream& operator<< (std::ostream& os, const File& file);
} // namespace Utility
#endif // UTILITY__FILE_HH__