PhoenixPresentation  2.0.0
Set of cmake function to automate presentation generation
PPath.h
Go to the documentation of this file.
1 /***************************************
2  Auteur : Pierre Aubert
3  Mail : pierre.aubert@lapp.in2p3.fr
4  Licence : CeCILL-C
5 ****************************************/
6 
7 #ifndef __PPATH_H__
8 #define __PPATH_H__
9 
10 #include <sys/stat.h>
11 #include <sys/types.h>
12 #include "PString.h"
13 
14 class PPath;
15 
17 class PPath : public PString{
18  public:
19  PPath();
20  PPath(const PString & other);
21  PPath(const PPath & other);
22  virtual ~PPath();
23  PPath & operator = (const PPath & other);
24  friend PPath operator / (const PPath & other1, const PPath & other2);
25 
26  bool isExist() const;
27  bool isFileExist() const;
28  bool isDirectoryExist() const;
29  bool isAbsolutePath() const;
30 
31  PPath getFileName() const;
32  PPath getDirectoryName() const;
33  PPath getParentDirectory() const;
34  PPath getParentDirectory(const PPath & subDirName) const;
35 
36  PString getExtension() const;
38 
41  PPath eraseExtension() const;
43 
44  bool createDirectory(mode_t mode = 0755) const;
45  PPath getUnderPath(const PString & pathPart) const;
46 
47  PString loadFileContent() const;
48  bool saveFileContent(const PString & content) const;
49  size_t getFileSize() const;
50  bool checkFileBegning(const PString & expectedBegining) const;
51  time_t getFileModificationTime() const;
52 
53  std::vector<PPath> getAllFileInDir() const;
54  std::vector<PPath> getAllDirectoryInDir() const;
55  std::vector<PPath> getAllElementInDir() const;
56 
57 
58  bool changeMode(mode_t __mode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) const;
59  PPath simplify() const;
60  PPath makeAbsolute() const;
61 
62  static PPath getProgramLocation();
63  static PPath getProgramDirectory();
64  static PPath getProgramPrefix();
65  static PPath getHomeDir();
66  static PPath getCurrentDirectory();
67  static PString getCurrentNodeName();
68  protected:
69  void copyPPath(const PPath & other);
70 
71  private:
72  void initialisationPPath();
73 };
74 
75 typedef std::vector<PPath> PVecPath;
76 
78 
79 #endif
80 
std::vector< PPath > PVecPath
Definition: PPath.h:75
PString phoenix_getFileContent(FILE *fp)
Get the content of a file.
Definition: PPath.cpp:28
Path of a directory or a file.
Definition: PPath.h:17
bool changeMode(mode_t __mode=S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) const
Change the mode of a file or directory.
Definition: PPath.cpp:526
bool checkFileBegning(const PString &expectedBegining) const
Check if the given file starts with the given begning.
Definition: PPath.cpp:421
PPath & eraseLongestExtension()
Erase the longest extension of the PPath.
Definition: PPath.cpp:303
std::vector< PPath > getAllDirectoryInDir() const
Get the list of files in a directory.
Definition: PPath.cpp:479
bool saveFileContent(const PString &content) const
Save a PString in a file.
Definition: PPath.cpp:395
PPath & eraseExtension()
Erase the extension of the PPath.
Definition: PPath.cpp:292
bool createDirectory(mode_t mode=0755) const
Create the current directory.
Definition: PPath.cpp:331
PPath getUnderPath(const PString &pathPart) const
Get path which is under the given pathPart ('some/dir/path' with 'dir' will return 'path')
Definition: PPath.cpp:360
static PPath getCurrentDirectory()
Returns the current directory.
Definition: PPath.cpp:636
static PString getCurrentNodeName()
Get the name of the current node on which the program is running.
Definition: PPath.cpp:650
PPath makeAbsolute() const
Make an absolute path of the given path.
Definition: PPath.cpp:572
PString getExtension() const
Get file extension.
Definition: PPath.cpp:252
friend PPath operator/(const PPath &other1, const PPath &other2)
Operator / for PPath to concatenate PPath.
Definition: PPath.cpp:119
PPath getParentDirectory() const
Get path of parent directory of current path.
Definition: PPath.cpp:207
PPath getDirectoryName() const
Get the name of the directory, from last char to / (if the last char is not a /, otherwise it takes t...
Definition: PPath.cpp:186
void copyPPath(const PPath &other)
Copy function of PPath.
Definition: PPath.cpp:657
static PPath getHomeDir()
Gets the $HOME directory.
Definition: PPath.cpp:629
size_t getFileSize() const
Get the size of the current file.
Definition: PPath.cpp:407
static PPath getProgramPrefix()
Get the program prefix (installation directory without /bin)
Definition: PPath.cpp:622
bool isDirectoryExist() const
Say if the current directory path does exist.
Definition: PPath.cpp:151
bool isAbsolutePath() const
Tel if a path is absolute or not.
Definition: PPath.cpp:164
time_t getFileModificationTime() const
Get the last modification time of the given file.
Definition: PPath.cpp:441
static PPath getProgramLocation()
Get the program location.
Definition: PPath.cpp:585
PPath simplify() const
Remove extra dots from the path.
Definition: PPath.cpp:533
bool isFileExist() const
Say if the current file path does exist.
Definition: PPath.cpp:139
PString loadFileContent() const
Get the file content in a PString.
Definition: PPath.cpp:382
std::vector< PPath > getAllFileInDir() const
Get the list of files in a directory.
Definition: PPath.cpp:457
PString getLongestExtension() const
Get the longest file extension.
Definition: PPath.cpp:268
virtual ~PPath()
Destructor of PPath.
Definition: PPath.cpp:89
bool isExist() const
Say if the current path does exist.
Definition: PPath.cpp:131
std::vector< PPath > getAllElementInDir() const
Get the list of all elements in a directory.
Definition: PPath.cpp:503
PPath & operator=(const PPath &other)
Definition of equal operator of PPath.
Definition: PPath.cpp:97
PPath getFileName() const
Get the name of the file, from last char to /.
Definition: PPath.cpp:172
static PPath getProgramDirectory()
Get the program directory.
Definition: PPath.cpp:606
void initialisationPPath()
Initialisation function of the class PPath.
Definition: PPath.cpp:662
PPath()
Default constructor of PPath.
Definition: PPath.cpp:64
Extends the std::string.
Definition: PString.h:16