added some more methods to FileSTat class
[libasyncio] / utils / asyncio_system_tools.hpp
CommitLineData
8c15b8c7
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
ef51ea7e
RP
20/**
21 * @file
22 * @brief some functions to wrap some system functions
23 *
24 * @author Reinhard Pfau \<Reinhard.Pfau@gmx.de\>
25 * @copyright &copy; Copyright 2009 by Intra2net AG
ef51ea7e
RP
26 */
27
28
29#ifndef _ASYNCIO_SYSTEM_TOOLS_HPP_
30#define _ASYNCIO_SYSTEM_TOOLS_HPP_
31
32#include <string>
33
34
35namespace AsyncIo
36{
37namespace Utils
38{
39
9b21df9d
RP
40/**
41 * @brief removed a file entry from file system (if existing).
42 * @param path path to be removed.
43 * @return @a true if the file was successfully deleted.
44 */
85108f09
RP
45bool unlink( const std::string& path );
46
47
9b21df9d
RP
48/**
49 * @brief represents a file(/path) status.
50 *
51 * This is basically a wrapper around the "stat" call.
52 */
85108f09
RP
53class FileStat
54{
55 public:
9b21df9d 56 FileStat( const std::string& path, bool follow_symlinks= true );
85108f09
RP
57 ~FileStat();
58
9b21df9d
RP
59 /**
60 * @brief stat the path again and updates the values.
61 */
85108f09
RP
62 void refresh();
63
9b21df9d
RP
64 /**
65 * @brief returns if the stat values are valid.
66 * @return @a true if the stat values are valid.
67 */
85108f09
RP
68 bool is_valid() const { return m_is_valid; }
69
70 operator bool() const { return m_is_valid; }
71
72 bool is_regular_file() const { return m_is_regular_file; }
73 bool is_directory() const { return m_is_directory; }
9b21df9d
RP
74 bool is_character_device() const { return m_is_character_device; }
75 bool is_block_device() const { return m_is_block_device; }
76 bool is_fifo() const { return m_is_fifo; }
77 bool is_symbolic_link() const { return m_is_symbolic_link; }
78 bool is_link() const { return m_is_symbolic_link; }
79 bool is_socket() const { return m_is_socket; }
85108f09
RP
80
81 private:
82 std::string m_path;
9b21df9d 83 bool m_follow_symlinks;
85108f09
RP
84
85 bool m_is_valid;
86
87 bool m_is_regular_file;
88 bool m_is_directory;
9b21df9d
RP
89 bool m_is_character_device;
90 bool m_is_block_device;
91 bool m_is_fifo;
92 bool m_is_symbolic_link;
93 bool m_is_socket;
85108f09
RP
94
95}; // end of FileStat
96
ef51ea7e
RP
97
98} // end of namespace Utils
9b21df9d 99} // end of namespace AsyncIo
ef51ea7e
RP
100
101
102#endif