rllib  1
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 
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 
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 
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 
int _size
Definition: rlbuffer.h:44
void * adr
Definition: rlbuffer.h:33
int size()
Definition: rlbuffer.cpp:55
unsigned long * ul
Definition: rlbuffer.h:39
rlBuffer()
Definition: rlbuffer.cpp:18
unsigned int * ui
Definition: rlbuffer.h:37
char * line(int i)
Definition: rlbuffer.cpp:72
long * l
Definition: rlbuffer.h:38
double * d
Definition: rlbuffer.h:41
virtual ~rlBuffer()
Definition: rlbuffer.cpp:31
unsigned char * uc
Definition: rlbuffer.h:35
int resize(int size)
Definition: rlbuffer.cpp:36
int * i
Definition: rlbuffer.h:36
int setText(const char *text)
Definition: rlbuffer.cpp:60
float * f
Definition: rlbuffer.h:40
char * c
Definition: rlbuffer.h:34