Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
path.h
1 #pragma once
2 
3 #include <string>
4 
5 namespace smlt {
6 
7 class Path {
8 public:
9  Path() = default;
10 
11  Path(const char* path):
12  path_(path) {}
13 
14  Path(const std::string& path):
15  path_(path) {}
16 
17  Path parent() const;
18 
19  std::string str() const {
20  return path_;
21  }
22 
23  std::string ext() const;
24 
25  /* Returns a new Path object, with the extension replaced. If there is no
26  * extension this will effectively append the extension to the path. */
27  Path replace_ext(const std::string& new_ext) const {
28  std::string prefix = path_.substr(0, path_.find_last_of("."));
29 
30  auto ext = new_ext;
31 
32  if(!ext.empty() && ext[0] == '.') {
33  ext = ext.substr(1, std::string::npos);
34  }
35 
36  return Path(prefix + "." + ext);
37  }
38 
39  bool operator==(const Path& p) const;
40  bool operator<(const Path& p) const;
41  bool operator!=(const Path& p) const {
42  return !(*this == p);
43  }
44 private:
45  std::string path_;
46 };
47 
48 std::ostream& operator<<(std::ostream& os, const Path& p);
49 
50 }
51 
52 namespace std {
53 
54 template<>
55 struct hash<smlt::Path> {
56  std::size_t operator()(const smlt::Path& k) const {
57  return hash<std::string>()(k.str());
58  }
59 };
60 
61 }
smlt
Definition: animation.cpp:25
smlt::Path
Definition: path.h:7
std
Extensions to the C++ standard library.
Definition: unique_id.h:200