File: smat.def.h

package info (click to toggle)
r-cran-pcapp 1.9-73-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 800 kB
  • sloc: cpp: 5,961; ansic: 917; sh: 13; makefile: 2
file content (152 lines) | stat: -rw-r--r-- 3,112 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
    SMat - Simple Matrix Classes v0.1beta
    Copyright (C) 2011 by Heinrich Fritz (heinrich_fritz@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 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ES_SMAT_DEF_H
#define ES_SMAT_DEF_H

typedef unsigned int UINT ;
typedef UINT BOOL ;

#define FALSE 0
#define TRUE 1

#ifndef NULL
	#define NULL 0
#endif

typedef  UINT t_size ;	//	2do: use size_t instead
typedef  UINT t_count ;

#define NAI	((t_size) -1)	//	not an index

#ifdef _DEBUG
	#define ASSERT(a)	THROW(a)
#else
	#define ASSERT(a)
#endif

class SMat_EXC
{
	public:
		SMat_EXC (char const * const szDate, char const * const szFile, const int nLine)
			: m_szDate (szDate), m_szFile (szFile), m_nLine (nLine) {}
		const char * const GetDate () const { return m_szDate ; }
		const char * const GetFile () const { return m_szFile ; }
		const int GetLine () const { return m_nLine ; }

		void OnException () ;
		static void OnUException () ;

	private:
		const char * const m_szDate, * const m_szFile ;
		const int m_nLine ;
} ;

#ifdef _DEBUG
	#define TRY(C)	C
#else
	#define TRY(C)	try {C} catch (SMat_EXC exc)  { exc.OnException () ; } catch (...) { SMat_EXC::OnUException () ; }
#endif

#define THROW(a) {if (!(a)){THROW_BASE}}
#define THROW_BASE { { throw (SMat_EXC (__DATE__, __FILE__, __LINE__)) ; } }

template <class T> inline const T sm_sqr (const T &a) { return a * a ; }

template <class T> void sm_swap (T &a, T &b)	//	-> move to COP?
{
	T c (a) ;
	a = b ;
	b = c ;
}

template <class T> void sm_swap (T &a, T &b, T&temp)
{
	temp = a;
	a = b;
	b = temp ;
}

///////////////
//	min max  //	//	-> move to COP?
///////////////

template <class T> const T &sm_min (const T &a, const T &b)
{
	if (a < b)
		return a ;
	return b ;
}

template <class T> const T &sm_max (const T &a, const T &b)
{
	if (a > b)
		return a ;
	return b ;
}

template <class TA, class TB>
TA &sm_setmax_t (TA &a, const TB &b)
{
	if (a < b)
		a = b ;
	return a ;
}

template <class TA, class TB>
TA &sm_setmin_t (TA &a, const TB &b)
{
	if (a > b)
		a = b ;
	return a ;
}		

template <class TA, class TB>
BOOL sm_setmax_b (TA &a, const TB &b)
{
	if (a >= b)
		return FALSE ;
	a = b ;
	return TRUE ;
}

template <class TA, class TB>
BOOL sm_setmin_b (TA &a, const TB &b)
{
	if (a <= b)
		return FALSE; 
	a = b ;
	return TRUE ;
}

template <class TA, class TB>
void sm_setmax (TA &a, const TB &b)
{
	if (a < b)
		a = b ;
}

template <class TA, class TB>
void sm_setmin (TA &a, const TB &b)
{
	if (a > b)
		a = b ;
}


#endif	//#ifndef ES_SMAT_DEF_H