Loading...
Searching...
No Matches
gamspath.h
1/*
2 * GAMS - General Algebraic Modeling System C++ API
3 *
4 * Copyright (c) 2017-2023 GAMS Software GmbH <support@gams.com>
5 * Copyright (c) 2017-2023 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
31namespace gams {
32
34class GAMSPath : public std::filesystem::path
35{
36public:
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
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
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
Represents the GAMS path to a specific file.
Definition: gamspath.h:35
GAMSPath(const GAMSPath &gpath)
Definition: gamspath.h:59
GAMSPath operator/(const GAMSPath &append)
bool rename(const char *newFileName)
GAMSPath suffix(const std::string &suffix) const
GAMSPath(const char *file)
Definition: gamspath.h:42
void pack()
Normalizes the Path to make it comparable by converting it to it's shortest absolute representation.
GAMSPath tempDir(const std::string &tempPath=std::string())
GAMSPath & operator+=(const std::string &append)
void setSuffix(const char *suffix)
GAMSPath(const std::filesystem::path &file)
Definition: gamspath.h:50
bool exists() const
const char * c_str() const
GAMSPath operator+(const std::string &append)
std::string suffix() const
Path suffix.
GAMSPath(const std::filesystem::path &dir, const std::string &file)
Definition: gamspath.h:55
bool rename(const std::string &newFileName)
GAMSPath path() const
Get the GAMSPath.
GAMSPath()
Standard constructor.
Definition: gamspath.h:38
GAMSPath(const std::string &file)
Definition: gamspath.h:46
static bool exists(const char *file)
GAMSPath & operator<<(const std::string &append)
GAMSPath suffix(const char *suffix) const
bool mkDir() const
Create the directory.
std::string toStdString() const
Get the path or file as std::string.
GAMSPath & operator=(const GAMSPath &other)
GAMSPath tempFile(const std::string &tempName="XXXXXX.tmp")
operator std::string()
Converts a std::string to GAMSPath.
static bool exists(const std::string &file)
bool rmDirRecurse()
GAMSPath up() const
void setSuffix(const std::string &suffix)
Definition: gams.h:91