HEBI C++ API  3.8.0
file.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 
5 namespace hebi {
6 namespace util {
7 namespace file {
8 
9 // Reads contents of file into string; returns empty string on error.
10 std::string readIntoString(std::string filename);
11 
12 // Small wrapper class to handle paths. Stores in os-specific encoding.
13 class File
14 {
15 public:
16  File(const char* path) : path_(convertDelimiters(std::string(path)))
17  { }
18  File(std::string path) : path_(convertDelimiters(path))
19  { }
20 
21  File getParentDirectory() const;
22 
23  bool isAbsolute() const;
24 
25  // Append, removing "move up" directory commands at the beginning of path
26  void append(std::string file_or_dir);
27 
28  // Get the path of this file relative to the current working directory
29  std::string getAbsolutePath() const;
30 
31  bool exists() const;
32 
33  static constexpr char WinDelimiter = '\\';
34  static constexpr char PosixDelimiter = '/';
35 
36  static constexpr char getPlatformDelimiter()
37  {
38  #ifdef WIN32
39  return WinDelimiter;
40  #else
41  return PosixDelimiter;
42  #endif
43  }
44  static constexpr char getNonPlatformDelimiter()
45  {
46  #ifdef WIN32
47  return PosixDelimiter;
48  #else
49  return WinDelimiter;
50  #endif
51  }
52 private:
53  static std::string convertDelimiters(std::string path);
54 
55  std::string path_;
56 };
57 
58 } // namespace file
59 } // namespace util
60 } // namespace hebi
std::string getAbsolutePath() const
Definition: file.cpp:88
Definition: file.hpp:13
Definition: arm.cpp:8
File(const char *path)
Definition: file.hpp:16
std::string readIntoString(std::string filename)
Definition: file.cpp:25
bool isAbsolute() const
Definition: file.cpp:60
static constexpr char PosixDelimiter
Definition: file.hpp:34
void append(std::string file_or_dir)
Definition: file.cpp:65
File getParentDirectory() const
Definition: file.cpp:43
bool exists() const
Definition: file.cpp:102
static constexpr char getNonPlatformDelimiter()
Definition: file.hpp:44
static constexpr char WinDelimiter
Definition: file.hpp:33
static constexpr char getPlatformDelimiter()
Definition: file.hpp:36
File(std::string path)
Definition: file.hpp:18