LCOV - code coverage report
Current view: top level - include/util - multi_buffer.h (source / functions) Hit Total Coverage
Test: CoherentDB code coverage Lines: 16 16 100.0 %
Date: 2011-02-13 Functions: 9 9 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 MULTI_BUFFER_H_2363
      22             : #define MULTI_BUFFER_H_2363
      23             : 
      24             : #include <stdint.h>
      25             : 
      26             : #include <vector>
      27             : 
      28             : #include <boost/smart_ptr.hpp>
      29             : #include <boost/utility.hpp>
      30             : 
      31             : namespace coherent {
      32             : namespace util {
      33             : 
      34             : class buffer : private boost::noncopyable
      35             : {
      36             : public:
      37             :         enum
      38             :         {
      39             :                 NO_ALIGNMENT = 0
      40             :         };
      41             : 
      42             :         buffer(uint32_t size, uint32_t alignment = NO_ALIGNMENT);
      43             :         ~buffer();
      44             :         
      45             :         inline char * get_data();
      46             :         inline char const * get_data() const;
      47             :         inline uint32_t get_size() const;
      48             : 
      49             : private:
      50             :         char * data;
      51             :         uint32_t size;
      52             : 
      53             : };
      54             : 
      55             : class file;
      56             : 
      57             : class multi_buffer
      58        1149 : {
      59             : public:
      60             :         typedef boost::shared_ptr<buffer> buffer_ptr;
      61             :         typedef std::vector<buffer_ptr> buffer_list;
      62             : 
      63             :         //invalidates buffers
      64             :         multi_buffer(buffer_list & buffers, uint32_t size, uint32_t left_off);
      65             :         multi_buffer(multi_buffer const & o);
      66             :         inline void read(
      67             :                 char * buf,
      68             :                 uint32_t size,
      69             :                 uint32_t off
      70             :         ) const;
      71             :         inline void write(
      72             :                 char const * buf,
      73             :                 uint32_t size,
      74             :                 uint32_t off,
      75             :                 //what alignment shall frames allocated by COW have
      76             :                 uint32_t align = buffer::NO_ALIGNMENT
      77             :         );
      78             :         inline uint32_t get_size() const;
      79             : 
      80             : private:
      81             :         friend class file;
      82             : 
      83             :         multi_buffer & operator=(multi_buffer const &); //not implemented on purpose
      84             : 
      85             :         template<bool READ>
      86        5248 :         void do_rw(
      87             :                 char * buf,
      88             :                 uint32_t size,
      89             :                 uint32_t off,
      90             :                 uint32_t align = buffer::NO_ALIGNMENT
      91             :         );
      92             : 
      93             :         buffer_list buffers;
      94             :         uint32_t size;
      95             :         uint32_t left_off;
      96             : };
      97             : 
      98             : //================ IMPLEMENTATION ==============================================
      99             : 
     100      693910 : uint32_t buffer::get_size() const
     101             : {
     102      693910 :         return this->size;
     103             : }
     104             : 
     105      249504 : char * buffer::get_data()
     106             : {
     107      249504 :         return this->data;
     108             : }
     109             : 
     110         500 : char const * buffer::get_data() const
     111             : {
     112         500 :         return this->data;
     113             : }
     114             : 
     115             : void multi_buffer::read(
     116        3148 :         char * buf,
     117             :         uint32_t size,
     118             :         uint32_t off
     119             : ) const
     120             : {
     121             :         const_cast<multi_buffer*>(this)->do_rw<true>(buf, size, off);
     122        3148 : }
     123        3148 : 
     124             : void multi_buffer::write(
     125        2100 :         char const * buf,
     126             :         uint32_t size,
     127             :         uint32_t off,
     128             :         uint32_t align
     129             : )
     130             : {
     131             :         this->do_rw<false>(const_cast<char *>(buf), size, off, align);
     132        2100 : }
     133        2100 : 
     134             : uint32_t multi_buffer::get_size() const
     135         300 : {
     136             :         return this->size;
     137         300 : }
     138             : 
     139             : } //namespace util
     140             : } //namespace coherent
     141             : 
     142             : #endif /* MULTI_BUFFER_H_2363 */

Generated by: LCOV version 1.9