00001
00024 #ifndef INC_MI32_RECORDBUFFER_H
00025 #define INC_MI32_RECORDBUFFER_H
00026
00027 #ifndef INC_MI32_SIMPLEAR_H
00028 #include <mi32/simplear.h>
00029 #endif
00030
00031
00032
00034 class RECORDBUFFER {
00035 public:
00036
00038 void Clear (
00039 ) { memset(static_cast<UINT8*>(m_buffer),0,GetSize()); }
00040
00042 UINT8* GetPtr (
00043 ) { return (m_buffer); }
00044
00046 const UINT8* GetPtr (
00047 ) const { return (m_buffer); }
00048
00050 int GetSize (
00051 ) const { return (m_buffer.GetNumItems()); }
00052
00054 INT8 GetINT8 (
00055 int offset
00056 ) const { return (static_cast<INT8>(m_buffer[offset])); }
00057
00059 UINT8 GetUINT8 (
00060 int offset
00061 ) const { return (m_buffer[offset]); }
00062
00064 void PutINT8 (
00065 int offset,
00066 INT8 value
00067 ) { m_buffer[offset] = static_cast<UINT8>(value); }
00068
00070 void PutUINT8 (
00071 int offset,
00072 UINT8 value
00073 ) { m_buffer[offset] = value; }
00074
00076 void PutString (
00077 int offset,
00078 const char *string
00079 ) { memcpy(&m_buffer[offset],string,strlen(string)); }
00080
00082 void PutString (
00083 int offset,
00084 int maxchars,
00085 const char *string,
00086 char fillchar = 0
00087 ) {
00088 int len = strlen(string);
00089 if (len < maxchars) {
00090 memcpy(&m_buffer[offset],string,len);
00091 memset(&m_buffer[offset+len],fillchar,maxchars-len);
00092 }
00093 else {
00094 memcpy(&m_buffer[offset],string,maxchars);
00095 }
00096 }
00097
00099 ERRVALUE Resize (
00100 int numbytes,
00101 bool keepold = true,
00102 bool clear = false
00103 ) { return (m_buffer.Resize(numbytes,keepold,clear)); }
00104
00105 protected:
00106 #ifndef GENERATING_DOXYGEN_OUTPUT
00107 SIMPLE_ARRAY<UINT8> m_buffer;
00108 #endif // GENERATING_DOXYGEN_OUTPUT
00109
00110 RECORDBUFFER () { }
00111
00112 ~RECORDBUFFER () { }
00113
00114 };
00115
00116
00117
00121 class RECORDBUFFER_LSBFIRST : public RECORDBUFFER {
00122 public:
00123
00125 INT16 GetINT16 (
00126 int offset
00127 ) {
00128 #ifdef BYTEORDER_HiLo
00129 return ((static_cast<INT16>(m_buffer[offset+0]) << 8) + m_buffer[offset+1]);
00130 #else
00131 return ((static_cast<INT16>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00132 #endif
00133 }
00134
00136 void GetINT16 (
00137 int offset,
00138 INT16 *values,
00139 int numvalues
00140 ) {
00141 memcpy(values,&m_buffer[offset],numvalues*sizeof(INT16));
00142 #ifdef BYTEORDER_HiLo
00143 SwapBytes(values,numvalues);
00144 #endif
00145 }
00146
00148 UINT16 GetUINT16 (
00149 int offset
00150 ) {
00151 #ifdef BYTEORDER_HiLo
00152 return ((static_cast<UINT16>(m_buffer[offset+0]) << 8) + m_buffer[offset+1]);
00153 #else
00154 return ((static_cast<UINT16>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00155 #endif
00156 }
00157
00159 void GetUINT16 (
00160 int offset,
00161 UINT16 *values,
00162 int numvalues
00163 ) {
00164 memcpy(values,&m_buffer[offset],numvalues*sizeof(UINT16));
00165 #ifdef BYTEORDER_HiLo
00166 SwapBytes(values,numvalues);
00167 #endif
00168 }
00169
00171 INT32 GetINT32 (
00172 int offset
00173 ) {
00174 #ifdef BYTEORDER_HiLo
00175 return ((static_cast<INT32>(m_buffer[offset+0]) << 24) + (static_cast<INT32>(m_buffer[offset+1]) << 16) + (static_cast<INT32>(m_buffer[offset+2]) << 8) + m_buffer[offset+3]);
00176 #else
00177 return ((static_cast<INT32>(m_buffer[offset+3]) << 24) + (static_cast<INT32>(m_buffer[offset+2]) << 16) + (static_cast<INT32>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00178 #endif
00179 }
00180
00182 void GetINT32 (
00183 int offset,
00184 INT32 *values,
00185 int numvalues
00186 ) {
00187 memcpy(values,&m_buffer[offset],numvalues*sizeof(INT32));
00188 #ifdef BYTEORDER_HiLo
00189 SwapBytes(values,numvalues);
00190 #endif
00191 }
00192
00194 UINT32 GetUINT32 (
00195 int offset
00196 ) {
00197 #ifdef BYTEORDER_HiLo
00198 return ((static_cast<UINT32>(m_buffer[offset+0]) << 24) + (static_cast<UINT32>(m_buffer[offset+1]) << 16) + (static_cast<UINT32>(m_buffer[offset+2]) << 8) + m_buffer[offset+3]);
00199 #else
00200 return ((static_cast<UINT32>(m_buffer[offset+3]) << 24) + (static_cast<UINT32>(m_buffer[offset+2]) << 16) + (static_cast<UINT32>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00201 #endif
00202 }
00203
00205 void GetUINT32 (
00206 int offset,
00207 UINT32 *values,
00208 int numvalues
00209 ) {
00210 memcpy(values,&m_buffer[offset],numvalues*sizeof(UINT32));
00211 #ifdef BYTEORDER_HiLo
00212 SwapBytes(values,numvalues);
00213 #endif
00214 }
00215
00217 float GetFloat (
00218 int offset
00219 ) {
00220 float value;
00221 memcpy(&value,&m_buffer[offset],sizeof(float));
00222 #ifdef BYTEORDER_HiLo
00223 SwapBytes(value);
00224 #endif
00225 return (value);
00226 }
00227
00229 void GetFloat (
00230 int offset,
00231 float *values,
00232 int numvalues
00233 ) {
00234 memcpy(values,&m_buffer[offset],numvalues*sizeof(float));
00235 #ifdef BYTEORDER_HiLo
00236 SwapBytes(values,numvalues);
00237 #endif
00238 }
00239
00241 double GetDouble (
00242 int offset
00243 ) {
00244 double value;
00245 memcpy(&value,&m_buffer[offset],sizeof(double));
00246 #ifdef BYTEORDER_HiLo
00247 SwapBytes(value);
00248 #endif
00249 return (value);
00250 }
00251
00253 void GetDouble (
00254 int offset,
00255 double *values,
00256 int numvalues
00257 ) {
00258 memcpy(values,&m_buffer[offset],numvalues*sizeof(double));
00259 #ifdef BYTEORDER_HiLo
00260 SwapBytes(values,numvalues);
00261 #endif
00262 }
00263
00267 template <typename _TT> void GetComposite (
00268 int offset,
00269 _TT& value
00270 ) const {
00271 memcpy(&value,&m_buffer[offset],sizeof(_TT));
00272 #ifdef BYTEORDER_HiLo
00273 SwapBytes(value);
00274 #endif
00275 return;
00276 }
00277
00281 template <typename _TT> void GetComposite (
00282 int offset,
00283 _TT *values,
00284 int numvalues
00285 ) const {
00286 memcpy(values,&m_buffer[offset],numvalues*sizeof(float));
00287 #ifdef BYTEORDER_HiLo
00288 SwapBytes(values,numvalues);
00289 #endif
00290 }
00291
00293 void PutINT16 (
00294 int offset,
00295 INT16 value
00296 ) {
00297 #ifdef BYTEORDER_HiLo
00298 SwapBytes(value);
00299 #endif
00300 memcpy(&m_buffer[offset],&value,sizeof(INT16));
00301 }
00302
00304 void PutINT16 (
00305 int offset,
00306 const INT16 *values,
00307 int numvalues
00308 ) {
00309 memcpy(&m_buffer[offset],values,numvalues*sizeof(INT16));
00310 #ifdef BYTEORDER_HiLo
00311 SwapBytes(reinterpret_cast<INT16*>(&m_buffer[offset]),numvalues);
00312 #endif
00313 }
00314
00316 void PutUINT16 (
00317 int offset,
00318 UINT16 value
00319 ) {
00320 #ifdef BYTEORDER_HiLo
00321 SwapBytes(value);
00322 #endif
00323 memcpy(&m_buffer[offset],&value,sizeof(UINT16));
00324 }
00325
00327 void PutUINT16 (
00328 int offset,
00329 const UINT16 *values,
00330 int numvalues
00331 ) {
00332 memcpy(&m_buffer[offset],values,numvalues*sizeof(UINT16));
00333 #ifdef BYTEORDER_HiLo
00334 SwapBytes(reinterpret_cast<UINT16*>(&m_buffer[offset]),numvalues);
00335 #endif
00336 }
00337
00339 void PutINT32 (
00340 int offset,
00341 INT32 value
00342 ) {
00343 #ifdef BYTEORDER_HiLo
00344 SwapBytes(value);
00345 #endif
00346 memcpy(&m_buffer[offset],&value,sizeof(INT32));
00347 }
00348
00350 void PutINT32 (
00351 int offset,
00352 const INT32 *values,
00353 int numvalues
00354 ) {
00355 memcpy(&m_buffer[offset],values,numvalues*sizeof(INT32));
00356 #ifdef BYTEORDER_HiLo
00357 SwapBytes(reinterpret_cast<INT32*>(&m_buffer[offset]),numvalues);
00358 #endif
00359 }
00360
00362 void PutUINT32 (
00363 int offset,
00364 UINT32 value
00365 ) {
00366 #ifdef BYTEORDER_HiLo
00367 SwapBytes(value);
00368 #endif
00369 memcpy(&m_buffer[offset],&value,sizeof(UINT32));
00370 }
00371
00373 void PutUINT32 (
00374 int offset,
00375 const UINT32 *values,
00376 int numvalues
00377 ) {
00378 memcpy(&m_buffer[offset],values,numvalues*sizeof(UINT32));
00379 #ifdef BYTEORDER_HiLo
00380 SwapBytes(reinterpret_cast<UINT32*>(&m_buffer[offset]),numvalues);
00381 #endif
00382 }
00383
00385 void PutFloat (
00386 int offset,
00387 float value
00388 ) {
00389 #ifdef BYTEORDER_HiLo
00390 SwapBytes(value);
00391 #endif
00392 memcpy(&m_buffer[offset],&value,sizeof(float));
00393 }
00394
00396 void PutFloat (
00397 int offset,
00398 const float *values,
00399 int numvalues
00400 ) {
00401 memcpy(&m_buffer[offset],values,numvalues*sizeof(float));
00402 #ifdef BYTEORDER_HiLo
00403 SwapBytes(reinterpret_cast<float*>(&m_buffer[offset]),numvalues);
00404 #endif
00405 }
00406
00408 void PutDouble (
00409 int offset,
00410 double value
00411 ) {
00412 #ifdef BYTEORDER_HiLo
00413 SwapBytes(value);
00414 #endif
00415 memcpy(&m_buffer[offset],&value,sizeof(double));
00416 }
00417
00419 void PutDouble (
00420 int offset,
00421 const double *values,
00422 int numvalues
00423 ) {
00424 memcpy(&m_buffer[offset],values,numvalues*sizeof(double));
00425 #ifdef BYTEORDER_HiLo
00426 SwapBytes(reinterpret_cast<double*>(&m_buffer[offset]),numvalues);
00427 #endif
00428 }
00429
00433 template <typename _TT> void PutComposite (
00434 int offset,
00435 _TT value
00436 ) {
00437 #ifdef BYTEORDER_HiLo
00438 SwapBytes(value);
00439 #endif
00440 memcpy(&m_buffer[offset],&value,sizeof(_TT));
00441 }
00442
00446 template <typename _TT> void PutComposite (
00447 int offset,
00448 const _TT *values,
00449 int numvalues
00450 ) {
00451 memcpy(&m_buffer[offset],values,numvalues*sizeof(_TT));
00452 #ifdef BYTEORDER_HiLo
00453 SwapBytes(reinterpret_cast<_TT*>(&m_buffer[offset]),numvalues);
00454 #endif
00455 }
00456
00457 };
00458
00459
00460
00464 class RECORDBUFFER_MSBFIRST : public RECORDBUFFER {
00465 public:
00466
00468 INT16 GetINT16 (
00469 int offset
00470 ) {
00471 #ifdef BYTEORDER_LoHi
00472 return ((static_cast<INT16>(m_buffer[offset+0]) << 8) + m_buffer[offset+1]);
00473 #else
00474 return ((static_cast<INT16>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00475 #endif
00476 }
00477
00479 void GetINT16 (
00480 int offset,
00481 INT16 *values,
00482 int numvalues
00483 ) {
00484 memcpy(values,&m_buffer[offset],numvalues*sizeof(INT16));
00485 #ifdef BYTEORDER_LoHi
00486 SwapBytes(values,numvalues);
00487 #endif
00488 }
00489
00491 UINT16 GetUINT16 (
00492 int offset
00493 ) {
00494 #ifdef BYTEORDER_LoHi
00495 return ((static_cast<UINT16>(m_buffer[offset+0]) << 8) + m_buffer[offset+1]);
00496 #else
00497 return ((static_cast<UINT16>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00498 #endif
00499 }
00500
00502 void GetUINT16 (
00503 int offset,
00504 UINT16 *values,
00505 int numvalues
00506 ) {
00507 memcpy(values,&m_buffer[offset],numvalues*sizeof(UINT16));
00508 #ifdef BYTEORDER_LoHi
00509 SwapBytes(values,numvalues);
00510 #endif
00511 }
00512
00514 INT32 GetINT32 (
00515 int offset
00516 ) {
00517 #ifdef BYTEORDER_LoHi
00518 return ((static_cast<INT32>(m_buffer[offset+0]) << 24) + (static_cast<INT32>(m_buffer[offset+1]) << 16) + (static_cast<INT32>(m_buffer[offset+2]) << 8) + m_buffer[offset+3]);
00519 #else
00520 return ((static_cast<INT32>(m_buffer[offset+3]) << 24) + (static_cast<INT32>(m_buffer[offset+2]) << 16) + (static_cast<INT32>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00521 #endif
00522 }
00523
00525 void GetINT32 (
00526 int offset,
00527 INT32 *values,
00528 int numvalues
00529 ) {
00530 memcpy(values,&m_buffer[offset],numvalues*sizeof(INT32));
00531 #ifdef BYTEORDER_LoHi
00532 SwapBytes(values,numvalues);
00533 #endif
00534 }
00535
00537 UINT32 GetUINT32 (
00538 int offset
00539 ) {
00540 #ifdef BYTEORDER_LoHi
00541 return ((static_cast<UINT32>(m_buffer[offset+0]) << 24) + (static_cast<UINT32>(m_buffer[offset+1]) << 16) + (static_cast<UINT32>(m_buffer[offset+2]) << 8) + m_buffer[offset+3]);
00542 #else
00543 return ((static_cast<UINT32>(m_buffer[offset+3]) << 24) + (static_cast<UINT32>(m_buffer[offset+2]) << 16) + (static_cast<UINT32>(m_buffer[offset+1]) << 8) + m_buffer[offset+0]);
00544 #endif
00545 }
00546
00548 void GetUINT32 (
00549 int offset,
00550 UINT32 *values,
00551 int numvalues
00552 ) {
00553 memcpy(values,&m_buffer[offset],numvalues*sizeof(UINT32));
00554 #ifdef BYTEORDER_LoHi
00555 SwapBytes(values,numvalues);
00556 #endif
00557 }
00558
00560 float GetFloat (
00561 int offset
00562 ) {
00563 float value;
00564 memcpy(&value,&m_buffer[offset],sizeof(float));
00565 #ifdef BYTEORDER_LoHi
00566 SwapBytes(value);
00567 #endif
00568 return (value);
00569 }
00570
00572 void GetFloat (
00573 int offset,
00574 float *values,
00575 int numvalues
00576 ) {
00577 memcpy(values,&m_buffer[offset],numvalues*sizeof(float));
00578 #ifdef BYTEORDER_LoHi
00579 SwapBytes(values,numvalues);
00580 #endif
00581 }
00582
00584 double GetDouble (
00585 int offset
00586 ) {
00587 double value;
00588 memcpy(&value,&m_buffer[offset],sizeof(double));
00589 #ifdef BYTEORDER_LoHi
00590 SwapBytes(value);
00591 #endif
00592 return (value);
00593 }
00594
00596 void GetDouble (
00597 int offset,
00598 double *values,
00599 int numvalues
00600 ) {
00601 memcpy(values,&m_buffer[offset],numvalues*sizeof(double));
00602 #ifdef BYTEORDER_LoHi
00603 SwapBytes(values,numvalues);
00604 #endif
00605 }
00606
00610 template <typename _TT> void GetComposite (
00611 int offset,
00612 _TT& value
00613 ) const {
00614 memcpy(&value,&m_buffer[offset],sizeof(_TT));
00615 #ifdef BYTEORDER_LoHi
00616 SwapBytes(value);
00617 #endif
00618 return;
00619 }
00620
00624 template <typename _TT> void GetComposite (
00625 int offset,
00626 _TT *values,
00627 int numvalues
00628 ) const {
00629 memcpy(values,&m_buffer[offset],numvalues*sizeof(float));
00630 #ifdef BYTEORDER_LoHi
00631 SwapBytes(values,numvalues);
00632 #endif
00633 }
00634
00636 void PutINT16 (
00637 int offset,
00638 INT16 value
00639 ) {
00640 #ifdef BYTEORDER_LoHi
00641 SwapBytes(value);
00642 #endif
00643 memcpy(&m_buffer[offset],&value,sizeof(INT16));
00644 }
00645
00647 void PutINT16 (
00648 int offset,
00649 const INT16 *values,
00650 int numvalues
00651 ) {
00652 memcpy(&m_buffer[offset],values,numvalues*sizeof(INT16));
00653 #ifdef BYTEORDER_LoHi
00654 SwapBytes(reinterpret_cast<INT16*>(&m_buffer[offset]),numvalues);
00655 #endif
00656 }
00657
00659 void PutUINT16 (
00660 int offset,
00661 UINT16 value
00662 ) {
00663 #ifdef BYTEORDER_LoHi
00664 SwapBytes(value);
00665 #endif
00666 memcpy(&m_buffer[offset],&value,sizeof(UINT16));
00667 }
00668
00670 void PutUINT16 (
00671 int offset,
00672 const UINT16 *values,
00673 int numvalues
00674 ) {
00675 memcpy(&m_buffer[offset],values,numvalues*sizeof(UINT16));
00676 #ifdef BYTEORDER_LoHi
00677 SwapBytes(reinterpret_cast<UINT16*>(&m_buffer[offset]),numvalues);
00678 #endif
00679 }
00680
00682 void PutINT32 (
00683 int offset,
00684 INT32 value
00685 ) {
00686 #ifdef BYTEORDER_LoHi
00687 SwapBytes(value);
00688 #endif
00689 memcpy(&m_buffer[offset],&value,sizeof(INT32));
00690 }
00691
00693 void PutINT32 (
00694 int offset,
00695 const INT32 *values,
00696 int numvalues
00697 ) {
00698 memcpy(&m_buffer[offset],values,numvalues*sizeof(INT32));
00699 #ifdef BYTEORDER_LoHi
00700 SwapBytes(reinterpret_cast<INT32*>(&m_buffer[offset]),numvalues);
00701 #endif
00702 }
00703
00705 void PutUINT32 (
00706 int offset,
00707 UINT32 value
00708 ) {
00709 #ifdef BYTEORDER_LoHi
00710 SwapBytes(value);
00711 #endif
00712 memcpy(&m_buffer[offset],&value,sizeof(UINT32));
00713 }
00714
00716 void PutUINT32 (
00717 int offset,
00718 const UINT32 *values,
00719 int numvalues
00720 ) {
00721 memcpy(&m_buffer[offset],values,numvalues*sizeof(UINT32));
00722 #ifdef BYTEORDER_LoHi
00723 SwapBytes(reinterpret_cast<UINT32*>(&m_buffer[offset]),numvalues);
00724 #endif
00725 }
00726
00728 void PutFloat (
00729 int offset,
00730 float value
00731 ) {
00732 #ifdef BYTEORDER_LoHi
00733 SwapBytes(value);
00734 #endif
00735 memcpy(&m_buffer[offset],&value,sizeof(float));
00736 }
00737
00739 void PutFloat (
00740 int offset,
00741 const float *values,
00742 int numvalues
00743 ) {
00744 memcpy(&m_buffer[offset],values,numvalues*sizeof(float));
00745 #ifdef BYTEORDER_LoHi
00746 SwapBytes(reinterpret_cast<float*>(&m_buffer[offset]),numvalues);
00747 #endif
00748 }
00749
00751 void PutDouble (
00752 int offset,
00753 double value
00754 ) {
00755 #ifdef BYTEORDER_LoHi
00756 SwapBytes(value);
00757 #endif
00758 memcpy(&m_buffer[offset],&value,sizeof(double));
00759 }
00760
00762 void PutDouble (
00763 int offset,
00764 const double *values,
00765 int numvalues
00766 ) {
00767 memcpy(&m_buffer[offset],values,numvalues*sizeof(double));
00768 #ifdef BYTEORDER_LoHi
00769 SwapBytes(reinterpret_cast<double*>(&m_buffer[offset]),numvalues);
00770 #endif
00771 }
00772
00776 template <typename _TT> void PutComposite (
00777 int offset,
00778 _TT value
00779 ) {
00780 #ifdef BYTEORDER_LoHi
00781 SwapBytes(value);
00782 #endif
00783 memcpy(&m_buffer[offset],&value,sizeof(_TT));
00784 }
00785
00789 template <typename _TT> void PutComposite (
00790 int offset,
00791 const _TT *values,
00792 int numvalues
00793 ) {
00794 memcpy(&m_buffer[offset],values,numvalues*sizeof(_TT));
00795 #ifdef BYTEORDER_LoHi
00796 SwapBytes(reinterpret_cast<_TT*>(&m_buffer[offset]),numvalues);
00797 #endif
00798 }
00799
00800 };
00801
00802
00803
00804 #endif // INC_MI32_RECORDBUFFER_H