Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : VECPTR.H

 
Output of file : VECPTR.H contained in archive : BLFMATH.ZIP
/////////////////////////////////////////////////////////////
// vecptr.h: Vector pointer class.
// Copyright(c) 1993 Azarona Software. All rights reserved.
/////////////////////////////////////////////////////////////
#ifndef H_VECPTR
#define H_VECPTR

// NOTE: You can define ELEMENT_STRIDE to get the non-optimized
// version of the vector pointers, which don't use byte strides.

#ifndef ELEMENT_STRIDE

// This is the optimized version

template
class VecPtr {
private:
TYPE *p;
const unsigned stride;
public:
VecPtr(TYPE *t, unsigned s=1) : p(t), stride(s*sizeof(TYPE)) { }
VecPtr(const VecPtr &s) : p(s.p), stride(s.stride) { }
void operator=(const VecPtr &s) { p = s.p; }
void operator=(TYPE *t) { p = t; }
void operator++() { (char *)p += stride; }
void operator++(int) { (char *)p += stride; }
void operator+=(unsigned n) { (char *)p += stride * n; }
TYPE &operator[](unsigned i) const { return *(TYPE *)((char *)p + stride*i); }
operator TYPE *() const { return p; }
TYPE &operator *() const { return *p; }
#ifdef TYPE_IS_STRUCTURE
TYPE *operator->() const { return p; }
#endif
};

#else

// This is the unoptimized version

template
class VecPtr {
private:
TYPE *p;
const unsigned stride;
public:
VecPtr(TYPE *t, unsigned s=1) : p(t), stride(s) { }
VecPtr(const VecPtr &s) : p(s.p), stride(s.stride) { }
void operator=(const VecPtr &s) { p = s.p; }
void operator=(TYPE *t) { p = t; }
void operator++() { p += stride; }
void operator++(int) { p += stride; }
void operator+=(unsigned n) { p += stride * n; }
TYPE &operator[](unsigned i) const { return p[stride*i]; }
operator TYPE *() const { return p; }
TYPE &operator *() const { return *p; }
#ifdef TYPE_IS_STRUCTURE
TYPE *operator->() const { return p; }
#endif
};

#endif

#endif


  3 Responses to “Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : VECPTR.H

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/