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

📄 elrgb5.cpp

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

// class information
const char* mgcRGB5::description = "x";
const int mgcRGB5::size = sizeof(unsigned short);
const int mgcRGB5::type = mgcRGB5::Register();

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

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

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

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

	mgcElementDBM::AddConvert
		(mgcRGB5::type,mgcUshort::type,mgcRGB5::ToUshort);
	mgcElementDBM::AddConvert
		(mgcRGB5::type,mgcUint::type,mgcRGB5::ToUint);
	mgcElementDBM::AddConvert
		(mgcRGB5::type,mgcUlong::type,mgcRGB5::ToUlong);
	mgcElementDBM::AddConvert
		(mgcRGB5::type,mgcRGB5::type,mgcRGB5::ToUshort);

	return mgcRGB5::type;
}
//---------------------------------------------------------------------------
mgcRGB5& mgcRGB5::
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 mgcRGB5::                                                              \
ToType (int quantity, void* src, void* trg)                                 \
{                                                                           \
	register unsigned short* psrc = (unsigned short*)src;                   \
	register type* ptrg = (type*)trg;                                       \
	for (register long i = 0; i < quantity; i++, psrc++, ptrg++)            \
		*ptrg = (type)(*psrc);                                              \
}

CONVERSION(ToUshort,unsigned short);
CONVERSION(ToUint,unsigned int);
CONVERSION(ToUlong,unsigned long);
//---------------------------------------------------------------------------
int mgcRGB5::
Number (unsigned single_error)
{
	int result;
	for (result = -1; single_error; single_error >>= 1)
		result++;
	return result;
}
//---------------------------------------------------------------------------
void mgcRGB5::
Report (unsigned single_error)
{
	if ( mgcElement::verbose || mgcRGB5::verbose )
		cout << "mgcRGB5: " << message[Number(single_error)] << endl;
	else
		ofstream("elint.err",ios::out|ios::app)
			 << "mgcRGB5: " << message[Number(single_error)] << endl;
        	
    error |= single_error;
}
//---------------------------------------------------------------------------
void mgcRGB5::
Report (ostream& ostr)
{
	for (unsigned single_error = 1; single_error; single_error <<= 1)
		if ( error & single_error )
			ostr << "mgcRGB5: " << message[Number(single_error)] << endl;

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

⌨️ 快捷键说明

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