Evita  0.16
evBitBuffer.h
Go to the documentation of this file.
1 /*
2  *
3  * EVITA: Efficient Visualization of Terascale Datasets
4  * Copyright (C) 2000-2016 Team Evita
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
18  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
19  * MA 02139, USA.
20  *
21  */
22 
23 
24 #ifndef __evBitBuffer_h
25 #define __evBitBuffer_h
26 
27 
28 #include "evFile.h"
29 #include "evBit.h"
30 #include "evVector.h"
31 #include "evBoundingBox.h"
32 
33 
34 class evBitBuffer : public evFile
35 {
36 public:
37  evBitBuffer(void);
38  virtual ~evBitBuffer(void);
39 
40  virtual const evString GetClassName(void) const
41  {
42  return(evString("evBitBuffer"));
43  }
44 
45  QccBitBuffer *GetBitBuffer(void);
46  const QccBitBuffer *GetBitBuffer(void) const;
47 
48  int Start(void);
49  int End(void);
50  int Flush(void);
51 
52  int Read(evBit &val);
53  int Read(unsigned char &val);
54  int Read(int &val);
55  int Read(float &val);
56  int Read(double &val);
57  int Read(evVector &val);
58  int Read(evAddress &val);
59  int Read(evBoundingBox &bounding_box);
60 
61  int Write(const evBit val);
62  int Write(const unsigned char val);
63  int Write(const int val);
64  int Write(const float val);
65  int Write(const double val);
66  int Write(const evVector &val);
67  int Write(const evAddress &val);
68  int Write(const evBoundingBox &bounding_box);
69 
70  int GetBitCount(void);
71 
72 protected:
73 
74 private:
75  QccBitBuffer BitBuffer;
76 
77 };
78 
79 
80 inline QccBitBuffer *evBitBuffer::GetBitBuffer(void)
81 {
82  return(&this->BitBuffer);
83 }
84 
85 
86 inline const QccBitBuffer *evBitBuffer::GetBitBuffer(void) const
87 {
88  return(&this->BitBuffer);
89 }
90 
91 
93 {
94  QccBitBufferInitialize(&(this->BitBuffer));
95 }
96 
97 
99 {
100 }
101 
102 
103 inline int evBitBuffer::Read(evBit &val)
104 {
105  int bit;
106 
107  if (QccBitBufferGetBit(&this->BitBuffer,
108  &bit))
109  {
110  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling QccBitBufferGetBit()");
111  return(1);
112  }
113 
114  val = evBit(bit);
115 
116  return(0);
117 }
118 
119 
120 inline int evBitBuffer::Read(unsigned char &val)
121 {
122  if (QccBitBufferGetChar(&this->BitBuffer,
123  &val))
124  {
125  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling QccBitBufferGetChar()");
126  return(1);
127  }
128 
129  return(0);
130 }
131 
132 
133 inline int evBitBuffer::Read(int &val)
134 {
135  if (QccBitBufferGetInt(&this->BitBuffer,
136  &val))
137  {
138  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling QccBitBufferGetInt()");
139  return(1);
140  }
141 
142  return(0);
143 }
144 
145 
146 inline int evBitBuffer::Read(float &val)
147 {
148  double val2;
149 
150  if (QccBitBufferGetDouble(&this->BitBuffer,
151  &val2))
152  {
153  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling QccBitBufferGetDouble()");
154  return(1);
155  }
156 
157  val = (float)val2;
158 
159  return(0);
160 }
161 
162 
163 inline int evBitBuffer::Read(double &val)
164 {
165  if (QccBitBufferGetDouble(&this->BitBuffer,
166  &val))
167  {
168  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling QccBitBufferGetDouble()");
169  return(1);
170  }
171 
172  return(0);
173 }
174 
175 
176 inline int evBitBuffer::Read(evVector &val)
177 {
178  for (unsigned int component = 0; component < val.Dimension(); component++)
179  if (this->Read(val[component]))
180  {
181  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling evBitBuffer::Read()");
182  return(1);
183  }
184 
185  return(0);
186 }
187 
188 
189 inline int evBitBuffer::Read(evAddress &val)
190 {
191  for (unsigned int component = 0;
192  component < val.GetNumDimensions(); component++)
193  {
194  int val2;
195 
196  if (this->Read(val2))
197  {
198  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling evBitBuffer::Read()");
199  return(1);
200  }
201 
202  val.Set(val2, component);
203  }
204 
205  return(0);
206 }
207 
208 
209 inline int evBitBuffer::Read(evBoundingBox &bounding_box)
210 {
211  unsigned int num_dimensions =
212  bounding_box.GetLowerBound().Dimension();
213 
214  evVector lower_bound(num_dimensions);
215  evVector upper_bound(num_dimensions);
216 
217  if (this->Read(lower_bound))
218  {
219  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling evBitBuffer::Read()");
220  return(1);
221  }
222  if (this->Read(upper_bound))
223  {
224  ErrorHandler.ErrorMessage("evBitBuffer::Read(): Error calling evBitBuffer::Read()");
225  return(1);
226  }
227 
228  bounding_box.SetBounds(lower_bound, upper_bound);
229 
230  return(0);
231 }
232 
233 
234 inline int evBitBuffer::Write(const evBit val)
235 {
236  if (QccBitBufferPutBit(&this->BitBuffer,
237  val.GetBit()))
238  {
239  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling QccBitBufferPutBit()");
240  return(1);
241  }
242 
243  return(0);
244 }
245 
246 
247 inline int evBitBuffer::Write(const unsigned char val)
248 {
249  if (QccBitBufferPutChar(&this->BitBuffer,
250  val))
251  {
252  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling QccBitBufferPutChar()");
253  return(1);
254  }
255 
256  return(0);
257 }
258 
259 
260 inline int evBitBuffer::Write(const int val)
261 {
262  if (QccBitBufferPutInt(&this->BitBuffer,
263  val))
264  {
265  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling QccBitBufferPutInt()");
266  return(1);
267  }
268 
269  return(0);
270 }
271 
272 
273 inline int evBitBuffer::Write(const float val)
274 {
275  if (QccBitBufferPutDouble(&this->BitBuffer,
276  (double)val))
277  {
278  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling QccBitBufferPutDouble()");
279  return(1);
280  }
281 
282  return(0);
283 }
284 
285 
286 inline int evBitBuffer::Write(const double val)
287 {
288  if (QccBitBufferPutDouble(&this->BitBuffer,
289  val))
290  {
291  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling QccBitBufferPutDouble()");
292  return(1);
293  }
294 
295  return(0);
296 }
297 
298 
299 inline int evBitBuffer::Write(const evVector &val)
300 {
301  for (unsigned int component = 0; component < val.Dimension(); component++)
302  if (this->Write(val[component]))
303  {
304  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling evBitBuffer::Write()()");
305  return(1);
306  }
307 
308  return(0);
309 }
310 
311 
312 inline int evBitBuffer::Write(const evAddress &val)
313 {
314  for (unsigned int component = 0;
315  component < val.GetNumDimensions(); component++)
316  {
317  int val2 = val.Get(component);
318 
319  if (this->Write(val2))
320  {
321  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling evBitBuffer::Write()");
322  return(1);
323  }
324  }
325 
326  return(0);
327 }
328 
329 
330 inline int evBitBuffer::Write(const evBoundingBox &bounding_box)
331 {
332  if (this->Write(bounding_box.GetLowerBound()))
333  {
334  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling evBitBuffer::Write()");
335  return(1);
336  }
337  if (this->Write(bounding_box.GetUpperBound()))
338  {
339  ErrorHandler.ErrorMessage("evBitBuffer::Write(): Error calling evBitBuffer::Write()");
340  return(1);
341  }
342  return(0);
343 }
344 
345 
346 inline int evBitBuffer::GetBitCount(void)
347 {
348  return(this->BitBuffer.bit_cnt);
349 }
350 
351 
352 #endif
QccBitBuffer BitBuffer
Definition: evBitBuffer.h:75
Definition: evFile.h:44
int Flush(void)
unsigned int Dimension(void) const
Definition: evVector.h:149
evVector GetLowerBound(void) const
Definition: evBoundingBox.h:102
int Read(evBit &val)
Definition: evBitBuffer.h:103
int End(void)
int Start(void)
Definition: evVector.h:36
int Write(const evBit val)
Definition: evBitBuffer.h:234
void Set(const int value, const unsigned int dimension)
Definition: evAddress.h:117
Definition: evAddress.h:37
virtual ~evBitBuffer(void)
Definition: evBitBuffer.h:98
void SetBounds(const evVector &lower_bound, const evVector &upper_bound)
Definition: evBoundingBox.h:120
Definition: evBoundingBox.h:32
QccBitBuffer * GetBitBuffer(void)
Definition: evBitBuffer.h:80
Definition: evBit.h:31
int * Get(void)
Definition: evAddress.h:124
int GetBitCount(void)
Definition: evBitBuffer.h:346
evVector GetUpperBound(void) const
Definition: evBoundingBox.h:114
Definition: evBitBuffer.h:34
int GetBit(void) const
Definition: evBit.h:74
evErrorHandler ErrorHandler
void ErrorMessage(const char *format,...)
evBitBuffer(void)
Definition: evBitBuffer.h:92
unsigned int GetNumDimensions(void) const
Definition: evAddress.h:148
Definition: evString.h:30
virtual const evString GetClassName(void) const
Definition: evBitBuffer.h:40