Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/util/filesys/file.h @ 8332

Last change on this file since 8332 was 8332, checked in by bensch, 18 years ago

trunk: some more functionality

File size: 1.9 KB
Line 
1/*!
2 * @file file.h
3 * @brief Definition of File Handler class
4 */
5
6#ifndef __FILE_H_
7#define __FILE_H_
8
9
10#include <string>
11typedef struct stat;
12
13//! A Class to Handle Files.
14class File
15{
16  public:
17  //! How the File should be opened.
18  typedef enum
19  {
20    ReadOnly,      //!< ReadOnly mode
21    WriteOnly,     //!< WriteOnly mode
22    ReadWrite,     //!< Read and Write mode together
23    Append,        //!< Append at the end.
24  } OpenMode;
25
26public:
27  File();
28  File(const std::string& fileName);
29  File(const File& file);
30  virtual ~File();
31
32  /// Set-Up
33  void setFileName(const std::string& fileName);
34  File& operator=(const std::string& fileName);
35  File& operator=(const File& file);
36
37  /// Comparison
38  bool operator==(const std::string& fileName) const;
39  bool operator==(const File& file) const;
40
41  virtual bool open(OpenMode mode);
42  virtual bool close();
43  int handle() const { return this->_handle; };
44
45  /** @returns the FileName of this File */
46  const std::string& name() const { return this->_name; };
47
48  /// Testing
49  bool exists() const;
50  bool isLink() const;
51  bool isFile() const;
52  bool isDirectory() const;
53  bool isReadeable() const;
54  bool isWriteable() const;
55  bool isExecutable() const;
56
57
58  /// Operate on the FileSystem
59  bool copy(const File& destination);
60  bool rename(const File& destination);
61  bool touch();
62  bool remove();
63
64  /// Transformations
65  static void relToAbs(std::string& relFileName);
66  static void absToRel(std::string& absFileName);
67  static const std::string& cwd();
68
69  private:
70    void init();
71    void statFile();
72    void homeDirCheck(std::string& fileName);
73
74  private:
75    int                 _handle;          //!< The FileHandle (if set).
76    std::string         _name;            //!< The Name of the File.
77    stat*               _status;          //!< The Stat of the File.
78
79    static std::string  _cwd;             //!< The currend Working directory.
80
81};
82
83#endif /* __FILE_H_ */
Note: See TracBrowser for help on using the repository browser.