String: don't split at quoted sep-chars
[platform/upstream/libzypp.git] / zypp / base / Fd.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/base/Fd.h
10  *
11 */
12 #ifndef ZYPP_BASE_FD_H
13 #define ZYPP_BASE_FD_H
14
15 #include "zypp/Pathname.h"
16
17 ///////////////////////////////////////////////////////////////////
18 namespace zypp
19 { /////////////////////////////////////////////////////////////////
20   ///////////////////////////////////////////////////////////////////
21   namespace base
22   { /////////////////////////////////////////////////////////////////
23
24     ///////////////////////////////////////////////////////////////////
25     //
26     //  CLASS NAME : Fd
27     //
28     /** Assert \c close called on open filedescriptor.
29      * \code
30      * ...
31      * scoped_ptr<Fd> fd; // calls close when going out of scope
32      * try {
33      *   fd.reset( new Fd( "/some/file" ) );
34      * } catch ( ... ) {
35      *   // open failed.
36      * }
37      * read( fd->fd(), ... ),
38      * \endcode
39      *
40      * \ingroup g_RAII
41      * \todo It's dumb. Openflags and more related functions (read/write..)
42      * could be added.
43     */
44     class Fd
45     {
46     public:
47       /** Ctor opens file.
48        * \throw EXCEPTION If open fails.
49       */
50       Fd( const Pathname & file_r, int open_flags, mode_t mode = 0 );
51
52       /** Dtor closes file. */
53       ~Fd()
54       { close(); }
55
56       /** Explicitly close the file. */
57       void close();
58
59       /** Test for valid filedescriptor. */
60       bool isOpen() const
61       { return m_fd != -1; }
62
63       /** Return the filedescriptor. */
64       int fd() const
65       { return m_fd; }
66
67     private:
68       /** The filedescriptor. */
69       int m_fd;
70       /** No copy. */
71       Fd( const Fd & );
72       /** No assign. */
73       Fd & operator=( const Fd & );
74     };
75     ///////////////////////////////////////////////////////////////////
76
77     /////////////////////////////////////////////////////////////////
78   } // namespace base
79   ///////////////////////////////////////////////////////////////////
80   /////////////////////////////////////////////////////////////////
81 } // namespace zypp
82 ///////////////////////////////////////////////////////////////////
83 #endif // ZYPP_BASE_FD_H