defs.h

Go to the documentation of this file.
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 */
00127 #ifndef SCYTHE_DEFS_H
00128 #define SCYTHE_DEFS_H
00129 
00130 /* In many functions returning matrices, we want to allow the user to
00131  * get a matrix of any style, but want to work with concretes inside
00132  * the function, for efficiency.  This macro originally contained the
00133  * code:
00134  * 
00135  * if (_STYLE_ == View)                                                \
00136  *   return Matrix<_TYPE_,_ORDER_,View>(_MATRIX_);                     \
00137  * else                                                                \
00138  *   return _MATRIX_;
00139  *
00140  * to convert to View before return if necessary.  Of course, this is
00141  * completely redundant, since the copy constructor gets called on
00142  * return anyway, so the body of the macro was replaced with a simple
00143  * return.  If we change our minds down the road about how to handle
00144  * these returns, code changes will be centered on this macro.
00145  */
00146 #define SCYTHE_VIEW_RETURN(_TYPE_, _ORDER_, _STYLE_, _MATRIX_)        \
00147     return _MATRIX_;
00148 
00149 /* Some macros to do bounds checking for iterator accesses.  The first
00150  * two are only called by the [] operator in the random access
00151  * iterator.  The third macro handles everything for checks on simple
00152  * current iterator location accesses.
00153  */
00154 #define SCYTHE_ITER_CHECK_POINTER_BOUNDS(POINTER)                     \
00155 {                                                                     \
00156   SCYTHE_CHECK_30(POINTER >= start_ + size_ || POINTER < start_,      \
00157     scythe_bounds_error, "Iterator access (offset "                   \
00158     << offset_ << ") out of matrix bounds")                           \
00159 }
00160 
00161 #define SCYTHE_ITER_CHECK_OFFSET_BOUNDS(OFFSET)                       \
00162 {                                                                     \
00163   SCYTHE_CHECK_30(OFFSET >= size_, scythe_bounds_error,               \
00164     "Iterator access (offset " << offset_ << ") out of matrix bounds")\
00165 }
00166 
00167 #define SCYTHE_ITER_CHECK_BOUNDS()                                    \
00168 {                                                                     \
00169   if (M_STYLE != Concrete || M_ORDER != ORDER) {                      \
00170     SCYTHE_ITER_CHECK_OFFSET_BOUNDS(offset_);                         \
00171   } else {                                                            \
00172     SCYTHE_ITER_CHECK_POINTER_BOUNDS(pos_);                           \
00173   }                                                                   \
00174 }
00175 
00183 namespace scythe {
00184 
00196   enum matrix_order { Col, Row };
00197 
00213   enum matrix_style { Concrete, View };
00214 
00231   struct all_elements {
00232   } const _ = {};
00233 
00234   // A little helper method to see if more col-order or row-order.
00235   // Tie breaks towards col.
00236   template <matrix_order o1, matrix_order o2, matrix_order o3>
00237   bool maj_col()
00238   {
00239     if ((o1 == Col && o2 == Col) ||
00240         (o1 == Col && o3 == Col) ||
00241         (o2 == Col && o3 == Col))
00242       return true;
00243     return false;
00244   }
00245 
00246   template <matrix_order o1, matrix_order o2, matrix_order o3,
00247             matrix_order o4>
00248   bool maj_col()
00249   {
00250     if ((o1 == Col && o2 == Col) ||
00251         (o1 == Col && o3 == Col) ||
00252         (o1 == Col && o4 == Col) ||
00253         (o2 == Col && o3 == Col) ||
00254         (o2 == Col && o4 == Col) ||
00255         (o3 == Col && o4 == Col))
00256       return true;
00257     return false;
00258   }
00259 }  // end namespace scythe
00260 
00261 #endif /* SCYTHE_ERROR_H */

Generated on Wed Aug 15 14:53:35 2007 for Scythe-1.0.2 by  doxygen 1.4.7