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

📄 generic.h

📁 一个完整的桌面日历程序
💻 H
字号:
// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																					-
// - File:			generic.h.																															-
// -																																					-
// - Contents: 		To supply generic and global functions.																								-
// -																																					-
// - Purpose:  		-																																	-
// -																																					-
// - Remarks:    	-																																	-
// -																																					-
// - Originator: 	Michael Mogensen, MM-IT Consult 2003.																								-
// -																																					-
// - Compiler:		MS Visual C++ ver6.0.																											    -
// -																																					-
// - Period:		00.00.00 - 00.00.00.																											    -
// -																																					-
// - Version:		1.80. 																																-
// -																																					-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Header(s).																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
#pragma once

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Miscellaneous.																																		-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// - Global(s).																																			-
// ------------------------------------------------------------------------------------------------------------------------------------------------------
template <class T>
inline const T Abs(const T &X)
// Return absoulte value of X.
{ T Y = X < (T)0 ? -X : X; return Y; }

template <class T>
inline const T& Const_Assign(const T &operand, T value)
// Assign non-const value to const operand.
{ return(*const_cast<T*>(&operand) = value); }

template <class T>
inline const T& Const_MM(const T &operand)
// Dec. const operand with 1.
{ return(*const_cast<T*>(&operand) = operand - (T)1); }

template <class T>
inline const T& Const_PP(const T &operand)
// Inc. const operand with 1.
{ return(*const_cast<T*>(&operand) = operand + (T)1); }

template <class T>
inline const T Max(const T op_A, const T op_B)
// Return biggest object.
{ return(op_A > op_B ? op_A : op_B); }

template <class T>
inline const T Min(const T op_A, const T op_B)
// Return smallest object.
{ return(op_A < op_B ? op_A : op_B); }

template <class T>
inline const int Random(const T Lower, const T Upper)
// Random number generator. Return random number between Lower and Upper.
{
	static bool bCalled = false;
	if(!bCalled)
	{
		::srand((unsigned)::time(NULL));
		bCalled = true;
	}
	const double dRand = (double)::rand() / (double)RAND_MAX; // Something in [0, 1].
	const double dLower = (double)Lower;
	const double dUpper = (double)Upper + 1.0;
	const double dDelta = (dUpper - dLower) * dRand;
	const T Chosen = (T)(dLower + dDelta);
	return Chosen;
}

template <class T>
inline const void SetCyclic(T &A, const T B, T C, T D)
// Cyclic increse or decrese A with the value of B to fit the interval [C, D].
{
	if((int)B == 0)
		return;
	T Diff = C;
	A -= Diff;
	C -= Diff;
	D -= ((int)Diff - 1);
	A += B;
	A %= D;
	if((int)A < 0)
		A = D + A;
	A += Diff;
}

template <class T>
inline const void SetLinear(T &A, const T B, const T C)
// Linear increse or decrese A with the value of B until C are reached.
{
	A += B;
	const int iB = (int)B;
	if((iB > 0 && A > C) || (iB < 0 && A < C))
		A = C;
}

template <class T>
inline const void SwapObjects(T &A, T &B)
// Swap two values of type T.
{
	T A_= A;
	A = B;
	B = A_;
}

template <class T_A, class T_B>
inline const void SupressObjectInDescreteRange(T_A &X, const T_B Bottom, const T_B Top, const T_B Step)
// Force object to be in the set [Bottom, Top], but in a descrete way.
{
	if(X > Top)
		X = Top;
	else
		if(X < Bottom)
			X = Bottom;
		else
			X = (T_A)(Bottom + Step * (((T_A)X - Bottom) / Step));
}

template <class T_A, class T_B>
inline const void SupressObjectInRange(T_A &X, const T_B Bottom, const T_B Top)
// Force object to be in the set [Bottom, Top].
{
	if(X > Top)
		X = Top;
	else
		if(X < Bottom)
			X = Bottom;
}

template <class T_A, class T_B>
inline const T_A SupressedObjectInRange(const T_A &X, const T_B Bottom, const T_B Top)
// Return object in the set [Bottom, Top].
{
	if(X > Top)
		return Top;
	else
		if(X < Bottom)
			return Bottom;
		else
			return X;
}

// ------------------------------------------------------------------------------------------------------------------------------------------------------
// -																																				  	-
// ------------------------------------------------------------------------------------------------------------------------------------------------------

// 0. Data. (alphabetical).
// 1. Object. (alphabetical).
// 2. Event's. (alphabetical).
// 3.0. Menu choice. (menu order).
// 3.1. Menu choice, enablers. (menu order).
// 4. Slaves. (alphabetical).
// 5. Other. (alphabetical).


⌨️ 快捷键说明

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