STIR  6.2.0
FilePath.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2018, University of Hull
3 
4  This file is part of STIR.
5  SPDX-License-Identifier: Apache-2.0
6 
7  See STIR/LICENSE.txt for details
8 */
9 
10 #ifndef __stir_FILEPATH_H__
11 #define __stir_FILEPATH_H__
12 
27 #include "stir/common.h"
28 #include <string>
29 #include <vector>
30 
31 START_NAMESPACE_STIR
32 
45 class FilePath
46 {
47 public:
48  FilePath();
49 
55  FilePath(const std::string& __str, bool _run_checks = true);
56 
57  ~FilePath() {}
58 
60  bool is_directory() const;
64  bool is_regular_file() const;
66  bool is_writable() const;
68  // This funtion has been copied from the Functions for filename manipulations
69  static bool is_absolute(const std::string& _filename_with_directory);
71  static bool exists(const std::string& s);
73  static std::string get_current_working_directory();
75  FilePath append(const FilePath& p);
80  FilePath append(const std::string& p);
82  static void append_separator(std::string& s);
84  // This funtion has been copied from the Functions for filename manipulations
85  void prepend_directory_name(const std::string& p);
87  // This funtion has been copied from the Functions for filename manipulations
88  void add_extension(const std::string& e);
90  // This funtion has been copied from the Functions for filename manipulations
91  void replace_extension(const std::string& e);
93  std::string get_path() const;
95  std::string get_path_only() const;
98  std::string get_filename() const;
100  std::string get_filename_no_extension() const;
102  // This function will return the the bit that is after the last dot.
103  std::string get_extension() const;
105  std::string get_as_string() const;
106 
107  inline std::string get_string() const;
108 
109  inline bool operator==(const FilePath& other);
110 
111  inline bool operator==(const std::string& other);
112 
113  inline void operator=(const FilePath& other);
114 
120  inline void operator=(const std::string& other);
121 
122 private:
124  void checks() const;
126  const std::vector<std::string> split(const std::string& s, const char* c = "");
127 
129  std::string merge(const std::string& first, const std::string& sec);
130 
132  inline void initSeparator();
133 
135  // This funtion has been copied from the Functions for filename manipulations
136  std::string::size_type find_pos_of_filename() const;
138  // This funtion has been copied from the Functions for filename manipulations
139  std::string::size_type find_pos_of_extension() const;
140 
141 protected:
143  std::string my_string;
145  std::string separator;
149 };
150 
151 END_NAMESPACE_STIR
152 
153 #include "stir/FilePath.inl"
154 
155 #endif
Implementations of inline functions for class stir::FilePath.
char * prepend_directory_name(char *filename_with_directory, const char *const directory_name)
Prepend directory_name to the filename, but only if !is_absolute_pathname(filename_with_directory) ...
Definition: utilities.cxx:285
std::string separator
The separator for the current OS.
Definition: FilePath.h:145
The FilePath class.
Definition: FilePath.h:45
std::string my_string
This is the string holding the data.
Definition: FilePath.h:143
bool run_checks
Run checks on the my_string on various occations. You want this when you operate on existing paths...
Definition: FilePath.h:148
string & add_extension(string &file_in_directory_name, const string &extension)
Append extension if none present.
Definition: utilities.cxx:209
string::size_type find_pos_of_filename(const string &filename_with_directory)
return the position of the start of the filename (i.e. after directory specifications) ...
Definition: utilities.cxx:135
string & replace_extension(string &file_in_directory_name, const string &extension)
Replace extension (or append if none present)
Definition: utilities.cxx:236
string::size_type find_pos_of_extension(const string &file_in_directory_name)
find the position of the &#39;.&#39; of the extension
Definition: utilities.cxx:185
basic configuration include file
string get_filename(const string &filename_with_directory)
return a std::string containing only the filename (i.e. after directory specifications) ...
Definition: utilities.cxx:161