xlnt
path.hpp
1 // Copyright (c) 2014-2022 Thomas Fussell
2 // Copyright (c) 2024 xlnt-community
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a copy
5 // of this software and associated documentation files (the "Software"), to deal
6 // in the Software without restriction, including without limitation the rights
7 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 // copies of the Software, and to permit persons to whom the Software is
9 // furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 // THE SOFTWARE
21 //
22 // @license: http://www.opensource.org/licenses/mit-license.php
23 // @author: see AUTHORS file
24 
25 #pragma once
26 
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 #include <xlnt/xlnt_config.hpp>
32 
33 namespace xlnt {
34 
38 class XLNT_API path
39 {
40 public:
44  static char system_separator();
45 
49  path();
50 
54  explicit path(const std::string &path_string);
55 
59  path(const std::string &path_string, char sep);
60 
61  // general attributes
62 
66  bool is_relative() const;
67 
71  bool is_absolute() const;
72 
76  bool is_root() const;
77 
82  path parent() const;
83 
87  std::string filename() const;
88 
92  std::string extension() const;
93 
97  std::pair<std::string, std::string> split_extension() const;
98 
99  // conversion
100 
105  std::vector<std::string> split() const;
106 
111  const std::string &string() const;
112 
113 #ifdef _MSC_VER
114  std::wstring wstring() const;
119 #endif
120 
126  path resolve(const path &base_path) const;
127 
133  path relative_to(const path &base_path) const;
134 
135  // filesystem attributes
136 
141  bool exists() const;
142 
147  bool is_directory() const;
148 
153  bool is_file() const;
154 
155  // filesystem
156 
161  std::string read_contents() const;
162 
163  // mutators
164 
168  path append(const std::string &to_append) const;
169 
173  path append(const path &to_append) const;
174 
178  bool operator==(const path &other) const;
179 
183  bool operator!=(const path &other) const;
184 
185 private:
194  char guess_separator() const;
195 
199  std::string internal_;
200 };
201 
202 } // namespace xlnt
203 
204 namespace std {
205 
209 template <>
210 struct hash<xlnt::path>
211 {
215  size_t operator()(const xlnt::path &p) const
216  {
217  static hash<string> hasher;
218  return hasher(p.string());
219  }
220 };
221 
222 } // namespace std
const std::string & string() const
Create a string representing this path separated by the provided separator or the system-default sepa...
Definition: cell_reference.hpp:262
size_t operator()(const xlnt::path &p) const
Returns a hashed represenation of the given path.
Definition: path.hpp:215
Enumerates the possible types a cell can be determined by it&#39;s current value.
Definition: cell.hpp:37
bool operator==(std::nullptr_t, const cell &cell)
Returns true if this cell is uninitialized.
Encapsulates a path that points to location in a filesystem.
Definition: path.hpp:38
bool operator!=(const std::string &reference_string, const range_reference &ref)
Returns true if the string representation of the range is not equivalent to ref.