STIR 6.4.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
26
27#include "stir/common.h"
28#include <string>
29#include <vector>
30
31START_NAMESPACE_STIR
32
44
45class FilePath
46{
47public:
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
122private:
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
141protected:
143 std::string my_string;
145 std::string separator;
149};
150
151END_NAMESPACE_STIR
152
153#include "stir/FilePath.inl"
154
155#endif
Implementations of inline functions for class stir::FilePath.
std::string separator
The separator for the current OS.
Definition FilePath.h:145
bool is_writable() const
On Windows the attribute INVALID_FILE_ATTRIBUTES is used. Which is not quite the same.
Definition FilePath.cxx:102
std::string get_filename_no_extension() const
Convinience function which returns the filename withouth the extension.
Definition FilePath.cxx:263
std::string get_path_only() const
Get the path from string. If no path in string returns empty string.
Definition FilePath.cxx:229
FilePath append(const FilePath &p)
Create a new folder,by FilePath, and return its path as FilePath.
Definition FilePath.cxx:139
std::string get_filename() const
Get only the filename An inherent functionality from utilities is that on Windows all separators will...
Definition FilePath.cxx:242
std::string get_path() const
Get path from string.
Definition FilePath.cxx:217
std::string my_string
This is the string holding the data.
Definition FilePath.h:143
static void append_separator(std::string &s)
Append the separator.
Definition FilePath.cxx:399
void prepend_directory_name(const std::string &p)
If path is no absolute then prepend the p string.
Definition FilePath.cxx:444
void replace_extension(const std::string &e)
Replace extension.
Definition FilePath.cxx:206
bool is_directory() const
Returns true if my_string points to a directory.
Definition FilePath.cxx:64
static bool is_absolute(const std::string &_filename_with_directory)
Returns true if the _filename_with_directory is an absolute path.
Definition FilePath.cxx:413
void add_extension(const std::string &e)
Append extension e if none is present.
Definition FilePath.cxx:198
static bool exists(const std::string &s)
Returns true if the path s already exists.
Definition FilePath.cxx:117
static std::string get_current_working_directory()
Returns the current / working directory.
Definition FilePath.cxx:324
std::string get_extension() const
Get the extension of the filename.
Definition FilePath.cxx:276
bool is_regular_file() const
Returns true if my_string points to a regular file Returns true if the path is writable.
Definition FilePath.cxx:82
std::string get_as_string() const
Return the current full string.
Definition FilePath.cxx:287
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
basic configuration include file