www.pudn.com > cad3d.zip > VectorSpec.h


/*************************************************************************** 
                          VectorSpec.h  -  description 
                             ------------------- 
    begin                : 2002 
    copyright            : (C) 2002 by Martin Marinov 
    email                : martin_marinov@hotmail.com 
 ***************************************************************************/ 
 
/*************************************************************************** 
 *                                                                         * 
 *   This program is free software; you can redistribute it and/or modify  * 
 *   it under the terms of the GNU General Public License as published by  * 
 *   the Free Software Foundation; either version 2 of the License, or     * 
 *   (at your option) any later version.                                   * 
 *                                                                         * 
 ***************************************************************************/ 
 
//#ifndef __Vector_h__ 
//#define __Vector_h__ 
 
#ifndef __VectorSpec_h__ 
#define __VectorSpec_h__ 
 
#include  
#include  
#include "defs.h" 
#include "Check.h" 
#include "3DMath/MathDefs.h" 
 
//basic unroll(not used, and fixed...) and set(used) 
////////////////////////////////////////////////////////////// 
#define UNROLL_BASIC(EXPR)\ 
	for (uint i=0; i < nDim; ++i)	EXPR(i); 
 
#define UNROLL_BASIC_OP(EXPR, OP, N)\ 
	_T& _Res = 0; \ 
	for (uint i=0; i < nDim; ++i ) _Res OP= EXPR(i); 
 
#define SET_CONSTRUCTOR_BASIC \ 
	VECTOR_CLASS_NAME (UNROLL_ARGS(ARG_CONSTREF_EXPR))	\ 
	{				 						\ 
		UNROLL_VEC(SET_EXPR); \ 
	}		 
 
#define SET_MEMBER_BASIC \ 
	void Set(UNROLL_ARGS(ARG_CONSTREF_EXPR))	\ 
	{				 						\ 
		UNROLL_VEC(SET_EXPR); \ 
	}		 
 
//Definitions 
////////////////////////////////////////////////////////////// 
#define DEFINE_VECTOR_CLASSES( n )	\ 
	typedef tmc::CVector##n##			CVector##n##i;	\ 
	typedef tmc::CVector##n##			CVector##n##u;	\ 
	typedef tmc::CVector##n##		CVector##n##f;	\ 
	typedef tmc::CVector##n##		CVector##n##d;  \ 
	typedef tmc::CVector##n##	CVector##n##r;  
 
//Dimension:	2 
////////////////////////////////////////////////////////////// 
#define DIMENSION				2 
#define	VECTOR_CLASS_NAME		CVector2 
 
#define __unroll_v2(RES, OP, EXPR)	\ 
	CHECK(RES.size() == 2);			\ 
	RES(0) OP EXPR(0);				\ 
	RES(1) OP EXPR(1);				 
 
#define	UNROLL_VEC(EXPR)		EXPR(0) EXPR(1) 
#define UNROLL_ARGS(EXPR)	\ 
	EXPR(0), EXPR(1) 
#define	UNROLL_VEC_OP(EXPR, OP) \ 
	EXPR(0) OP EXPR(1)  
#define SET_CONSTRUCTOR			SET_CONSTRUCTOR_BASIC 
#define SET_MEMBER				SET_MEMBER_BASIC 
 
#include "3DMath/Generic/Vector.h" 
 
DEFINE_VECTOR_CLASSES(2) 
 
//Dimension:	3 
////////////////////////////////////////////////////////////// 
#define DIMENSION				3 
#define	VECTOR_CLASS_NAME		CVector3 
 
#define __unroll_v3(RES, OP, EXPR)	\ 
	CHECK(RES.size() == 3);			\ 
	RES(0) OP EXPR(0);				\ 
	RES(1) OP EXPR(1);				\ 
	RES(2) OP EXPR(2);				\ 
		 
#define	UNROLL_VEC(EXPR)		EXPR(0) EXPR(1) EXPR(2) 
#define UNROLL_ARGS(EXPR)	\ 
	EXPR(0), EXPR(1), EXPR(2) 
#define	UNROLL_VEC_OP(EXPR, OP) \ 
	EXPR(0) OP EXPR(1) OP EXPR(2) 
#define SET_CONSTRUCTOR			SET_CONSTRUCTOR_BASIC 
#define SET_MEMBER				SET_MEMBER_BASIC 
 
#include "3DMath/Generic/Vector.h" 
 
DEFINE_VECTOR_CLASSES(3) 
 
 
//Dimension:	4 
////////////////////////////////////////////////////////////// 
#define DIMENSION				4 
#define	VECTOR_CLASS_NAME		CVector4 
 
#define __unroll_v4(RES, OP, EXPR)	\ 
	CHECK(RES.size() == 4);			\ 
	RES(0) OP EXPR(0);				\ 
	RES(1) OP EXPR(1);				\ 
	RES(2) OP EXPR(2);				\ 
	RES(3) OP EXPR(3);				  
 
#define	UNROLL_VEC(EXPR)		EXPR(0) EXPR(1) EXPR(2) EXPR(3) 
#define UNROLL_ARGS(EXPR)	\ 
	EXPR(0), EXPR(1), EXPR(2), EXPR(3) 
#define	UNROLL_VEC_OP(EXPR, OP) \ 
	EXPR(0) OP EXPR(1) OP EXPR(2) OP EXPR(3) 
#define SET_CONSTRUCTOR			SET_CONSTRUCTOR_BASIC 
#define SET_MEMBER				SET_MEMBER_BASIC 
 
#include "3DMath/Generic/Vector.h" 
 
DEFINE_VECTOR_CLASSES(4) 
 
#undef DEFINE_VECTOR_CLASSES 
#undef SET_MEMBER_BASIC 
#undef SET_CONSTRUCTOR_BASIC 
#undef UNROLL_BASIC_OP 
#undef UNROLL_BASIC 
 
 
 
#endif//__VectorSpec_h__