Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

DCFbytepack.cpp

Go to the documentation of this file.
00001 // DCFbytepack.cpp
00002 //////////////////////////////////////////////////////////////////////
00003 //          (c) Copyright 2001-2002 Brown Deer Technology, LLC. 
00004 //                        All rights reserved.              
00005 //////////////////////////////////////////////////////////////////////
00006 
00007 #ifdef USE_STD
00008 #include <iostream>
00009 #include <string>
00010 #include <algorithm>
00011 using namespace std;
00012 #else
00013 #include <iostream.h>
00014 #include <string.h>
00015 #include <algorithm.h>
00016 #endif
00017 
00018 #include "DCFbytepack.h"
00019 
00020 //bytepack::bytepack( const int sizemax ) 
00021 //  : _sizemax(sizemax), _size(0)
00022 //{
00023 //   _pt = new char[_sizemax+1];
00024 //   _pt[0] = 0;
00025 //};
00026 
00027 //bytepack::~bytepack() { delete [] _pt; _pt = 0; };
00028 
00029 bytepack& bytepack::operator()( const char data, const int size ) 
00030 {
00031    for( int i = 0; i <= size; i++ ) _pt[i] = 0;
00032    _pt[0] = data;
00033    _size = 1;
00034    return *this;
00035 };
00036 
00037 bytepack& bytepack::operator()( const int data0, const int size ) {
00038    int data = data0;
00039    char* ptdata = (char*)(&data);
00040    for(int i=0;i<=size;i++) _pt[i] = 0;
00041 #ifdef STORM_RS6000_AIX
00042    for(int i = 0; i < min( size, int(sizeof(int)) ); i++ ) {
00043       _pt[i] = ptdata[ sizeof(int) - 1 - i ]; 
00044    }
00045    _size = size;
00046 #endif
00047 #ifdef STORM_x86_LINUX
00048    for( int i = 0; i < min( size, int(sizeof(int)) ); i++ ) {
00049       _pt[i] = ptdata[i]; 
00050    }
00051    _size = size;
00052 #endif
00053 #ifdef STORM_SGI_IRIX
00054    for( int i = 0; i < min( size, int(sizeof(int)) ); i++ ) {
00055       _pt[i] = ptdata[ sizeof(int) - 1 - i ]; 
00056    }
00057    _size = size;
00058 #endif
00059    return *this;
00060 };
00061 
00062 bytepack& bytepack::operator()( const float data0, const int size ) {
00063    float data = data0;
00064    char* ptdata = (char*)(&data);
00065    for( int i = 0; i <= size; i++ ) _pt[i] = 0;
00066 #ifdef STORM_RS6000_AIX
00067    for( int i = 0; i < min( size, int(sizeof(float)) ); i++ ) {
00068       _pt[i] = ptdata[i]; 
00069    }
00070    _size = size;
00071 #endif
00072 #ifdef STORM_x86_LINUX
00073    for( int i = 0 ; i < min( size, int(sizeof(float)) ); i++ ) {
00074       _pt[i] = ptdata[ sizeof(float) - 1 - i ]; 
00075    }
00076    _size = size;
00077 #endif
00078 #ifdef STORM_SGI_IRIX
00079    for( i = 0; i < min( size, int(sizeof(float)) ); i++ ) {
00080       _pt[i] = ptdata[i]; 
00081    }
00082    _size = size;
00083 #endif
00084 //#ifdef STORM_DEBUG
00085 //   cout << "bytepack::operator(): float : data0 _size _pt[] "
00086 //      << data0 << ' ' << _size << ' ';
00087 //   for(i=0;i<_size;i++) { cout << int( (unsigned char)(_pt[i]) ) << ' '; }
00088 //   cout << '\n';
00089 //#endif
00090    return *this;
00091 };
00092 
00093 bytepack& bytepack::operator()( const double data0, const int size ) {
00094    double data = data0;
00095    char* ptdata = (char*)(&data);
00096    for( int i = 0; i <= size; i++ ) _pt[i] = 0;
00097 #ifdef STORM_RS6000_AIX
00098    for( int i = 0; i < min( size, int(sizeof(double)) ); i++ ) {
00099       _pt[i] = ptdata[i]; 
00100    }
00101    _size = size;
00102 #endif
00103 #ifdef STORM_x86_LINUX
00104    for( int i = 0; i < min( size, int(sizeof(double)) ); i++ ) {
00105       _pt[i] = ptdata[ sizeof(double) - 1 - i ]; 
00106    }
00107    _size = size;
00108 #endif
00109 #ifdef STORM_SGI_IRIX
00110    for( int i = 0; i < min( size, int(sizeof(double)) ); i++ ) {
00111       _pt[i] = ptdata[i]; 
00112    }
00113    _size = size;
00114 #endif
00115    return *this;
00116 };
00117 
00118 bytepack::operator char() { return char(_pt[0]); }
00119 
00120 bytepack::operator int() {
00121    int data;
00122    char* ptdata = (char*)(&data);
00123    if ((_pt[_size-1]&0x80)) {
00124       for( int i = 0; i < sizeof(int); i++ ) ptdata[i] = 0xFF; 
00125    }
00126    else {
00127       for( int i = 0; i < sizeof(int); i++ ) ptdata[i] = 0x00; 
00128    }
00129 #ifdef STORM_RS6000_AIX
00130    for( int i = 0; i < min( _size, int(sizeof(int)) ); i++ ) { 
00131       ptdata[ sizeof(int) - 1 - i ] = _pt[i]; 
00132    }
00133 #endif
00134 #ifdef STORM_x86_LINUX
00135    for( int i = 0; i < min( _size, int(sizeof(int)) ); i++ ) { 
00136       ptdata[i] = _pt[i]; 
00137    }
00138 #endif
00139 #ifdef STORM_SGI_IRIX
00140    for( int i = 0; i < min( _size, int(sizeof(int)) ); i++ ) { 
00141       ptdata[ sizeof(int) - 1 - i ] = _pt[i]; 
00142    }
00143 #endif
00144    return data;
00145 };
00146 
00147 bytepack::operator float() {
00148    float data = 0;
00149    char* ptdata = (char*)(&data);
00150 #ifdef STORM_RS6000_AIX
00151    for( int i = 0; i < min( _size, int(sizeof(float)) ); i++ ) { 
00152       ptdata[i] = _pt[i]; 
00153    }
00154 #endif
00155 #ifdef STORM_x86_LINUX
00156    for( int i = 0; i < min( _size, int(sizeof(float)) ); i++ ) { 
00157       ptdata[ sizeof(float) - 1 - i ] = _pt[i];
00158    }
00159 #endif
00160 #ifdef STORM_SGI_IRIX
00161    for( int i = 0; i < min( _size, int(sizeof(float)) ); i++ ) { 
00162       ptdata[i] = _pt[i]; 
00163    }
00164 #endif
00165    return data;
00166 };
00167 
00168 bytepack::operator double() {
00169    double data=0;
00170    char* ptdata = (char*)(&data);
00171 #ifdef STORM_RS6000_AIX
00172    for( int i = 0; i < min( _size, int(sizeof(double)) ); i++ ) { 
00173       ptdata[i] = _pt[i]; 
00174    }
00175 #endif
00176 #ifdef STORM_x86_LINUX
00177    for( int i = 0; i < min( _size, int(sizeof(double)) ); i++ ) { 
00178       ptdata[ sizeof(double) - 1 - i ] = _pt[i];
00179    }
00180 #endif
00181 #ifdef STORM_SGI_IRIX
00182    for( int i = 0; i < min( _size, int(sizeof(double)) ); i++ ) { 
00183       ptdata[i] = _pt[i]; 
00184    }
00185 #endif
00186    return data;
00187 };
00188 
00189 ostream& operator << ( ostream& os, bytepack& bp ) {
00190    for( int i = 0; i < bp._size; i++ ) { os.put( bp._pt[i] ); }
00191 //#ifdef STORM_DEBUG
00192 //   cout << "bytepack:operator<<: ";
00193 //   for(i=0;i<bp._size;i++) { cout << int( (unsigned char)(bp._pt[i]) ); }
00194 //   cout << '\n';
00195 //#endif
00196    return os;
00197 };
00198 
00199 istream& operator >> ( istream& is, bytepack& bp ) {
00200    for( int i = 0; i < bp._size; i++ ) { is.get( bp._pt[i] ); }
00201    bp._pt[ bp._size ] = 0;
00202    return is;
00203 };
00204 

Generated on Mon May 31 21:38:43 2004 for SR2k4 Assembler by doxygen 1.3.6