Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
doxygen-1.8.11
src
growbuf.h
Go to the documentation of this file.
1
#ifndef GROWBUF_H
2
#define GROWBUF_H
3
4
#include <stdlib.h>
5
#include <string.h>
6
7
#define GROW_AMOUNT 1024
8
9
/** Class representing a string buffer optimised for growing. */
10
class
GrowBuf
11
{
12
public
:
13
GrowBuf
() :
str
(0),
pos
(0),
len
(0) {}
14
~GrowBuf
() { free(
str
);
str
=0;
pos
=0;
len
=0; }
15
void
clear
() {
pos
=0; }
16
void
addChar
(
char
c
) {
if
(
pos
>=
len
) {
len
+=
GROW_AMOUNT
;
str
= (
char
*)realloc(
str
,
len
); }
17
str
[
pos
++]=
c
;
18
}
19
void
addStr
(
const
char
*
s
) {
20
if
(s)
21
{
22
int
l
=strlen(s);
23
if
(
pos
+l>=
len
) {
len
+=l+
GROW_AMOUNT
;
str
= (
char
*)realloc(
str
,
len
); }
24
strcpy(&
str
[
pos
],s);
25
pos+=
l
;
26
}
27
}
28
void
addStr
(
const
char
*
s
,
int
n
) {
29
if
(s)
30
{
31
int
l
=strlen(s);
32
if
(n<l) l=
n
;
33
if
(
pos
+l>=
len
) {
len
+=l+
GROW_AMOUNT
;
str
= (
char
*)realloc(
str
,
len
); }
34
strncpy(&
str
[
pos
],s,n);
35
pos+=
l
;
36
}
37
}
38
const
char
*
get
() {
return
str
; }
39
int
getPos
()
const
{
return
pos
; }
40
char
at
(
int
i)
const
{
return
str
[i]; }
41
private
:
42
char
*
str
;
43
int
pos
;
44
int
len
;
45
};
46
47
#endif
GrowBuf::clear
void clear()
Definition:
growbuf.h:15
GrowBuf::addStr
void addStr(const char *s)
Definition:
growbuf.h:19
GrowBuf::pos
int pos
Definition:
growbuf.h:43
l
static QStrList * l
Definition:
config.cpp:1044
GROW_AMOUNT
#define GROW_AMOUNT
Definition:
growbuf.h:7
GrowBuf::addChar
void addChar(char c)
Definition:
growbuf.h:16
GrowBuf::len
int len
Definition:
growbuf.h:44
cet::n
std::void_t< T > n
Definition:
metaprogramming.h:28
ValidateOpDetSimulation.c
dictionary c
Definition:
ValidateOpDetSimulation.py:57
GrowBuf::addStr
void addStr(const char *s, int n)
Definition:
growbuf.h:28
GrowBuf
Definition:
growbuf.h:10
GrowBuf::str
char * str
Definition:
growbuf.h:42
GrowBuf::at
char at(int i) const
Definition:
growbuf.h:40
GrowBuf::getPos
int getPos() const
Definition:
growbuf.h:39
GrowBuf::GrowBuf
GrowBuf()
Definition:
growbuf.h:13
GrowBuf::~GrowBuf
~GrowBuf()
Definition:
growbuf.h:14
s
static QCString * s
Definition:
config.cpp:1042
Generated by
1.8.11