source: trunk/yat/utility/FileIO.h @ 709

Last change on this file since 709 was 709, checked in by Jari Häkkinen, 16 years ago

Addresses #1 and #80. Issues fixed, but bogus params to functions exists. cleanup needed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1#ifndef _theplu_yat_utility_fileio_
2#define _theplu_yat_utility_fileio_
3
4// $Id: FileIO.h 709 2006-12-20 21:49:02Z jari $
5
6/*
7  Copyright (C) 2004 Jari Häkkinen
8  Copyright (C) 2005 Peter Johansson
9  Copyright (C) 2006 Jari Häkkinen
10
11  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 2 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "Exception.h"
30
31#include <string>
32#include <sys/stat.h>
33#include <unistd.h>
34
35namespace theplu {
36namespace yat {
37namespace utility {
38
39  ///
40  /// FileIO is useful for many common task on files.
41  ///
42  class FileIO {
43  public:
44
45    ///
46    /// \brief Constructor
47    ///
48    /// \exception IO_error if underlying stat(2) call fails in other
49    /// ways than file does not exist.
50    ///
51    explicit FileIO(const std::string& path);
52
53    ///
54    /// @brief Check file/directory permissions
55    ///
56    /// Check if access permissions match \a mode. \a mode must be
57    /// given as r, w, x, or combinations of these letters.
58    ///
59    /// @note Checking permissions on a non-existent file will return
60    /// the permissions for the parent directory, but only the parent
61    /// directory. If the parent directory does not exist then fail is
62    /// returned.
63    ///
64    /// @return On success (all requested permissions granted), zero
65    /// is returned. On error (at least one bit in mode asked for a
66    /// permission that is denied, or some other error occurred), -1
67    /// is returned, and errno is set appropriately.
68    ///
69    int access_rights(const std::string& path,const std::string& bits) const;
70
71    ///
72    /// @brief Check whether \a file exists.
73    ///
74    /// @return True if \a file exists, false otherwise.
75    ///
76    bool file_exists(const std::string& file) const;
77
78    ///
79    /// @brief Get path associated with the object.
80    ///
81    const std::string& path(void) const;
82
83  private:
84    ///
85    /// \brief The copy constructor, not implemented
86    ///
87    FileIO(const FileIO&);
88
89    bool no_file_;
90    std::string path_;
91    struct stat stat_;
92  };
93
94}}} // of namespace utility, yat, and theplu
95
96#endif
Note: See TracBrowser for help on using the repository browser.