Category : C++ Source Code
Archive   : BLFMATH.ZIP
Filename : VECTOR.H
// vector.h: Fixed-length shared vector template.
// Copyright(c) 1993 Azarona Software. All rights reserved.
/////////////////////////////////////////////////////////////
#ifndef H_VECTOR
#define H_VECTOR
#include "range.h"
#include "vecptr.h"
#define INLINE
enum SliceType { SHARED, COPIED };
// Vector representation class. Private to the vector class.
template
template
class VecRep {
// WARNING: VecRep objects are meant to be allocated only
// dynamically. The only exception is null_rep, which is
// a special null version of a VecRep object. Only one
// of these should be created.
#ifdef NO_BORLAND_BUG
private:
friend class Vector
#else
public:
#endif
unsigned alloclen;
unsigned refcnt;
TYPE data[1];
VecRep(unsigned d);
void *operator new(size_t n, unsigned d);
void operator delete(void *p);
public: // So we can set up null_rep
static VecRep
VecRep();
~VecRep();
};
// You need to call this for each type of vector, to
// set up the special null VecRep object. Do it only
// once though.
#define INITNULLVEC(TYPE) VecRep
// The vector class
template
template
class Vector {
protected:
friend class Matrix
VecRep
TYPE *start; // Pointer to logical start of data
unsigned len; // Number of logical elements
unsigned stride; // Stride (offset to next logical element)
int Alloc(unsigned n);
void Bind(const Vector
void Unbind();
void NewBinding(const Vector
public:
Vector(unsigned n = 0, const TYPE *s = 0);
Vector(const Vector
Vector(const Vector
unsigned n=0, unsigned str=1, unsigned ofs=0);
~Vector();
#ifndef NO_RANGE_CHECK
unsigned CheckIndx(unsigned i) const;
#endif
// We'll provide both forms of subscripting
TYPE &operator[](unsigned i);
const TYPE &operator[](unsigned i) const;
void CopyN(const TYPE *src, unsigned n);
void Copy(const Vector
void Share(const Vector
void SetElements(const TYPE &x);
Vector
Vector
int IsNull() const;
int IsUnique() const;
Vector
int EnsureUnique();
unsigned Length() const;
unsigned Stride() const;
// Low-level hooks
VecPtr
VecPtr
};
template
INLINE VecRep
// Constructor to form a null VecRep object.
// This object should only be allocated statically.
// NOTE: TYPE's default constructor called implicitly.
{
alloclen = 1;
refcnt = 1;
}
template
INLINE Vector
// Destructor unbinds this vector from the data
// it was sharing.
{
Unbind();
}
template
INLINE TYPE &Vector
// For non-const vectors.
{
return start[CHECK(i)*stride];
}
template
INLINE const TYPE &Vector
// For const vectors.
{
return start[CHECK(i)*stride];
}
template
INLINE Vector
// Share semantics used for assignment.
{
if (this != &v) Share(v); // Note trap for assignment to self
return *this;
}
template
INLINE Vector
// Sets each element of the vector to the value x.
{
SetElements(x);
return *this;
}
template
INLINE int Vector
// Returns true if the vector references null_rep.
{
return rep == &VecRep
}
template
INLINE int Vector
// Returns true if vector has only reference to shared data,
// or the shared data is null_rep.
{
return rep->refcnt == 1 || IsNull();
}
template
INLINE unsigned Vector
// Return the logical number of elements of the vector.
{
return len;
}
template
INLINE unsigned Vector
// Return the vector's stride (ie. offset between
// each logical element.)
{
return stride;
}
template
INLINE VecPtr
// Returns a vector pointer to the beginning of
// this vector's elements.
{
return VecPtr
}
template
INLINE VecPtr
// Returns a vector pointer to the beginning of
// this vector's elements.
{
return VecPtr
}
#undef INLINE
// Whether or not we should include the non-line methods for
// our class templates here is implementation dependent.
#include "vector.mth"
#endif
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/