HyperslabParameters.hpp

00001 
00002 //
00003 // $Id: HyperslabParameters.hpp,v 1.3 2007/10/08 22:22:08 werner Exp $
00004 //
00006 #ifndef __vector_HyperslabParameters_HPP
00007 #define __vector_HyperslabParameters_HPP "Created 24.08.2006 11:48:12 by werner"
00008 
00009 #include "Index.hpp"
00010 #include <typeinfo>
00011 
00012 namespace Fiber
00013 {
00014 
00033 class   HyperslabParameters
00034 {
00035 protected:
00037         index_t length;
00038         index_t stride;
00039         index_t offset;
00040         index_t shift;
00041         // how many elements at the end are not allowed to be iterable
00042         index_t cropped;
00043 
00044 public:
00046         HyperslabParameters(index_t Length, index_t Stride, index_t Offset) throw()
00047         : length(Length)
00048         , stride(Stride)
00049         , offset(Offset)
00050         , shift(0)
00051         , cropped(0)
00052         {}
00053 
00055         HyperslabParameters(const HyperslabParameters&H) throw()
00056         : length(H.length)
00057         , stride(H.stride)
00058         , offset(H.offset)
00059         , shift(H.shift)
00060         , cropped(H.cropped)
00061         {}
00062 
00065         HyperslabParameters(index_t i, const HyperslabParameters&H) throw()
00066         : length(H.length)
00067         , stride(H.stride)
00068         , offset(H.offset)
00069         , shift (H.shift+i)
00070         , cropped(H.cropped)
00071         {}
00072 
00076         index_t getLength() const throw()
00077         {
00078                 return length;
00079         }
00080 
00081         index_t getOffset() const throw()
00082         {
00083                 return offset;
00084         }
00085 
00086         index_t getStride() const throw()
00087         {
00088                 return stride;
00089         }
00090 
00091         index_t getShift() const throw()
00092         {
00093                 return shift;
00094         }
00095 
00096         index_t getCropped() const throw()
00097         {
00098                 return cropped;
00099         }
00100 
00108         bool isSeparatedCompound() const throw()
00109         {
00110                 return stride == 1;
00111         }
00112 
00116         int multiplicity() const throw()
00117         {
00118                 if (stride==1)
00119                 {
00120                         assert(offset>0);
00121                         return length / offset; 
00122                 }
00123                 else
00124                         return stride;
00125         }
00126         
00130         index_t maxcount() const throw()
00131         {
00132                 if (stride==1)
00133                 {
00134                         return offset - shift;
00135                 }
00136                 else
00137                 {
00138                         assert(stride>0); 
00139                         return length / stride - shift;
00140                 }
00141         }
00142 
00147         index_t count() const throw()
00148         {
00149                 return maxcount() - cropped;
00150         }
00151 
00156         void setCount(index_t size)  throw()
00157         {
00158                 cropped = maxcount() - size; 
00159                 if (cropped<0)
00160                         cropped=0;
00161         }
00162 
00172         index_t getIndex(index_t i, int c) const throw()
00173         {
00174                 return (shift + i)*stride + c*offset;
00175         }
00176 
00177 
00178         // MSVC                          GCC                                              SGI C++
00179 #if     defined(_IOSTREAM_) || defined(_GLIBCXX_OSTREAM) || defined(_CPP_IOSTREAM) || defined(__SGI_STL_IOSTREAM)
00180 #define ITERATOR_OSTREAM
00181          friend std::ostream&operator<<(std::ostream&os, const HyperslabParameters&It)
00182          {
00183                  os << "{shift=" << It.shift << ", stride=" << It.stride << ", offset=" << It.offset 
00184                     << ", length=" << It.length << ", cropped=" << It.cropped
00185                     <<  "} => count=" << It.count() << ", multiplicity=" << It.multiplicity() << "\n"
00186                    ;
00187                  return os;
00188          }
00189 #endif
00190 
00191         HyperslabParameters&getHyperslabParameters() throw()
00192         {
00193                 return *this;
00194         }
00195 
00196         const HyperslabParameters&getHyperslabParameters() const throw()
00197         {
00198                 return *this;
00199         }
00200 };
00201 
00202 
00203 } /* namespace Fiber */ 
00204 
00205 #endif /* __vector_HyperslabParameters_HPP */
00206