vtk-dicom  0.8.17
vtkDICOMFilePath.h
1 /*=========================================================================
2 
3  Program: DICOM for VTK
4 
5  Copyright (c) 2012-2024 David Gobbi
6  All rights reserved.
7  See Copyright.txt or http://dgobbi.github.io/bsd3.txt for details.
8 
9  This software is distributed WITHOUT ANY WARRANTY; without even
10  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  PURPOSE. See the above copyright notice for more information.
12 
13 =========================================================================*/
14 #ifndef vtkDICOMFilePath_h
15 #define vtkDICOMFilePath_h
16 
17 #include "vtkSystemIncludes.h"
18 #include "vtkDICOMModule.h" // For export macro
19 #include "vtkDICOMConfig.h" // For configuration details
20 
21 #include <string> // Interface type
22 
24 class VTKDICOM_EXPORT vtkDICOMFilePath
25 {
26 public:
28 
33  vtkDICOMFilePath(const std::string& path);
34 
35 #ifdef _WIN32
37 
40  vtkDICOMFilePath(const std::wstring& path);
41 #endif
42 
45 
49 
51  const std::string& AsString() const { return this->Path; }
54 
56  bool IsEmpty() const { return (this->Path.length() == 0); }
58 
60  bool IsRoot() const;
61 
63  bool IsDirectory() const;
64 
66  bool IsSpecial() const;
67 
69  bool IsSymlink() const;
71 
73  std::string Join(const std::string& second) const;
76 
78  std::string GetBack() const;
80 
82  void PopBack();
83 
85  void PushBack(const std::string& path);
87 
89  std::string GetExtension() const;
91 
93  void PopExtension();
94 
96  void PushExtension(const std::string& path);
98 
100 
108  std::string GetRealPath() const;
110 
111 #ifdef _WIN32
113 
118  const wchar_t *Wide();
119 
121 
125  const char *Local();
127 
128 #endif
129 
131  vtkDICOMFilePath& operator=(const vtkDICOMFilePath&);
134 
135 private:
136 
138  static bool IsSeparator(char c) {
139 #ifndef __WRAP__
140 #ifdef _WIN32
141  return (c == '/' || c == '\\');
142 #else
143  return (c == '/');
144 #endif
145 #endif
146  }
147 
149  static void StripTrailingSlash(std::string *path);
150 
152  static size_t ExtensionPosition(const std::string& path);
153 
155 
160  static size_t RootLength(const std::string& path);
161 
162 #ifdef _WIN32
164  static bool HasExtendedPrefix(const std::string& path);
165 
167  static char DriveLetter(const std::string& path);
168 
170  static wchar_t *ConvertToWideChar(const char *filename);
171 
173  static char *ConvertToUTF8(const wchar_t *filename);
174 
176  static char *ConvertToLocal(const wchar_t *filename);
177 #endif
178 
179  std::string Path;
180  char Separator;
181 #ifdef _WIN32
182  wchar_t *WidePath;
183  char *LocalPath;
184 #endif
185 };
186 
187 #endif /* vtkDICOMFilePath_h */
188 // VTK-HeaderTest-Exclude: vtkDICOMFilePath.h
A class that provides path manipulation.
Definition: vtkDICOMFilePath.h:25
vtkDICOMFilePath(const vtkDICOMFilePath &)
Copy constructor.
bool IsDirectory() const
Check whether the path is an existing directory.
vtkDICOMFilePath(const std::string &path)
Create a new path from the given string.
void PopBack()
Remove a component from the path.
void PushExtension(const std::string &path)
Add a new file extension to the current file path.
bool IsSymlink() const
Check whether the path is a symbolic link.
std::string GetRealPath() const
Get the full absolute path (or empty string if file doesn't exist).
void PushBack(const std::string &path)
Add a new component (or components) to the path.
void PopExtension()
Remove the current file extension, including the dot.
~vtkDICOMFilePath()
Destructor.
bool IsRoot() const
Check if the path is a root path.
bool IsSpecial() const
Check whether the path goes to a device, socket, or pipe.