elchar.h

来自「《3D游戏引擎设计》的源码」· C头文件 代码 · 共 77 行

H
77
字号
#ifndef ELCHAR_H
#define ELCHAR_H

#include "element.h"

class mgcChar : public mgcElement
{
// object information
public:
	mgcChar () : mgcElement(type,&value)
		{ value = 0; }
	mgcChar (const char& _value) : mgcElement(type,&value)
		{ value = _value; }
	mgcChar (const mgcElement& element) : mgcElement(type,&value)
		{ *this = element; }

	operator char () const
		{ return value; }

	mgcChar& operator= (char _value)
		{ value = _value;  return *this; }
	mgcChar& operator= (const mgcChar& derived)
		{ value = derived.value;  return *this; }
	mgcChar& operator= (const mgcElement& element);

	int operator== (const mgcChar& derived) const
		{ return value == derived.value; }
	int operator!= (const mgcChar& derived) const
		{ return value != derived.value; }

	friend istream& operator>> (istream& istr, mgcChar& derived)
		{ return istr >> derived.value; }
	friend ostream& operator<< (ostream& ostr, const mgcChar& derived)
		{ return ostr << derived.value; }

private:
	char value;

// class information
public:
	static const int type;
	static const char* description;
	static const int size;

	static int Register ();
	static void ToChar   (int quantity, void* src, void* trg);
	static void ToUchar  (int quantity, void* src, void* trg);
	static void ToShort  (int quantity, void* src, void* trg);
	static void ToUshort (int quantity, void* src, void* trg);
	static void ToInt    (int quantity, void* src, void* trg);
	static void ToUint   (int quantity, void* src, void* trg);
	static void ToLong   (int quantity, void* src, void* trg);
	static void ToUlong  (int quantity, void* src, void* trg);
	static void ToFloat  (int quantity, void* src, void* trg);
	static void ToDouble (int quantity, void* src, void* trg);

	static void Input (istream& istr, void* trg)
		{ istr >> *(char*)trg; }
	static void Output (ostream& ostr, const void* src)
		{ ostr << *(char*)src; }

// error handling
public:
	static int verbose;
	static unsigned error;
	static void Report (ostream& ostr);
private:
	static const unsigned registration_failed;
	static const char* message[1];
	static int Number (unsigned single_error);
	static void Report (unsigned single_error);
};

static int mgcChar_key = mgcChar::Register();

#endif

⌨️ 快捷键说明

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