LCOV - code coverage report
Current view: top level - include/util - file.h (source / functions) Hit Total Coverage
Test: CoherentDB code coverage Lines: 2 2 100.0 %
Date: 2011-02-13 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * (C) Copyright 2010 Marek Dopiera
       3             :  * 
       4             :  * This file is part of CoherentDB.
       5             :  * 
       6             :  * CoherentDB is free software: you can redistribute it and/or modify it
       7             :  * under the terms of the GNU General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  * 
      11             :  * CoherentDB is distributed in the hope that it will be useful, but
      12             :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
      14             :  * General Public License for more details.
      15             :  * 
      16             :  * You should have received a copy of the GNU General Public
      17             :  * License along with CoherentDB. If not, see
      18             :  * http://www.gnu.org/licenses/.
      19             :  */
      20             : 
      21             : #ifndef FILE_22941
      22             : #define FILE_22941
      23             : 
      24             : #include <memory>
      25             : #include <string>
      26             : 
      27             : #include <boost/noncopyable.hpp>
      28             : 
      29             : #include <util/multi_buffer.h>
      30             : 
      31             : namespace coherent {
      32             : namespace util {
      33             : 
      34             : class file;
      35             : 
      36             : class io_exception
      37           1 : {
      38             : public:
      39             :         io_exception(file const & file, std::string const & msg);
      40             :         io_exception(file const & file, int err, std::string const & op);
      41             : 
      42             :         virtual const char* what() const throw();
      43             : 
      44             :         virtual ~io_exception();
      45             : private:
      46             :         std::string message;
      47             : };
      48             : 
      49             : class file : private boost::noncopyable
      50             : {
      51             : public:
      52             :         typedef std::auto_ptr<multi_buffer> multi_buffer_ptr;
      53             : 
      54             :         file(std::string const & path);
      55             : 
      56             :         //O_CREAT and O_EXCL should not be passed
      57             :         static std::auto_ptr<file> create(
      58             :                 std::string const & path,
      59             :                 int flags,
      60             :                 int mode
      61             :                 );
      62             :         static std::auto_ptr<file> open(
      63             :                 std::string const & path,
      64             :                 int flags
      65             :                 );
      66             :         ~file();
      67             : 
      68             :         void create(int flags, int mode);
      69             :         void open(int flags);
      70             :         void close();
      71             : 
      72             :         multi_buffer_ptr read(uint32_t size, uint64_t offset);
      73             :         void write(multi_buffer const & buf, uint64_t offset);
      74             : 
      75             :         inline bool is_open() const;
      76             : 
      77             : private:
      78             :         friend class io_exception;
      79             : 
      80             :         enum {
      81             :                 NOT_OPEN = -1
      82             :         };
      83             : 
      84             :         void open_internal(int flags, bool create, int mode = 0);
      85             : 
      86             :         std::string path;
      87             :         int fd;
      88             : 
      89             : };
      90             : 
      91             : //======== inline implementation ===============================================
      92             : 
      93        1028 : bool file::is_open() const { return this->fd != NOT_OPEN; }
      94             : 
      95             : } // namespace util
      96             : } // namespace coherent
      97             : 
      98             : #endif /* FILE_22941 */

Generated by: LCOV version 1.9