⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ellong.cpp

📁 3D Game Engine Design Source Code非常棒
💻 CPP
字号:
#include <fstream.h>
#include "elemdbm.h"
#include "elements.h"

// class information
const char* mgcLong::description = "l";
const int mgcLong::size = sizeof(long);
const int mgcLong::type = mgcLong::Register();

// error handling
int mgcLong::verbose = 0;
unsigned mgcLong::error = 0;
const unsigned mgcLong::registration_failed = 0x00000001;
const char* mgcLong::message[1] = {
    "registration failed"
};

//===========================================================================
int mgcLong::
Register ()
{
	static int first_time = 1;
	if ( first_time == 0 )
		return mgcLong::type;
	first_time = 0;

	mgcElementDBM::ElementRecord er;
	er.addrtype = &mgcLong::type;
	er.description = mgcLong::description;
	er.memory_size = mgcLong::size;
	er.packed_size = mgcLong::size;
	er.input = mgcLong::Input;
	er.output = mgcLong::Output;
	er.reverse = mgcElementDBM::Reverse4;
	er.pack = 0;
	er.unpack = 0;
	er.convert_to = 0;

	if ( mgcLong::type != mgcElementDBM::AddType(er) ) {
		Report(registration_failed);
		return -1;
	}

	mgcElementDBM::AddConvert
		(mgcLong::type,mgcChar::type,mgcLong::ToChar);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcUchar::type,mgcLong::ToUchar);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcShort::type,mgcLong::ToShort);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcUshort::type,mgcLong::ToUshort);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcInt::type,mgcLong::ToInt);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcUint::type,mgcLong::ToUint);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcLong::type,mgcLong::ToLong);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcUlong::type,mgcLong::ToUlong);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcFloat::type,mgcLong::ToFloat);
	mgcElementDBM::AddConvert
		(mgcLong::type,mgcDouble::type,mgcLong::ToDouble);

	return mgcLong::type;
}
//---------------------------------------------------------------------------
mgcLong& mgcLong::
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 mgcLong::                                                              \
ToType (int quantity, void* src, void* trg)                                 \
{                                                                           \
	register long* psrc = (long*)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 mgcLong::
Number (unsigned single_error)
{
	int result;
	for (result = -1; single_error; single_error >>= 1)
		result++;
	return result;
}
//---------------------------------------------------------------------------
void mgcLong::
Report (unsigned single_error)
{
	if ( mgcElement::verbose || mgcLong::verbose )
		cout << "mgcLong: " << message[Number(single_error)] << endl;
	else
		ofstream("ellong.err",ios::out|ios::app)
			 << "mgcLong: " << message[Number(single_error)] << endl;

	error |= single_error;
}
//---------------------------------------------------------------------------
void mgcLong::
Report (ostream& ostr)
{
	for (unsigned single_error = 1; single_error; single_error <<= 1)
		if ( error & single_error )
			ostr << "mgcLong: " << message[Number(single_error)] << endl;

	error = 0;
}
//===========================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -