FileUtils.h
1 /**************************************************************************************
2 Copyright 2015 Applied Research Associates, Inc.
3 Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4 this file except in compliance with the License. You may obtain a copy of the License
5 at:
6 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software distributed under
8 the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
9 CONDITIONS OF ANY KIND, either express or implied. See the License for the
10 specific language governing permissions and limitations under the License.
11 **************************************************************************************/
12 
13 #pragma once
14 
15 #include <biogears/cdm/CommonDataModel.h>
16 
17 #include <mutex>
18 #include <string>
19 #include <vector>
20 
21 #if defined(_MSC_VER) || defined(__MINGW64_VERSION_MAJOR)
22 
23 #include <windows.h>
24 
25 #else
26 
27 #include <unistd.h>
28 
29 #if defined(__clang__) && !defined(ANDROID)
30 #include <sys/syslimits.h>
31 #endif
32 
33 #if defined(__gnu_linux__)
34 #include <cstring>
35 #endif
36 
37 #endif
38 
39 struct dirent;
40 
41 namespace biogears {
42 BIOGEARS_API bool CreateFilePath(const std::string&);
43 BIOGEARS_API bool CreateFilePath(const char*);
44 BIOGEARS_API std::string Replace(const std::string& original, const std::string& replace, const std::string& withThis);
45 BIOGEARS_API void ListFiles(const std::string& dir, std::vector<std::string>& files, const std::string& mask = "", bool recurse = true);
46 BIOGEARS_API std::vector<std::string> ListFiles(const std::string& dir, const std::string& regex, bool recurse = true);
47 
48 BIOGEARS_API bool IsAbsolutePath(const std::string& path);
49 BIOGEARS_API bool IsAbsolutePath(const char* path);
50 BIOGEARS_API std::string ResolvePath(const std::string& path);
51 BIOGEARS_API const char* ResolvePath_cStr(const char* path);
52 BIOGEARS_API void SetCurrentWorkingDirectory(std::string working_dir);
53 BIOGEARS_API void SetCurrentWorkingDirectory(const char* working_dir);
54 BIOGEARS_API bool TestLastDirName(std::string path, std::string dirname);
55 BIOGEARS_API bool TestFirstDirName(std::string path, std::string dirname);
56 BIOGEARS_API bool TestLastDirName(const char* path, const char* dirname);
57 BIOGEARS_API bool TestFirstDirName(const char* path, const char* dirname);
58 
59 BIOGEARS_API std::string GetCurrentWorkingDirectory();
60 BIOGEARS_API const char* GetCurrentWorkingDirectory_cStr();
61 
62 BIOGEARS_API void DeleteDirectory(const std::string& dir, bool bDeleteSubdirectories = true);
63 BIOGEARS_API void MakeDirectory(const std::string& dir);
64 
65 BIOGEARS_API extern std::recursive_mutex g_fileSystemMutex;
66 
67 class BIOGEARS_API ScopedFileSystemLock {
68 public:
71 
72  ScopedFileSystemLock(const ScopedFileSystemLock& other) = delete;
73  ScopedFileSystemLock& operator=(const ScopedFileSystemLock& other) = delete;
74 
76  ScopedFileSystemLock& operator=(ScopedFileSystemLock&& other) = delete;
77 };
78 
79 bool BIOGEARS_API IsDirectory(dirent* ent);
80 }
BIOGEARS_API std::string Replace(const std::string &original, const std::string &replace, const std::string &withThis)
Definition: FileUtils.cpp:40
BIOGEARS_API void SetCurrentWorkingDirectory(std::string working_dir)
Definition: FileUtils.cpp:202
bool BIOGEARS_API IsDirectory(dirent *ent)
BIOGEARS_API const char * ResolvePath_cStr(const char *path)
This call is very unsafe when using threading. The lifetime of the char* returned is until the next c...
Definition: FileUtils.cpp:158
Definition: FileUtils.h:67
BIOGEARS_API bool TestFirstDirName(std::string path, std::string dirname)
Definition: FileUtils.cpp:220
BIOGEARS_API std::string GetCurrentWorkingDirectory()
Definition: FileUtils.cpp:244
BIOGEARS_API const char * GetCurrentWorkingDirectory_cStr()
Definition: FileUtils.cpp:249
BIOGEARS_API bool IsAbsolutePath(const std::string &path)
Definition: FileUtils.cpp:124
BIOGEARS_API bool CreateFilePath(const std::string &)
Definition: FileUtils.cpp:52
BIOGEARS_API void MakeDirectory(const std::string &dir)
Definition: FileUtils.cpp:172
BIOGEARS_API std::string ResolvePath(const std::string &path)
Definition: FileUtils.cpp:134
BIOGEARS_API void ListFiles(const std::string &dir, std::vector< std::string > &files, const std::string &mask="", bool recurse=true)
Definition: FileUtils.cpp:96
BIOGEARS_API std::recursive_mutex g_fileSystemMutex
Definition: FileUtils.cpp:254
Definition: SEElectricalCircuit.h:18
BIOGEARS_API void DeleteDirectory(const std::string &dir, bool bDeleteSubdirectories=true)
Definition: FileUtils.cpp:177
BIOGEARS_API bool TestLastDirName(std::string path, std::string dirname)
Definition: FileUtils.cpp:212