COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
Covise_Util.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef COVISE_UTIL_H
9 #define COVISE_UTIL_H
10 
11 #include "covise.h"
12 
13 namespace covise
14 {
15 
16 class CharNum
17 {
18  char *buf;
19  int num;
20 
21 public:
23  {
24  num = 0;
25  buf = NULL;
26  };
27  CharNum(int n)
28  {
29  buf = new char[50];
30  sprintf(buf, "%d", n);
31  num = n;
32  };
33  CharNum(float n)
34  {
35  buf = new char[50];
36  sprintf(buf, "%f", n);
37  num = (int)n;
38  };
40  {
41  delete[] buf;
42  };
43  operator char *()
44  {
45  return (buf);
46  };
47  operator int()
48  {
49  return (num);
50  };
51 };
52 
54 {
55  char *buf;
56  int len;
57 
58 public:
59  int cur_len;
61  {
62  cur_len = 0;
63  len = 0;
64  buf = NULL;
65  };
67  {
68  cur_len = obuf->cur_len;
69  len = cur_len + 1;
70  buf = new char[len];
71  strcpy(buf, obuf->getbuf());
72  };
73  CharBuffer(int def)
74  {
75  cur_len = 0;
76  len = def;
77  buf = new char[len];
78  if (len)
79  *buf = '\0';
80  };
82  {
83  delete[] buf;
84  };
85  char *return_data()
86  {
87  char *tmp = buf;
88  buf = NULL;
89  cur_len = 0;
90  len = 0;
91  return (tmp);
92  };
93  int strlen()
94  {
95  return (cur_len);
96  };
97  void operator+=(const char *const s)
98  {
99  int l = (int)::strlen(s);
100  if (cur_len + l >= len)
101  {
102  len += l * 10;
103  char *nbuf = new char[len];
104  strcpy(nbuf, buf);
105  delete[] buf;
106  buf = nbuf;
107  }
108  strcpy(buf + cur_len, s);
109  cur_len += l;
110  };
111  void operator+=(char c)
112  {
113  if (cur_len + 1 >= len)
114  {
115  len += 100;
116  char *nbuf = new char[len];
117  strcpy(nbuf, buf);
118  delete[] buf;
119  buf = nbuf;
120  }
121  buf[cur_len] = c;
122  cur_len++;
123  buf[cur_len] = 0;
124  };
125  void operator+=(int n)
126  {
127  CharNum s(n);
128  int l = (int)::strlen(s);
129  if (cur_len + l >= len)
130  {
131  len += l * 10;
132  char *nbuf = new char[len];
133  strcpy(nbuf, buf);
134  delete[] buf;
135  buf = nbuf;
136  }
137  strcpy(buf + cur_len, s);
138  cur_len += l;
139  };
140  void operator+=(float n)
141  {
142  CharNum s(n);
143  int l = (int)::strlen(s);
144  if (cur_len + l >= len)
145  {
146  len += l * 10;
147  char *nbuf = new char[len];
148  strcpy(nbuf, buf);
149  delete[] buf;
150  buf = nbuf;
151  }
152  strcpy(buf + cur_len, s);
153  cur_len += l;
154  };
155  operator const char *() const
156  {
157  return (buf);
158  };
159  const char *getbuf()
160  {
161  return (buf);
162  };
163 };
164 }
165 #endif
GLenum GLsizei len
Definition: khronos-glext.h:7440
CharNum(float n)
Definition: Covise_Util.h:33
int len
Definition: Covise_Util.h:56
void operator+=(const char *const s)
Definition: Covise_Util.h:97
int strlen()
Definition: Covise_Util.h:93
int num
Definition: Covise_Util.h:19
CharBuffer()
Definition: Covise_Util.h:60
GLdouble n
Definition: khronos-glext.h:8447
void operator+=(char c)
Definition: Covise_Util.h:111
GLdouble s
Definition: khronos-glext.h:6441
#define NULL
Definition: covise_list.h:22
Definition: Covise_Util.h:16
CharNum(int n)
Definition: Covise_Util.h:27
char * return_data()
Definition: Covise_Util.h:85
int cur_len
Definition: Covise_Util.h:59
char * buf
Definition: Covise_Util.h:55
void operator+=(float n)
Definition: Covise_Util.h:140
CharBuffer(CharBuffer *obuf)
Definition: Covise_Util.h:66
const char * getbuf()
Definition: Covise_Util.h:159
Definition: Covise_Util.h:53
const GLubyte * c
Definition: khronos-glext.h:9864
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: khronos-glext.h:8469
~CharNum()
Definition: Covise_Util.h:39
~CharBuffer()
Definition: Covise_Util.h:81
void operator+=(int n)
Definition: Covise_Util.h:125
GLuint GLuint num
Definition: khronos-glext.h:10593
char * buf
Definition: Covise_Util.h:18
CharBuffer(int def)
Definition: Covise_Util.h:73
CharNum()
Definition: Covise_Util.h:22