# PhasicFlow: src/phasicFlow/fileSystem/fileSystem.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

fileSystem.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __fileSystem_hpp__
#define __fileSystem_hpp__
#include <filesystem>
#include "bTypes.hpp"
#include "List.hpp"
namespace pFlow
{
// - Forward
class iOstream;
class fileSystem;
iOstream& operator <<
(
iOstream& os,
const fileSystem& fs
);
std::ostream& operator <<
(
std::ostream& os,
const fileSystem& fs
);
fileSystem operator /
(
const fileSystem& fs1,
const fileSystem& fs2
);
fileSystem operator /
(
const fileSystem& fs1,
const word& dir2
);
fileSystem operator +
(
const fileSystem& fs1,
const word fName
);
class fileSystem
{
public:
using pathType = std::filesystem::path;
protected:
pathType path_;
bool isDir_;
inline static word notPermittedCharsFile = word(" ") + word("&\t\n;:?*/<>\"?\'");
bool static validFileName(const word& name)
{
return name.find_first_of(notPermittedCharsFile)==word::npos;
}
bool static checkFileName(const word& name);
public:
inline static fileSystem CWD()
{
return fileSystem(std::filesystem::current_path().c_str());
}
public:
fileSystem():
path_(),
isDir_(true)
{}
explicit
fileSystem(const word & wPath);
fileSystem( const word& dir, const word& file);
fileSystem( const char* dir, const char* file="");
explicit
fileSystem( const pathType& path );
fileSystem(const fileSystem&) = default;
fileSystem(fileSystem&&) = default;
fileSystem& operator = (const fileSystem&) = default;
fileSystem& operator = (fileSystem&&) = default;
~fileSystem() = default;
bool isDir() const
{
return isDir_;
}
const pathType& path()const
{
return path_;
}
word wordPath()const
{
return word(path_.c_str());
}
fileSystem dirPath() const;
word fileName() const;
fileSystem absolute()const;
fileSystem canonical()const;
fileSystem relative(const fileSystem& base)const;
bool dirExist()const;
bool exist()const;
fileSystem createDirs()const;
void operator += (const word& fileName);
void operator /=(const fileSystem& fs );
friend fileSystem operator /(const fileSystem& fs1, const fileSystem& fs2 );
fileSystem operator()(bool retDir = true) const;
friend iOstream& operator << (iOstream& os, const fileSystem& fs);
friend std::ostream& operator << (std::ostream& os, const fileSystem& fs);
};
using fileSystemList = List<fileSystem>;
inline fileSystem CWD()
{
return fileSystem::CWD();
}
bool isDirectory(const fileSystem& path);
bool isRegularFile(const fileSystem& path);
fileSystemList subDirectories(const fileSystem& path);
fileSystemList containingFiles(const fileSystem& path);
} // pFlow
#endif
pFlow::List
Definition: List.hpp:39
pFlow::fileSystem::canonical
fileSystem canonical() const
Canonical path of this (it should exist)
Definition: fileSystem.cpp:149
pFlow::fileSystem::operator/
friend fileSystem operator/(const fileSystem &fs1, const fileSystem &fs2)
Create a dir path from dir path of fs1 and fas2 in the form of fs1/fs2
pFlow::fileSystem::fileName
word fileName() const
File name part of the path (if any)
Definition: fileSystem.cpp:105
pFlow::fileSystem::fileSystem
fileSystem()
Default.
Definition: fileSystem.hpp:111
pFlow::fileSystem::dirExist
bool dirExist() const
Only operate on dir path Check if the dir path exists.
Definition: fileSystem.cpp:176
pFlow::fileSystem::CWD
static fileSystem CWD()
return current working directory
Definition: fileSystem.hpp:101
pFlow::fileSystem::exist
bool exist() const
Check if the path exists.
Definition: fileSystem.cpp:192
pFlow::fileSystem::operator/=
void operator/=(const fileSystem &fs)
It operates on dir path only Add the dir path of fs to this
Definition: fileSystem.cpp:265
pFlow::fileSystem::operator+=
void operator+=(const word &fileName)
If this is dir path, add the filename to dir path if it is file path, replace the file name
Definition: fileSystem.cpp:245
pFlow::fileSystem::operator()
fileSystem operator()(bool retDir=true) const
Return the dir path of this.
Definition: fileSystem.cpp:235
List.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::containingFiles
fileSystemList containingFiles(const fileSystem &path)
A list of file paths that exist in the path.
Definition: fileSystem.cpp:359
pFlow::fileSystem::isDir_
bool isDir_
Is this a directory path?
Definition: fileSystem.hpp:83
pFlow::fileSystem::operator=
fileSystem & operator=(const fileSystem &)=default
Copy assignment.
pFlow::fileSystem::isDir
bool isDir() const
Is directory?
Definition: fileSystem.hpp:148
bTypes.hpp
pFlow
Definition: demGeometry.hpp:27
pFlow::isRegularFile
bool isRegularFile(const fileSystem &path)
free function to check if the path is regular file
Definition: fileSystem.cpp:331
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::subDirectories
fileSystemList subDirectories(const fileSystem &path)
A list of sub-directories that exist in path.
Definition: fileSystem.cpp:337
pFlow::fileSystem::path_
pathType path_
File path.
Definition: fileSystem.hpp:80
pFlow::fileSystem::notPermittedCharsFile
static word notPermittedCharsFile
Not premitted chars in file name
Definition: fileSystem.hpp:87
pFlow::fileSystem::path
const pathType & path() const
Const access to path.
Definition: fileSystem.hpp:154
pFlow::fileSystem::dirPath
fileSystem dirPath() const
Dir part of the path.
Definition: fileSystem.cpp:91
pFlow::fileSystem::operator<<
friend iOstream & operator<<(iOstream &os, const fileSystem &fs)
pFlow::isDirectory
bool isDirectory(const fileSystem &path)
Free function to check if the path is dir path.
Definition: fileSystem.cpp:324
pFlow::fileSystem::absolute
fileSystem absolute() const
Absolute path of this.
Definition: fileSystem.cpp:125
pFlow::fileSystem::validFileName
static bool validFileName(const word &name)
Is name is valid for a file?
Definition: fileSystem.hpp:90
pFlow::fileSystem::checkFileName
static bool checkFileName(const word &name)
Is a valid file name?
Definition: fileSystem.cpp:27
pFlow::fileSystemList
List< fileSystem > fileSystemList
Definition: fileSystem.hpp:217
pFlow::CWD
fileSystem CWD()
Free function to reture current working directory.
Definition: fileSystem.hpp:221
pFlow::fileSystem::~fileSystem
~fileSystem()=default
Destructor.
pFlow::fileSystem::relative
fileSystem relative(const fileSystem &base) const
relative path of this this with respect to base
Definition: fileSystem.cpp:170
pFlow::fileSystem::wordPath
word wordPath() const
Path in word type.
Definition: fileSystem.hpp:160
pFlow::fileSystem::pathType
std::filesystem::path pathType
Definition: fileSystem.hpp:75
pFlow::fileSystem::createDirs
fileSystem createDirs() const
Operate on dir path only Create dir based on the path and returns the canonical path.
Definition: fileSystem.cpp:208
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59