Simulant  21.12-194
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  std::string str() const {
18  return path_;
19  }
20 
21  std::string ext() const;
22 
23  /* Returns a new Path object, with the extension replaced. If there is no
24  * extension this will effectively append the extension to the path. */
25  Path replace_ext(const std::string& new_ext) const {
26  std::string prefix = path_.substr(0, path_.find_last_of("."));
27 
28  auto ext = new_ext;
29 
30  if(!ext.empty() && ext[0] == '.') {
31  ext = ext.substr(1, std::string::npos);
32  }
33 
34  return Path(prefix + "." + ext);
35  }
36 
37  bool operator==(const Path& p) const;
38  bool operator<(const Path& p) const;
39  bool operator!=(const Path& p) const {
40  return !(*this == p);
41  }
42 private:
43  std::string path_;
44 };
45 
46 std::ostream& operator<<(std::ostream& os, const Path& p);
47 
48 }
49 
50 namespace std {
51 
52 template<>
53 struct hash<smlt::Path> {
54  std::size_t operator()(const smlt::Path& k) const {
55  return hash<std::string>()(k.str());
56  }
57 };
58 
59 }
smlt
Definition: animation.cpp:25
smlt::Path
Definition: path.h:7
std
Extensions to the C++ standard library.
Definition: unique_id.h:200