Scythe-1.0.3
|
00001 /* 00002 * Scythe Statistical Library 00003 * Copyright (C) 2000-2002 Andrew D. Martin and Kevin M. Quinn; 00004 * 2002-present Andrew D. Martin, Kevin M. Quinn, and Daniel 00005 * Pemstein. All Rights Reserved. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * under the terms of the GNU General Public License as published by 00009 * Free Software Foundation; either version 2 of the License, or (at 00010 * your option) any later version. See the text files COPYING 00011 * and LICENSE, distributed with this source code, for further 00012 * information. 00013 * -------------------------------------------------------------------- 00014 * scythestat/defs.h 00015 */ 00016 00029 /* Doxygen main page text */ 00146 #ifndef SCYTHE_DEFS_H 00147 #define SCYTHE_DEFS_H 00148 00149 /* In many functions returning matrices, we want to allow the user to 00150 * get a matrix of any style, but want to work with concretes inside 00151 * the function, for efficiency. This macro originally contained the 00152 * code: 00153 * 00154 * if (_STYLE_ == View) \ 00155 * return Matrix<_TYPE_,_ORDER_,View>(_MATRIX_); \ 00156 * else \ 00157 * return _MATRIX_; 00158 * 00159 * to convert to View before return if necessary. Of course, this is 00160 * completely redundant, since the copy constructor gets called on 00161 * return anyway, so the body of the macro was replaced with a simple 00162 * return. If we change our minds down the road about how to handle 00163 * these returns, code changes will be centered on this macro. 00164 */ 00165 #define SCYTHE_VIEW_RETURN(_TYPE_, _ORDER_, _STYLE_, _MATRIX_) \ 00166 return _MATRIX_; 00167 00168 /* Some macros to do bounds checking for iterator accesses. The first 00169 * two are only called by the [] operator in the random access 00170 * iterator. The third macro handles everything for checks on simple 00171 * current iterator location accesses. 00172 */ 00173 #define SCYTHE_ITER_CHECK_POINTER_BOUNDS(POINTER) \ 00174 { \ 00175 SCYTHE_CHECK_30(POINTER >= start_ + size_ || POINTER < start_, \ 00176 scythe_bounds_error, "Iterator access (offset " \ 00177 << offset_ << ") out of matrix bounds") \ 00178 } 00179 00180 #define SCYTHE_ITER_CHECK_OFFSET_BOUNDS(OFFSET) \ 00181 { \ 00182 SCYTHE_CHECK_30(OFFSET >= size_, scythe_bounds_error, \ 00183 "Iterator access (offset " << offset_ << ") out of matrix bounds")\ 00184 } 00185 00186 #define SCYTHE_ITER_CHECK_BOUNDS() \ 00187 { \ 00188 if (M_STYLE != Concrete || M_ORDER != ORDER) { \ 00189 SCYTHE_ITER_CHECK_OFFSET_BOUNDS(offset_); \ 00190 } else { \ 00191 SCYTHE_ITER_CHECK_POINTER_BOUNDS(pos_); \ 00192 } \ 00193 } 00194 00202 namespace scythe { 00203 00215 enum matrix_order { Col, Row }; 00216 00232 enum matrix_style { Concrete, View }; 00233 00250 struct all_elements { 00251 } const _ = {}; 00252 00253 // A little helper method to see if more col-order or row-order. 00254 // Tie breaks towards col. 00255 template <matrix_order o1, matrix_order o2, matrix_order o3> 00256 bool maj_col() 00257 { 00258 if ((o1 == Col && o2 == Col) || 00259 (o1 == Col && o3 == Col) || 00260 (o2 == Col && o3 == Col)) 00261 return true; 00262 return false; 00263 } 00264 00265 template <matrix_order o1, matrix_order o2, matrix_order o3, 00266 matrix_order o4> 00267 bool maj_col() 00268 { 00269 if ((o1 == Col && o2 == Col) || 00270 (o1 == Col && o3 == Col) || 00271 (o1 == Col && o4 == Col) || 00272 (o2 == Col && o3 == Col) || 00273 (o2 == Col && o4 == Col) || 00274 (o3 == Col && o4 == Col)) 00275 return true; 00276 return false; 00277 } 00278 } // end namespace scythe 00279 00280 #endif /* SCYTHE_ERROR_H */