vtf-logo

IndexGridData1.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 #ifndef _included_IndexGridData1_h
00004 #define _included_IndexGridData1_h
00005 
00012 #include "generic.h"
00013 
00014 /*
00015 *************************************************************************
00016 *                                                                       *
00017 * Define some looping constructs for GridData.  Note that these will    *
00018 * take either an array or a region as the second argument.              *
00019 *                                                                       *
00020 * Copy the region extents into a local constant integer to aid the      *
00021 * compiler in doing some loop optimizations.                            *
00022 *                                                                       *
00023 *************************************************************************
00024 */
00025 
00026 #ifndef for_1
00027 #define for_1(i, r, s) {                                                \
00028    const int name2(i,_L) = (((r).lower(0)+((r).lower(0)<0?-s(0)+1:s(0)-1))/s(0))*s(0);      \
00029    const int name2(i,_U) = (r).upper(0);                                \
00030    const int name2(si,_S) = (s(0));                                     \
00031    for (register int i = name2(i,_L); i <= name2(i,_U); i+=name2(si,_S)) {
00032 #endif
00033 #ifndef end_for
00034 #define end_for } }
00035 #endif
00036 
00037 /*
00038 *************************************************************************
00039 *                                                                       *
00040 * These macros provide simple access to ``fast indexing'' from C++.     *
00041 * Current C++ compilers do not do a good job of optimizing C++ loops    *
00042 * with array access.  Using these macros should speed up loops by a     *
00043 * factor of about three.  Note that we still use the Fortran indexing   *
00044 * convention.                                                           *
00045 *                                                                       *
00046 * These macros should be used as follows:                               *
00047 *                                                                       *
00048 *       BeginFastIndex1(a, double);                                     *
00049 *       for_1(i, a)                                                     *
00050 *          FastIndex1(a, i) = 0.0;                                      *
00051 *       end_for                                                         *
00052 *       EndFastIndex1(a);                                               *
00053 *                                                                       *
00054 *************************************************************************
00055 */
00056 
00057 #ifndef BeginFastIndex1
00058 #define BeginFastIndex1(a, b, d, type) {                                \
00059 const int   name2(a,_B)  = b.bottom();                                  \
00060 type *const name2(a,_D)  = d;                                           \
00061 const int   name2(a,_s0) = b.stepsize(0)
00062 #define FastIndex1(a, i)                                                \
00063 name2(a,_D)[name2(a,_B)+((i)/name2(a,_s0))]
00064 #define EndFastIndex1(a) }
00065 #endif
00066 
00067 #endif

Generated on Fri Aug 24 13:00:29 2007 for AMROC's Hierachical Data Structures - by  doxygen 1.4.7