-
Notifications
You must be signed in to change notification settings - Fork 1
/
FileName.h
50 lines (48 loc) · 2.03 KB
/
FileName.h
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
#ifndef INC_FILENAME_H
#define INC_FILENAME_H
#include <string>
#include <vector>
/// Class to hold file name, extension, etc. TODO add to File namespace?
class FileName {
public:
FileName() {}
FileName(std::string const& s) { SetFileName(s); }
FileName(const char* s) { SetFileName( std::string(s) ); }
FileName(const FileName&);
FileName& operator=(const FileName&);
/// Set file name and extensions, perform expansion as necessary.
int SetFileName(std::string const&);
/// Set file name, no expansions.
int SetFileName_NoExpansion(std::string const&);
/// Append given string to file name but do not change extension info.
int AppendFileName(std::string const&);
/// \return Filename with given string prepended to base file name.
FileName PrependFileName(std::string const&) const;
/// Clear FileName
void clear();
/// \return true if string matches full or base file name.
bool MatchFullOrBase(std::string const&) const;
const std::string& Full() const { return fullPathName_; }
const std::string& Base() const { return baseName_; }
const std::string& Ext() const { return extension_; }
const char* full() const { return fullPathName_.c_str(); }
const char* base() const { return baseName_.c_str(); }
const char* ext() const { return extension_.c_str(); }
const std::string& Compress() const { return compressExt_; }
const std::string& DirPrefix() const { return dirPrefix_; }
bool empty() const { return fullPathName_.empty(); }
private:
std::string fullPathName_;
std::string baseName_;
std::string extension_;
std::string compressExt_;
std::string dirPrefix_;
};
/// This namespace contains useful file-related routines.
namespace File {
typedef std::vector<FileName> NameArray;
NameArray ExpandToFilenames(std::string const&);
bool Exists(std::string const&);
bool Exists(FileName const&);
}
#endif