templatelib.hh

来自「Motion JPEG编解码器源代码」· HH 代码 · 共 106 行

HH
106
字号
#ifndef __TEMPLATELIB_H__#define __TEMPLATELIB_H__// This file (C) 2004 Steven Boswell.  All rights reserved.// Released to the public under the GNU General Public License.// See the file COPYING for more information.// Basic template definitions.enum { g_knBitsPerByte = 8 };	// The number of bits per byte.  (I doubt this'll ever change,	// but just in case, we make a constant for it.)// Calcluate the size of an array of items.#define ARRAYSIZE(CLASS,COUNT) ((size_t)(&(((CLASS*)0)[COUNT])))// A template function class that declares two classes are the same.template <class FIRST, class SECOND>class Ident{public:	const SECOND &operator() (const FIRST &a_rOther) const  		{ return a_rOther; }};// A generic pair.template <class FIRST, class SECOND>class Pair{public:	Pair()		: m_oFirst (FIRST()), m_oSecond (SECOND()) {}	Pair (const FIRST &a_oFirst, const SECOND &a_oSecond)		: m_oFirst (a_oFirst), m_oSecond (a_oSecond) {}	template <class U, class V> Pair (const Pair<U,V> &a_rOther)		: m_oFirst (a_rOther.m_oFirst), m_oSecond (a_rOther.m_oSecond)			{}		FIRST m_oFirst;	SECOND m_oSecond;};// A template function that returns the first item (i.e. in a Pair).template <class PAIR, class FIRST>class Select1st{public:	const FIRST &operator() (const PAIR &a_rOther) const		{ return a_rOther.m_oFirst; }};// A standard less-than comparison object.template <class TYPE>class Less{public:	bool operator() (const TYPE &a_rLeft, const TYPE &a_rRight) const		{ return a_rLeft < a_rRight; }};// A general absolute-value function.template <class TYPE>TYPEAbsoluteValue (const TYPE &a_rValue){	return (a_rValue < TYPE (0)) ? (-a_rValue) : a_rValue;}// A general minimum-value function.template <class TYPE>TYPEMin (const TYPE &a_rLeft, const TYPE &a_rRight){	return (a_rLeft < a_rRight) ? a_rLeft : a_rRight;}// A general maximum-value function.template <class TYPE>TYPEMax (const TYPE &a_rLeft, const TYPE &a_rRight){	return (a_rLeft > a_rRight) ? a_rLeft : a_rRight;}#endif // __TEMPLATELIB_H__

⌨️ 快捷键说明

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