NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
filesystem.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2014 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19
20#include <string>
21#include <vector>
22
23//#include "error.hpp"
24
25#ifndef FILESYSTEM_HPP
26#define FILESYSTEM_HPP
27
28std::string toSystemCodePage(std::string);
29std::string fromSystemCodePage(std::string);
30
31/*
32 * Headerdatei zur FileSystem Klasse
33 * -> FileSystem dient als PARENT fuer Output und Datafile, da die Methode FileSystem::ValidFileName(string) in beiden Klassen benutzt wird
34 */
35
41{
42 std::string drive;
43 std::string path;
44 std::string name;
45 std::string ext;
46 size_t filesize;
50
52 {
64 ATTR_OFFLINE = 0x1000,
68 ATTR_VIRTUAL = 0x10000,
71 ATTR_PINNED = 0x80000,
72 ATTR_UNPINNED = 0x100000,
74 };
75
77 {
78 filesize = 0;
80 creationTime = 0.0;
81 modificationTime = 0.0;
82 }
83};
84
92{
93 private:
94 std::string cleanPath(std::string sFilePath, bool checkInvalidChars) const;
95 void resolveWildCards(std::string& _sFileName, bool isFile, bool checkExtension = true) const;
96
97 protected:
98 std::string sPath;
99 std::string sExecutablePath;
100 std::string sTokens[7][2];
101 mutable std::string sValidExtensions;
102
103 int createFolders(const std::string& _sPath) const;
104
105 public:
106 FileSystem();
107
108 FileSystem& assign(const FileSystem& _fSys);
109
110 std::string ValidFileName(std::string _sFileName, const std::string sExtension = ".dat", bool checkExtension = true, bool doCleanPath = true) const;
111 std::string ValidFolderName(std::string _sFileName, bool doCleanPath = true, bool appendTrailingSeparator = true) const;
112 std::string ValidizeAndPrepareName(const std::string& _sFileName, const std::string& sExtension = ".dat") const;
113 int setPath(std::string _sPath, bool bMkDir, std::string _sExePath);
115 std::string getPath() const;
116 std::vector<std::string> getFileParts(const std::string& sFilePath) const;
117 FileInfo getFileInfo(const std::string& sFilePath) const;
118 void setTokens(std::string _sTokens);
119 bool isFile(const std::string& _sPath) const;
121
122 inline void setProgramPath(std::string _sExePath)
123 {
124 sExecutablePath = _sExePath;
125 }
126
127 inline std::string getProgramPath() const
128 {
129 return sExecutablePath;
130 }
131
132 inline void declareFileType(const std::string& sFileType)
133 {
134 if (sValidExtensions.find(sFileType) == std::string::npos)
135 {
136 if (sFileType[0] == '.')
137 sValidExtensions += sFileType + ";";
138 else
139 sValidExtensions += "." + sFileType + ";";
140 }
141 }
142};
143
144#endif
145
This class implements the basic input/ output file system and provides functionalities to work with f...
Definition: filesystem.hpp:92
void setProgramPath(std::string _sExePath)
Definition: filesystem.hpp:122
std::string getProgramPath() const
Definition: filesystem.hpp:127
std::string sPath
Definition: filesystem.hpp:98
std::string ValidFolderName(std::string _sFileName, bool doCleanPath=true, bool appendTrailingSeparator=true) const
This member function evaluates, whether the passed foldername is a valid foldername.
Definition: filesystem.cpp:369
std::string ValidizeAndPrepareName(const std::string &_sFileName, const std::string &sExtension=".dat") const
This member function validizes the passed file name and creates the needed folders on-the-fly.
Definition: filesystem.cpp:424
std::string cleanPath(std::string sFilePath, bool checkInvalidChars) const
This function cleans the passed file path, i.e. replaces the character encoding of umlauts,...
Definition: filesystem.cpp:82
std::string sExecutablePath
Definition: filesystem.hpp:99
FileSystem & assign(const FileSystem &_fSys)
Assignment member function to copy the settings from another FileSystem instance.
Definition: filesystem.cpp:56
std::vector< std::string > getFileParts(const std::string &sFilePath) const
This member function separates all path parts into single strings: the drive letter,...
Definition: filesystem.cpp:566
void initializeFromKernel()
Member function to remote-initialize the class from the kernel. Cannot be used during kernel start-up...
Definition: filesystem.cpp:750
FileInfo getFileInfo(const std::string &sFilePath) const
Return the file information about the passed file path.
Definition: filesystem.cpp:642
std::string getPath() const
Returns the default path of this FileSystem instance.
Definition: filesystem.cpp:547
void resolveWildCards(std::string &_sFileName, bool isFile, bool checkExtension=true) const
This member function resolves all wildcards, which may be found in the passed filename.
Definition: filesystem.cpp:159
std::string ValidFileName(std::string _sFileName, const std::string sExtension=".dat", bool checkExtension=true, bool doCleanPath=true) const
This member function evaluates, whether the passed filename is a valid filename. One may supply a pre...
Definition: filesystem.cpp:280
FileSystem()
Default constructor.
Definition: filesystem.cpp:34
void setTokens(std::string _sTokens)
This member function may be used to update the path placeholders of the current FileSystem instance.
Definition: filesystem.cpp:694
void createRevisionsFolder()
This member function creates the hidden revisions folders for the version control system.
Definition: filesystem.cpp:532
void declareFileType(const std::string &sFileType)
Definition: filesystem.hpp:132
std::string sTokens[7][2]
Definition: filesystem.hpp:100
std::string sValidExtensions
Definition: filesystem.hpp:101
bool isFile(const std::string &_sPath) const
This function determines, whether a path name indicates a file or a folder.
Definition: filesystem.cpp:716
int createFolders(const std::string &_sPath) const
This member function creates all missing directories in the passed path.
Definition: filesystem.cpp:234
int setPath(std::string _sPath, bool bMkDir, std::string _sExePath)
This member function may be used to set the preferred file path of the current FileSystem instance.
Definition: filesystem.cpp:443
static bool checkInvalidChars(std::string sPathname)
This function checks for the invalid chars that can not appear in a valid directory name.
Definition: filecheck.cpp:14
std::string fromSystemCodePage(std::string)
Transforms the system code page to the internal one.
std::string toSystemCodePage(std::string)
Converts an internal to an external string. Does nothing currently.
This structure contains all relevant information about a file path.
Definition: filesystem.hpp:41
std::string path
Definition: filesystem.hpp:43
size_t filesize
Definition: filesystem.hpp:46
double creationTime
Definition: filesystem.hpp:48
double modificationTime
Definition: filesystem.hpp:49
@ ATTR_RECALL_ON_DATA_ACCESS
Definition: filesystem.hpp:73
@ ATTR_NO_SCRUB_DATA
Definition: filesystem.hpp:69
@ ATTR_SPARSE_FILE
Definition: filesystem.hpp:61
@ ATTR_ENCRYPTED
Definition: filesystem.hpp:66
@ ATTR_COMPRESSED
Definition: filesystem.hpp:63
@ ATTR_REPARSE_POINT
Definition: filesystem.hpp:62
@ ATTR_RECALL_ON_OPEN
Definition: filesystem.hpp:70
@ ATTR_OFFLINE
Definition: filesystem.hpp:64
@ ATTR_UNPINNED
Definition: filesystem.hpp:72
@ ATTR_READONLY
Definition: filesystem.hpp:53
@ ATTR_INTEGRITY_STREAM
Definition: filesystem.hpp:67
@ ATTR_VIRTUAL
Definition: filesystem.hpp:68
@ ATTR_DIRECTORY
Definition: filesystem.hpp:56
@ ATTR_TEMPORARY
Definition: filesystem.hpp:60
@ ATTR_ARCHIVE
Definition: filesystem.hpp:57
@ ATTR_NOT_CONTENT_INDEXED
Definition: filesystem.hpp:65
std::string drive
Definition: filesystem.hpp:42
size_t fileAttributes
Definition: filesystem.hpp:47
std::string ext
Definition: filesystem.hpp:45
std::string name
Definition: filesystem.hpp:44