gamspath.h
1/*
2  * GAMS - General Algebraic Modeling System C++ API
3  *
4  * Copyright (c) 2017-2022 GAMS Software GmbH <support@gams.com>
5  * Copyright (c) 2017-2022 GAMS Development Corp. <support@gams.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24  */
25 
26 #ifndef GAMSPATH_H
27 #define GAMSPATH_H
28 
29 #include <filesystem>
30 
31 namespace gams {
32 
34 class GAMSPath : public std::filesystem::path
35 {
36 public:
38  GAMSPath() : std::filesystem::path() {}
39 
42  GAMSPath(const char *file) : std::filesystem::path(file) {}
43 
46  GAMSPath(const std::string &file) : std::filesystem::path(file) {}
47 
50  GAMSPath(const std::filesystem::path &file) : std::filesystem::path(file) {}
51 
55  GAMSPath(const std::filesystem::path & dir, const std::string &file) : std::filesystem::path(dir / file){ }
56 
59  GAMSPath(const GAMSPath &gpath) : std::filesystem::path(gpath.string()) {}
60 
64  GAMSPath &operator=(const GAMSPath &other);
65 
69  GAMSPath &operator <<(const std::string &append);
70 
74  GAMSPath &operator +=(const std::string &append);
75 
79  GAMSPath operator +(const std::string &append);
80 
84  GAMSPath operator +(const char *append);
85 
89  GAMSPath operator /(const GAMSPath &append);
90 
94  GAMSPath operator /(const std::string &append);
95 
99  GAMSPath operator /(const char *append);
100 
102  operator std::string();
103 
105  std::string toStdString() const;
106 
109  const char* c_str() const;
110 
114  GAMSPath tempDir(const std::string &tempPath = std::string());
115 
119  GAMSPath tempFile(const std::string &tempName = "XXXXXX.tmp");
120 
123  void setSuffix(const char *suffix);
124 
127  void setSuffix(const std::string &suffix);
128 
132  GAMSPath suffix(const std::string &suffix) const;
133 
137  GAMSPath suffix(const char *suffix) const;
138 
141  GAMSPath up() const;
142 
144  std::string suffix() const;
145 
147  GAMSPath path() const;
148 
150  bool mkDir() const;
151 
154  bool rmDirRecurse();
155 
157  void pack();
158 
161  bool remove();
162 
166  bool rename(const std::string &newFileName);
167 
171  bool rename(const char *newFileName);
172 
175  bool exists() const;
176 
180  static bool exists(const std::string &file);
181 
185  static bool exists(const char *file);
186 
187 };
188  static thread_local bool seedGenerated;
189 }
190 
191 #endif // GPATH_H
void setSuffix(const std::string &suffix)
GAMSPath & operator+=(const std::string &append)
GAMSPath suffix(const std::string &suffix) const
const char * c_str() const
GAMSPath operator+(const std::string &append)
bool rename(const char *newFileName)
GAMSPath suffix(const char *suffix) const
Definition: gams.h:91
GAMSPath up() const
GAMSPath operator/(const GAMSPath &append)
bool exists() const
std::string suffix() const
Path suffix.
bool mkDir() const
Create the directory.
bool rename(const std::string &newFileName)
Represents the GAMS path to a specific file.
Definition: gamspath.h:35
GAMSPath & operator<<(const std::string &append)
GAMSPath tempFile(const std::string &tempName="XXXXXX.tmp")
std::string toStdString() const
Get the path or file as std::string.
void pack()
Normalizes the Path to make it comparable by converting it to it's shortest absolute representation.
GAMSPath path() const
Get the GAMSPath.
static bool exists(const std::string &file)
GAMSPath(const std::string &file)
Definition: gamspath.h:46
GAMSPath tempDir(const std::string &tempPath=std::string())
bool rmDirRecurse()
GAMSPath(const std::filesystem::path &dir, const std::string &file)
Definition: gamspath.h:55
GAMSPath & operator=(const GAMSPath &other)
GAMSPath(const std::filesystem::path &file)
Definition: gamspath.h:50
static bool exists(const char *file)
void setSuffix(const char *suffix)
GAMSPath()
Standard constructor.
Definition: gamspath.h:38
GAMSPath(const GAMSPath &gpath)
Definition: gamspath.h:59
GAMSPath(const char *file)
Definition: gamspath.h:42