Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

marray.C

Go to the documentation of this file.
00001 //----------------------------------------------------------------------
00002 //               The Motion Strategy Library (MSL)
00003 //----------------------------------------------------------------------
00004 //
00005 // Copyright (c) 1998-2000 Iowa State University and Steve LaValle.  
00006 // All Rights Reserved.
00007 // 
00008 // Permission to use, copy, and distribute this software and its 
00009 // documentation is hereby granted free of charge, provided that 
00010 // (1) it is not a component of a commercial product, and 
00011 // (2) this notice appears in all copies of the software and
00012 //     related documentation. 
00013 // 
00014 // Iowa State University and the author make no representations
00015 // about the suitability or fitness of this software for any purpose.  
00016 // It is provided "as is" without express or implied warranty.
00017 //----------------------------------------------------------------------
00018 
00019 #include "marray.h"
00020 
00021 #include <LEDA/REDEFINE_NAMES.h>
00022 
00023 
00024 template<class E> MultiArray<E>::MultiArray(const array<int> &dims, 
00025                                             const E &x) {
00026   int i,offset;
00027 
00028   MaxSize = 10000000; // Maximum allowable size
00029   Dimensions = dims;
00030   Dimension = dims.size();
00031   
00032   Offsets = array<int>(Dimension);
00033 
00034   offset = 1;
00035   for (i = 0; i < Dimension; i++) {
00036     Offsets[i] = offset;
00037     offset *= Dimensions[i];
00038   }
00039 
00040   Size = offset;
00041 
00042   if (Size <= MaxSize) {
00043     // Make the LEDA array to hold all of the data
00044     A = array<E>(Size);
00045     A.init(x); // Write the value x to all elements
00046   }
00047   else {
00048     cout << "Size " << Size << " exceeds MaxSize limit " << MaxSize << "\n";
00049     exit(-1);
00050   }
00051 }
00052 
00053 
00054 template<class E> MultiArray<E>::MultiArray(const array<int> &dims) {
00055   E x;
00056 
00057   MultiArray(dims,x);
00058 }
00059 
00060 
00061 template<class E> inline E& MultiArray<E>::operator[](const array<int> 
00062                                                       &indices) {
00063   int i,index;
00064 
00065   index = indices[0];
00066 
00067   for (i = 1; i < Dimension; i++) {
00068     index += indices[i]*Offsets[i];
00069   }
00070 
00071   return A[index];
00072 }
00073 
00074 #include <LEDA/UNDEFINE_NAMES.h>
00075 
Motion Strategy Library


Web page maintained by Steve LaValle
Partial support provided by NSF CAREER Award IRI-970228 (LaValle), Honda Research, and Iowa State University.
Contributors: Anna Atramentov, Peng Cheng, James Kuffner, Steve LaValle, and Libo Yang.