LCOV - code coverage report
Current view: top level - ugbase/common/util - binary_buffer.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 1 0
Test Date: 2025-09-21 23:31:46 Functions: - 0 0

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) 2011-2015:  G-CSC, Goethe University Frankfurt
       3              :  * Author: Sebastian Reiter
       4              :  * 
       5              :  * This file is part of UG4.
       6              :  * 
       7              :  * UG4 is free software: you can redistribute it and/or modify it under the
       8              :  * terms of the GNU Lesser General Public License version 3 (as published by the
       9              :  * Free Software Foundation) with the following additional attribution
      10              :  * requirements (according to LGPL/GPL v3 §7):
      11              :  * 
      12              :  * (1) The following notice must be displayed in the Appropriate Legal Notices
      13              :  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
      14              :  * 
      15              :  * (2) The following notice must be displayed at a prominent place in the
      16              :  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
      17              :  * 
      18              :  * (3) The following bibliography is recommended for citation and must be
      19              :  * preserved in all covered files:
      20              :  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
      21              :  *   parallel geometric multigrid solver on hierarchically distributed grids.
      22              :  *   Computing and visualization in science 16, 4 (2013), 151-164"
      23              :  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
      24              :  *   flexible software system for simulating pde based models on high performance
      25              :  *   computers. Computing and visualization in science 16, 4 (2013), 165-179"
      26              :  * 
      27              :  * This program is distributed in the hope that it will be useful,
      28              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      29              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      30              :  * GNU Lesser General Public License for more details.
      31              :  */
      32              : 
      33              : #ifndef __H__UG__binary_buffer__
      34              : #define __H__UG__binary_buffer__
      35              : 
      36              : #include <vector>
      37              : #include "common/types.h"
      38              : 
      39              : namespace ug
      40              : {
      41              : 
      42              : /// \addtogroup ugbase_common_io
      43              : /// \{
      44              : 
      45              : ///     A Buffer for binary data.
      46              : /**     The BinaryBuffer allows read and write access, which mimics the
      47              :  * behavior of std::iostream. However, in contrary to ug::BinaryStream,
      48              :  * this class is not a specialization of std::iostream. This is crucial
      49              :  * to achieve maximal performance.
      50              :  *
      51              :  * Furthermore BinaryBuffer gives access to its internal buffer,
      52              :  * which can be handy in some situations. However, this feature
      53              :  * has to be used with extreme care!
      54              :  */
      55            0 : class BinaryBuffer
      56              : {
      57              :         public:
      58              :                 BinaryBuffer();
      59              : 
      60              :         ///     creates a binary buffer and reserves bufSize bytes.
      61              :                 BinaryBuffer(size_t bufSize);
      62              : 
      63              :         ///     clears the buffer
      64              :         /**     This method does not free associated memory. It only
      65              :          * resets the read and write positions. To free the memory
      66              :          * you may create a new instance of ug::BinaryBuffer and
      67              :          * assign it by value to your current instance.*/
      68              :                 void clear();
      69              : 
      70              :         ///     resizes the associated buffer to the given size.
      71              :         /**     You can check the number of bytes reserved in the buffer through
      72              :          * ug::BinaryBuffer::capacity*/
      73              :                 void reserve(size_t newSize);
      74              : 
      75              :         ///     returns the capacity (reserved memory) of the buffer
      76              :                 inline size_t capacity() const;
      77              : 
      78              :         ///     returns the current read-pos (in bytes)
      79              :                 inline size_t read_pos() const;
      80              : 
      81              :         ///     returns the current write-pos (in bytes)
      82              :                 inline size_t write_pos() const;
      83              : 
      84              :         ///     reads data of the given size (in bytes)
      85              :         /**     This automatically advances the read position.*/
      86              :                 inline void read(char* buf, size_t size);
      87              : 
      88              :         /// writes data of the given size (in bytes)
      89              :         /**     This automatically advances the write position.*/
      90              :                 inline void write(const char* buf, size_t size);
      91              : 
      92              :         ///     returns the raw buffer pointer or NULL if the buffer is empty (capacity() == 0)
      93              :                 inline char* buffer();
      94              : 
      95              :         ///     returns true if the read-position reached the write-position
      96              :                 inline bool eof();
      97              : 
      98              :         ///     sets the read position (in bytes).
      99              :                 void set_read_pos(size_t pos);
     100              : 
     101              :         ///     sets the write position.
     102              :                 void set_write_pos(size_t pos);
     103              : 
     104              :         private:
     105              :                 std::vector<char> m_data;
     106              :                 size_t                          m_readPos;
     107              :                 size_t                          m_writePos;
     108              : };
     109              : 
     110              : // end group ugbase_common_io
     111              : /// \}
     112              : 
     113              : }//     end of namespace
     114              : 
     115              : 
     116              : ////////////////////////////////
     117              : //      include implementation
     118              : #include "binary_buffer_impl.h"
     119              : 
     120              : #endif
        

Generated by: LCOV version 2.0-1