ONPOSIX
2.0
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Enumerator
Friends
Macros
Pages
Buffer.hpp
Go to the documentation of this file.
1
/*
2
* Buffer.hpp
3
*
4
* Copyright (C) 2012 Evidence Srl - www.evidence.eu.com
5
*
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU Library General Public
8
* License as published by the Free Software Foundation; either
9
* version 2 of the License, or (at your option) any later version.
10
*
11
* This library is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* Library General Public License for more details.
15
*
16
* You should have received a copy of the GNU Library General Public
17
* License along with this library; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#ifndef BUFFER_HPP_
22
#define BUFFER_HPP_
23
24
25
26
namespace
onposix {
27
28
/**
29
* \brief Very simple buffer with control on overflow.
30
*
31
* This is a simple buffer, internally allocated as a char buffer with new
32
* and delete.
33
* With respect to hand-made buffers, it adds the check on boundaries.
34
*/
35
class
Buffer
{
36
/**
37
* \brief Current size of the buffer.
38
*/
39
unsigned
long
int
size_
;
40
41
/**
42
* \brief Pointer to the allocated memory.
43
*/
44
char
*
data_
;
45
46
// Disable default copy constructor
47
Buffer
(
const
Buffer
&);
48
49
public
:
50
explicit
Buffer
(
unsigned
long
int
size);
51
virtual
~Buffer
();
52
char
&
operator[]
(
unsigned
long
int
p);
53
unsigned
long
int
fill
(
const
char
* src,
unsigned
long
int
size);
54
unsigned
long
int
fill
(
Buffer
* b,
unsigned
long
int
size);
55
bool
compare
(
Buffer
* b,
unsigned
long
int
size);
56
bool
compare
(
const
char
* s,
unsigned
long
int
size);
57
58
/**
59
* \brief Method to get a pointer to the buffer.
60
*
61
* @return position of the first byte
62
*/
63
char
*
getBuffer
(){
64
return
reinterpret_cast<
char
*
>
(
data_
);
65
}
66
67
/**
68
* \brief Method to get the size of the buffer
69
*
70
* @return Size of the buffer
71
*/
72
inline
unsigned
long
int
getSize
()
const
{
73
return
size_
;
74
}
75
76
inline
unsigned
long
int
fill
(
char
* src,
unsigned
long
int
size) {
77
return
fill
(reinterpret_cast<const char*> (src), size);
78
}
79
};
80
81
}
/* onposix */
82
83
#endif
/* BUFFER_HPP_ */
include
Buffer.hpp
Generated on Wed Apr 30 2014 15:27:24 for ONPOSIX by
1.8.1.2