Commit 97ea98e8 authored by Will Schroeder's avatar Will Schroeder
Browse files

ENH: Added comments

parent a615ca49
......@@ -15,9 +15,13 @@ without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Class for performing common math operations (e.g., dot, cross products)
//
// .NAME vlByteSwap - perform machine dependent byte swapping
// .SECTION Description
// vlByteSwap is used by other classes to perform machine dependent byte
// swapping. Byte swapping is often used when reading or writing binary
// files.
// .EXAMPLE STLRead.cc
#ifndef __vlByteSwap_hh
#define __vlByteSwap_hh
......
......@@ -44,7 +44,7 @@ public:
// special operators
vlFloatArray &operator=(const vlFloatArray& fa);
vlFloatArray &operator+=(const vlFloatArray& fa);
void operator+=(const vlFloatArray& fa);
void operator+=(const float f) {this->InsertNextValue(f);};
float& operator[](const int i);
......
......@@ -13,9 +13,12 @@ written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Dynamic, self adjusting integer array
//
// .NAME vlIntArray - dynamic, self adjusting integer array
// .SECTION Description
// vlIntArray is an array of integer numbers. It provides methods
// for insertion and retrieval of integer values, and will
// automatically resize itself to hold new data.
#ifndef __vlIntArray_h
#define __vlIntArray_h
......@@ -25,43 +28,96 @@ class vlIntArray : public vlObject
{
public:
vlIntArray():Array(NULL),Size(0),MaxId(-1),Extend(1000) {};
int Allocate(const int sz, const int ext=1000);
void Initialize();
int Allocate(const int sz, const int ext);
vlIntArray(const int sz, const int ext);
vlIntArray(const int sz, const int ext=1000);
vlIntArray(const vlIntArray& ia);
~vlIntArray();
int GetValue(const int id) {return this->Array[id];};
int *GetPtr(const int id) {return this->Array + id;};
vlIntArray &InsertValue(const int id, const int i)
{if ( id >= this->Size ) this->Resize(id);
this->Array[id] = i;
if ( id > this->MaxId ) this->MaxId = id;
return *this;
}
int InsertNextValue(const int i)
{this->InsertValue (++this->MaxId,i); return this->MaxId;};
virtual char *GetClassName() {return "vlIntArray";};
void PrintSelf(ostream& os, vlIndent indent);
// access/insertion methods
int GetValue(const int id);
int *GetPtr(const int id);
vlIntArray &InsertValue(const int id, const int i);
int InsertNextValue(const int i);
// special operators
vlIntArray &operator=(const vlIntArray& ia);
void operator+=(const vlIntArray& ia);
void operator+=(const int i) {this->InsertNextValue(i);};
// operator[] can be used on both left and right side of expression;
// Note: if used on lh side, user's responsibility to do range checking
int& operator[](const int i)
{if (i > this->MaxId) this->MaxId = i; return this->Array[i];};
void Squeeze() {this->Resize (this->MaxId+1);};
int GetSize() {return this->Size;};
int GetMaxId() {return this->MaxId;};
int *GetArray() {return this->Array;};
void Reset() {this->MaxId = -1;};
virtual char *GetClassName() {return "vlIntArray";};
void PrintSelf(ostream& os, vlIndent indent);
int& operator[](const int i);
// miscellaneous methods
void Squeeze();
int GetSize();
int GetMaxId();
int *GetArray();
void Reset();
private:
int *Array; // pointer to data
int Size; // allocated size of data
int MaxId; // maximum index inserted thus iar
int MaxId; // maximum index inserted thus far
int Extend; // grow array by this point
int *Resize(const int sz); // function to resize data
};
#endif
// Description:
// Get the data at a particular index.
inline int vlIntArray::GetValue(const int id) {return this->Array[id];};
// Description:
// Get the address of a particular data index.
inline int *vlIntArray::GetPtr(const int id) {return this->Array + id;};
// Description:
// Insert data at a specified position in the array.
inline vlIntArray& vlIntArray::InsertValue(const int id, const int i)
{
if ( id >= this->Size ) this->Resize(id);
this->Array[id] = i;
if ( id > this->MaxId ) this->MaxId = id;
return *this;
}
// Description:
// Insert data at the end of the array. Return its location in the array.
inline int vlIntArray::InsertNextValue(const int i)
{
this->InsertValue (++this->MaxId,i);
return this->MaxId;
}
// Description:
// Does insert or get (depending on location on lhs or rhs of statement). Does
// not do automatic resizing - user's responsibility to range check.
inline int& vlIntArray::operator[](const int i)
{
if (i > this->MaxId) this->MaxId = i;
return this->Array[i];
}
// Description:
// Resize object to just fit data requirement. Reclaims extra memory.
inline void vlIntArray::Squeeze() {this->Resize (this->MaxId+1);};
// Description:
// Get the allocated size of the object in terms of number of data items.
inline int vlIntArray::GetSize() {return this->Size;};
// Description:
// Returning the maximum index of data inserted so far.
inline int vlIntArray::GetMaxId() {return this->MaxId;};
// Description:
// Get the pointer to the array. Useful for interfacing to C or
// FORTRAN routines.
inline int *vlIntArray::GetArray() {return this->Array;};
// Description:
// Reuse the memory allocated by this object. Objects appears like
// no data has been previously inserted.
inline void vlIntArray::Reset() {this->MaxId = -1;};
#endif
......@@ -17,6 +17,8 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "ByteSwap.hh"
// Description:
// Swap four byte word.
void vlByteSwap::Swap4(char *mem_ptr1)
{
char one_byte;
......
......@@ -43,7 +43,7 @@ void vlFloatArray::Initialize()
}
// Description:
//
// Construct with specified storage and extend value.
vlFloatArray::vlFloatArray(const int sz, const int ext)
{
this->Size = ( sz > 0 ? sz : 1);
......@@ -96,7 +96,7 @@ vlFloatArray& vlFloatArray::operator=(const vlFloatArray& fa)
// Description:
// Append one array onto the end of this array.
vlFloatArray& vlFloatArray::operator+=(const vlFloatArray& fa)
void vlFloatArray::operator+=(const vlFloatArray& fa)
{
int i, sz;
......@@ -107,8 +107,6 @@ vlFloatArray& vlFloatArray::operator+=(const vlFloatArray& fa)
this->Array[this->MaxId+1+i] = fa.Array[i];
}
this->MaxId += fa.MaxId + 1;
return *this;
}
void vlFloatArray::PrintSelf(ostream& os, vlIndent indent)
......
......@@ -13,13 +13,11 @@ written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
//
// Dynamic, self adjusting integer array
//
//
#include "IntArray.hh"
vlIntArray::Allocate(const int sz, const int ext)
// Description:
// Allocate memory for this array. Delete old storage if present.
int vlIntArray::Allocate(const int sz, const int ext)
{
if ( this->Array != NULL ) delete [] this->Array;
......@@ -31,6 +29,8 @@ vlIntArray::Allocate(const int sz, const int ext)
return 1;
}
// Description:
// Release storage and reset array to initial state.
void vlIntArray::Initialize()
{
if ( this->Array != NULL )
......@@ -42,6 +42,8 @@ void vlIntArray::Initialize()
this->MaxId = -1;
}
// Description:
// Construct with specified storage and extend value.
vlIntArray::vlIntArray(const int sz, const int ext)
{
this->Size = ( sz > 0 ? sz : 1);
......@@ -55,6 +57,8 @@ vlIntArray::~vlIntArray()
delete [] this->Array;
}
// Description:
// Construct array from another array. Copy each element of other array.
vlIntArray::vlIntArray(const vlIntArray& ia)
{
int i;
......@@ -69,6 +73,8 @@ vlIntArray::vlIntArray(const vlIntArray& ia)
}
// Description:
// Deep copy of another array.
vlIntArray& vlIntArray::operator=(const vlIntArray& ia)
{
int i;
......@@ -88,9 +94,8 @@ vlIntArray& vlIntArray::operator=(const vlIntArray& ia)
return *this;
}
//
// Copy on write if used by more than one object
//
// Description:
// Append one array onto the end of this array.
void vlIntArray::operator+=(const vlIntArray& ia)
{
int i, sz;
......@@ -102,7 +107,6 @@ void vlIntArray::operator+=(const vlIntArray& ia)
this->Array[this->MaxId+1+i] = ia.Array[i];
}
this->MaxId += ia.MaxId + 1;
}
void vlIntArray::PrintSelf(ostream& os, vlIndent indent)
......@@ -119,7 +123,7 @@ void vlIntArray::PrintSelf(ostream& os, vlIndent indent)
}
//
// Private function does "reallocate"
// Protected function does "reallocate"
//
int *vlIntArray::Resize(const int sz)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment