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

📄 elchar.cpp

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

// class information
const char* mgcChar::description = "c";
const int mgcChar::size = sizeof(char);
const int mgcChar::type = mgcChar::Register();

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

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

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

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

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

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

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

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

⌨️ 快捷键说明

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