ResourcePath.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
5 
6 namespace iv
7 {
8 
21 {
22 public:
23  ResourcePath();
24  ResourcePath( const char * abspath );
25  ResourcePath( std::string const & abspath );
26 
27  ResourcePath & operator=( const char * abspath );
28  ResourcePath & operator=( std::string const & abspath );
29 
30  ResourcePath operator+( std::string const & append ) const;
31  ResourcePath & operator+=( std::string const & append );
32 
33  ResourcePath operator/( std::string const & join ) const;
34  ResourcePath & operator/=( std::string const & join );
35 
36  std::string const & string() const;
37 
38  bool empty() const;
39 
43  std::string to_real_path( const char * vroot ) const;
44 
48  ResourcePath get_neighbour_path( const char * relative ) const;
49 
55 
56  bool operator==( ResourcePath const & other ) const;
57  bool operator!=( ResourcePath const & other ) const;
58  bool operator<( ResourcePath const & other ) const;
59 
60  static void Clean( std::string & path );
61 
62 private:
63  mutable std::string path;
64 };
65 
66 inline std::ostream & operator<<( std::ostream & out, iv::ResourcePath const & path )
67 {
68  out << path.string();
69  return out;
70 }
71 
73 {
74 public:
75  Resource_LogTrace( ResourcePath const & path ) :
76  path( path )
77  {
78  }
79 
80  virtual void PrintTraceLine( std::ostream & out ) override
81  {
82  out << "Resource '" << this->path << "':" << std::endl;
83  }
84 
85 private:
86  ResourcePath path;
87 };
88 
93 template<>
95 {
96  ResourcePath Read( const char * name, Context const * context )
97  {
98  ResourcePath target_path;
99  std::string filename = name;
100  if( filename.size() > 0 && filename[ 0 ] == '/' )
101  { // absolute path
102  target_path = filename;
103  }
104  else
105  { // relative path
106  //target_path = cwd.get_neighbour_path( filename.c_str() );
107  context->warning( SRC_INFO, "Reading relative paths to ResourcePath is not currently implemented." );
108  }
109 
110  return target_path;
111  }
112 
113  std::string Write( ResourcePath const & value, Context const * context ) const
114  {
115  return value.string();
116  }
117 };
118 
119 }
120 
121 namespace std
122 {
123 
124 template<>
125 struct hash< iv::ResourcePath >
126 {
127  size_t operator()( iv::ResourcePath const & val ) const
128  {
129  return std::hash< std::string >()( val.string() );
130  }
131 };
132 
133 }