rllib
1
lib
rlbuffer.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
rlbuffer.cpp - description
3
-------------------
4
begin : Sun Aug 24 2014
5
copyright : (C) 2014 by R. Lehrig
6
email : lehrig@t-online.de
7
***************************************************************************/
8
9
/***************************************************************************
10
* *
11
* This library is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as *
13
* published by the Free Software Foundation *
14
* *
15
***************************************************************************/
16
#include "
rlbuffer.h
"
17
18
rlBuffer::rlBuffer
()
19
{
20
adr
= NULL;
21
c
= (
char
*)
adr
;
22
uc
= (
unsigned
char
*)
adr
;
23
i
= (
int
*)
adr
;
24
ui
= (
unsigned
int
*)
adr
;
25
l
= (
long
*)
adr
;
26
ul
= (
unsigned
long
*)
adr
;
27
f
= (
float
*)
adr
;
28
d
= (
double
*)
adr
;
29
}
30
31
rlBuffer::~rlBuffer
()
32
{
33
if
(
adr
!= NULL)
delete
[]
c
;
34
}
35
36
int
rlBuffer::resize
(
int
size)
37
{
38
if
(
size
<= 0)
return
-1;
39
_size
=
size
;
40
if
(
adr
!= NULL)
delete
[]
c
;
41
42
adr
= (
void
*)
new
char
[
_size
];
43
c
= (
char
*)
adr
;
44
uc
= (
unsigned
char
*)
adr
;
45
i
= (
int
*)
adr
;
46
ui
= (
unsigned
int
*)
adr
;
47
l
= (
long
*)
adr
;
48
ul
= (
unsigned
long
*)
adr
;
49
f
= (
float
*)
adr
;
50
d
= (
double
*)
adr
;
51
52
return
_size
;
53
}
54
55
int
rlBuffer::size
()
56
{
57
return
_size
;
58
}
59
60
int
rlBuffer::setText
(
const
char
*text)
61
{
62
int
len;
63
if
((len = strlen(text)) >=
_size
)
64
{
65
printf(
"rlBuffer::setText() text is too long\n"
);
66
return
-1;
67
}
68
strcpy(
c
,text);
69
return
len;
70
}
71
72
char
*
rlBuffer::line
(
int
i)
73
{
74
if
(
c
== NULL)
return
NULL;
75
char
*cptr_start =
c
;
76
for
(
int
ind=0; ind<
i
; ind++)
77
{
78
cptr_start = strchr(cptr_start,
'\n'
);
79
if
(cptr_start != NULL) cptr_start++;
80
else
return
NULL;
81
}
82
if
((cptr_start -
c
) >=
_size
)
return
NULL;
83
return
cptr_start;
84
}
85
rlBuffer::_size
int _size
Definition:
rlbuffer.h:44
rlBuffer::adr
void * adr
Definition:
rlbuffer.h:33
rlBuffer::size
int size()
Definition:
rlbuffer.cpp:55
rlBuffer::ul
unsigned long * ul
Definition:
rlbuffer.h:39
rlbuffer.h
rlBuffer::rlBuffer
rlBuffer()
Definition:
rlbuffer.cpp:18
rlBuffer::ui
unsigned int * ui
Definition:
rlbuffer.h:37
rlBuffer::line
char * line(int i)
Definition:
rlbuffer.cpp:72
rlBuffer::l
long * l
Definition:
rlbuffer.h:38
rlBuffer::d
double * d
Definition:
rlbuffer.h:41
rlBuffer::~rlBuffer
virtual ~rlBuffer()
Definition:
rlbuffer.cpp:31
rlBuffer::uc
unsigned char * uc
Definition:
rlbuffer.h:35
rlBuffer::resize
int resize(int size)
Definition:
rlbuffer.cpp:36
rlBuffer::i
int * i
Definition:
rlbuffer.h:36
rlBuffer::setText
int setText(const char *text)
Definition:
rlbuffer.cpp:60
rlBuffer::f
float * f
Definition:
rlbuffer.h:40
rlBuffer::c
char * c
Definition:
rlbuffer.h:34
Generated by
1.8.14