1#define BIORBD_API_EXPORTS
8#include "Utils/Error.h"
9#include "Utils/String.h"
20using namespace BIORBD_NAMESPACE;
78 if (FILE* file = fopen(
93 std::ifstream fichier(
100 bool isOpen(fichier.is_open());
114 INVALID_FILE_ATTRIBUTES) {
126 if (stat(path.c_str(), &statbuf) != -1) {
141 size_t sepPos(pathSep.rfind(
"/"));
144 if (sepPos == std::string::npos)
150 folder = pathSep.substr(0, sepPos) +
"/";
153 if (
folder.find(
"./") == 0) {
158 size_t ext(pathSep.rfind(
"."));
159 if (ext != std::string::npos) {
166 filename = pathSep.substr(sepPos + 1, ext - sepPos - 1);
187 size_t sepMe = std::string::npos;
188 size_t sepCurrentDir = std::string::npos;
191 me = me.substr(sepMe + 1);
195 sepMe = me.find(
"/");
199 meFirstPart = me.substr(0, sepMe);
200 currentDirFirstPart =
currentDir.substr(0, sepCurrentDir);
204 }
while (!meFirstPart.compare(currentDirFirstPart));
213 if (sepCurrentDir != std::string::npos) {
216 currentDirFirstPart =
currentDir.substr(0, sepCurrentDir);
226 if (!outPath.compare(
"") && me.find(
"../") != 0) {
245 if (std::regex_search(current, matches, std::regex(
"^([A-Z]):[\\/].*$"))) {
246 base = matches[1].str() +
":/";
249 "I could not find the current drive to estimate the path");
282 size_t pos(pathOut.rfind(
"\\\\"));
283 while (pos != std::string::npos) {
284 pathOut.replace(pos, 2,
"/");
285 pos = pathOut.rfind(
"\\\\");
290 pos = pathOut.rfind(
"\\");
291 while (pos != std::string::npos) {
292 pathOut.replace(pos, 1,
"/");
293 pos = pathOut.rfind(
"\\");
300 size_t pos(pathOut.rfind(
"/"));
301 while (pos != std::string::npos) {
302 pathOut.replace(pos, 1,
"\\\\");
303 pos = pathOut.rfind(
"/");
333 if (std::regex_search(current, matches, std::regex(
"^([A-Z]):[\\/].*$"))) {
340 size_t pos(
m_folder->find(base.c_str()));
350 char buff[FILENAME_MAX];
353 _getcwd(buff, FILENAME_MAX),
"Could not find the current directory");
356 getcwd(buff, FILENAME_MAX),
"Could not find the current directory");
365 size_t sep = std::string::npos;
369 tp2 = tp2.substr(sep + 1);
373 if (sep != std::string::npos) {
381 mkdir(tp.substr(0, sepTrack).c_str(), 0777);
385 }
while (sep != std::string::npos);
static void raise(const String &message)
Throw an error message.
static void check(bool cond, const String &message)
Assert that raises the error message if false.
Collection of methods to manipulate path.
void setFolder(const String &folder)
Set the folder of the file.
void setIsFolderAbsolute()
Set if folder is absolute.
void createFolder() const
To create folder on the computer.
const String & originalPath() const
Return original path as it was at constructor time.
String absolutePath() const
Return the absolute path relative to root.
bool isFileReadable() const
Test if file exist on the computer and is accessible.
std::shared_ptr< String > m_folder
The folder.
bool isFileExist() const
Test if file exist on the computer.
const String & filename() const
Return the filename.
bool isFolderExist() const
Test if folder exists on the computer.
static String currentDir()
String relativePath() const
Return relative path to current working directory.
static void parseFileName(const String &path, String &folder, String &filename, String &extension)
Parse a path in folder, filename and extension.
static String toUnixFormat(const String &path)
Return the path to Unix format.
std::shared_ptr< String > m_originalPath
The original path at construction time.
std::shared_ptr< bool > m_isFolderAbsolute
If folder is absolute.
static String absoluteFolder(const Path &path)
Return the absolute path relative to root.
const String & folder() const
Return the folder of the file.
std::shared_ptr< String > m_filename
The filename.
void setExtension(const String &ext)
Set the extension.
const String & extension() const
Return the extension of the file.
std::shared_ptr< String > m_extension
The extension.
String absoluteFolder() const
Return the absolute folder relative to root.
static String toWindowsFormat(const String &path)
Return the path to Windows format.
void setFilename(const String &name)
Set the filename.
Path DeepCopy() const
Deep copy of path.
Wrapper around the std::string class with augmented functionality.