ug4
binary_buffer.h
Go to the documentation of this file.
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 
44 
46 
56 {
57  public:
58  BinaryBuffer();
59 
61  BinaryBuffer(size_t bufSize);
62 
64 
68  void clear();
69 
71 
73  void reserve(size_t newSize);
74 
76  inline size_t capacity() const;
77 
79  inline size_t read_pos() const;
80 
82  inline size_t write_pos() const;
83 
85 
86  inline void read(char* buf, size_t size);
87 
89 
90  inline void write(const char* buf, size_t size);
91 
93  inline char* buffer();
94 
96  inline bool eof();
97 
99  void set_read_pos(size_t pos);
100 
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
112 
113 }// end of namespace
114 
115 
117 // include implementation
118 #include "binary_buffer_impl.h"
119 
120 #endif
A Buffer for binary data.
Definition: binary_buffer.h:56
size_t read_pos() const
returns the current read-pos (in bytes)
Definition: binary_buffer_impl.h:48
char * buffer()
returns the raw buffer pointer or NULL if the buffer is empty (capacity() == 0)
Definition: binary_buffer_impl.h:94
size_t capacity() const
returns the capacity (reserved memory) of the buffer
Definition: binary_buffer_impl.h:43
void set_write_pos(size_t pos)
sets the write position.
Definition: binary_buffer.cpp:69
size_t m_readPos
Definition: binary_buffer.h:106
void reserve(size_t newSize)
resizes the associated buffer to the given size.
Definition: binary_buffer.cpp:58
void read(char *buf, size_t size)
reads data of the given size (in bytes)
Definition: binary_buffer_impl.h:58
BinaryBuffer()
Definition: binary_buffer.cpp:38
size_t m_writePos
Definition: binary_buffer.h:107
void set_read_pos(size_t pos)
sets the read position (in bytes).
Definition: binary_buffer.cpp:64
void clear()
clears the buffer
Definition: binary_buffer.cpp:48
size_t write_pos() const
returns the current write-pos (in bytes)
Definition: binary_buffer_impl.h:53
std::vector< char > m_data
Definition: binary_buffer.h:105
bool eof()
returns true if the read-position reached the write-position
Definition: binary_buffer_impl.h:99
void write(const char *buf, size_t size)
writes data of the given size (in bytes)
Definition: binary_buffer_impl.h:71
the ug namespace