📄 eluint.cpp
字号:
#include <fstream.h>
#include "elemdbm.h"
#include "elements.h"
// class information
const char* mgcUint::description = "I";
const int mgcUint::size = sizeof(unsigned int);
const int mgcUint::type = mgcUint::Register();
// error handling
int mgcUint::verbose = 0;
unsigned mgcUint::error = 0;
const unsigned mgcUint::registration_failed = 0x00000001;
const char* mgcUint::message[1] = {
"registration failed"
};
//===========================================================================
int mgcUint::
Register ()
{
static int first_time = 1;
if ( first_time == 0 )
return mgcUint::type;
first_time = 0;
mgcElementDBM::ElementRecord er;
er.addrtype = &mgcUint::type;
er.description = mgcUint::description;
er.memory_size = mgcUint::size;
er.packed_size = mgcUint::size;
er.input = mgcUint::Input;
er.output = mgcUint::Output;
#ifdef __WIN32__
er.reverse = mgcElementDBM::Reverse4;
#else
er.reverse = mgcElementDBM::Reverse2;
#endif
er.pack = 0;
er.unpack = 0;
er.convert_to = 0;
if ( mgcUint::type != mgcElementDBM::AddType(er) ) {
Report(registration_failed);
return -1;
}
mgcElementDBM::AddConvert
(mgcUint::type,mgcChar::type,mgcUint::ToChar);
mgcElementDBM::AddConvert
(mgcUint::type,mgcUchar::type,mgcUint::ToUchar);
mgcElementDBM::AddConvert
(mgcUint::type,mgcShort::type,mgcUint::ToShort);
mgcElementDBM::AddConvert
(mgcUint::type,mgcUshort::type,mgcUint::ToUshort);
mgcElementDBM::AddConvert
(mgcUint::type,mgcInt::type,mgcUint::ToInt);
mgcElementDBM::AddConvert
(mgcUint::type,mgcUint::type,mgcUint::ToUint);
mgcElementDBM::AddConvert
(mgcUint::type,mgcLong::type,mgcUint::ToLong);
mgcElementDBM::AddConvert
(mgcUint::type,mgcUlong::type,mgcUint::ToUlong);
mgcElementDBM::AddConvert
(mgcUint::type,mgcFloat::type,mgcUint::ToFloat);
mgcElementDBM::AddConvert
(mgcUint::type,mgcDouble::type,mgcUint::ToDouble);
return mgcUint::type;
}
//---------------------------------------------------------------------------
mgcUint& mgcUint::
operator= (const mgcElement& element)
{
mgcElementDBM::EFconvert convert =
mgcElementDBM::record[element.type].convert_to[type];
if ( convert )
convert(1,element.data,data);
return *this;
}
//---------------------------------------------------------------------------
#define CONVERSION(ToType,type) \
void mgcUint:: \
ToType (int quantity, void* src, void* trg) \
{ \
register unsigned int* psrc = (unsigned int*)src; \
register type* ptrg = (type*)trg; \
for (register long i = 0; i < quantity; i++, psrc++, ptrg++) \
*ptrg = (type)(*psrc); \
}
CONVERSION(ToChar,char);
CONVERSION(ToUchar,unsigned char);
CONVERSION(ToShort,short);
CONVERSION(ToUshort,unsigned short);
CONVERSION(ToInt,int);
CONVERSION(ToUint,unsigned int);
CONVERSION(ToLong,long);
CONVERSION(ToUlong,unsigned long);
CONVERSION(ToFloat,float);
CONVERSION(ToDouble,double);
//---------------------------------------------------------------------------
int mgcUint::
Number (unsigned single_error)
{
int result;
for (result = -1; single_error; single_error >>= 1)
result++;
return result;
}
//---------------------------------------------------------------------------
void mgcUint::
Report (unsigned single_error)
{
if ( mgcElement::verbose || mgcUint::verbose )
cout << "mgcUint: " << message[Number(single_error)] << endl;
else
ofstream("eluint.err",ios::out|ios::app)
<< "mgcUint: " << message[Number(single_error)] << endl;
error |= single_error;
}
//---------------------------------------------------------------------------
void mgcUint::
Report (ostream& ostr)
{
for (unsigned single_error = 1; single_error; single_error <<= 1)
if ( error & single_error )
ostr << "mgcUint: " << message[Number(single_error)] << endl;
error = 0;
}
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -