Arrays
The root code that led to Guildhall started so many years ago that C++ was not yet a settled thing. The Pink project started out using CFront, an MPW precompiler that would effect a C++ implementation by translating it to C code. Eventually we had good compilers to work with, including the CompTech compiler that Taligent worked on. At that time, standard C++ templates for arrays weren't a thing, because templates weren't a thing.
It's also true that templates can be capricious things. Taligent had some moments where the teams went template crazy, building templates on top of templates on top of templates. At one point we had a situation where a single of line of code could instantiate huge amounts of object code. As I started to implement my own version of the APIs my apps were using, working downward to the underyling HAL, I developed and debugged several simple arrays, a few pointer arrays detailed in the Primitives section and other arrays for the scalars and TString. By the time C++ standard library templates were starting to see wider usage, I had what I needed, so I didn't bother to look at that stuff. Don't fix what ain't broke. Somebody said that.
So I continued to upgrade what I already had. When I normalized the scalar types and lived through Apple's upgrade to 64 bits, I expanded the array offerings to accommodate every scalar type available. At the same time I tried to normalize the methods in each one so anything purporting to be an array would offer the same assortment of methods. Here's what those methods look like for the ulong type (unsigned 32-bit integer).
|
class TULongArray { public : // ... standard destructor and constructors TULongArray(ulong numberOfElements); TULongArray(const ulong* ulongElements,ulong numberOfElements); // ... standard static methods // TULongArray methods public : void SetToEmpty(); void GetNumberOfElements() const; ulong GetDefaultValue() const; void SetDefaultValue(ulong defaultValue) const; void FillWith(ulong value) const; void FillDefaultWith() const; void HasElement(ulong index) const; void GetElement(ulong index) const; void SetElement(ulong index,ulong value); void GetNextIndex(ulong index,ulong value); void PutElements ( TULongArray& target, ulong index, ulong numberOfElements ) const; void SetElements ( TULongArray& source, ulong sourceIndex, ulong numberOfElements, ulong targetIndex ) const; void InsertElement(ulong index,ulong value); void InsertElements ( ulong targetIndex, const TULongArray& source, ulong sourceIndex, ulong numberOfElements ); ulong RemoveElement(ulong index); void RemoveElements(ulong index,ulong numberOfElements); void RemoveAllElements(); void AppendElement(ulong value); ulong DetachElement(); void MoveElementBefore(ulong sourceIndex,ulong beforeIndex); // Sorting methods void SwapElements(ulong firstIndex,ulong secondIndex); void Sort(nbool ascending); void SortAndRemoveDuplicates(nbool ascending); void Sort(TULongArray& sorter,nbool ascending); void ApplySorter(const TULongArray& sorter); // Calculations ulong GetAverageValue(ulong startIndex,ulong limitIndex) const; ulong GetMinimumValue(ulong startIndex,ulong limitIndex) const; ulong GetMaximumValue(ulong startIndex,ulong limitIndex) const; ulong GetSum(ulong startIndex,ulong limitIndex) const; // Additional operators ulong operator[](ulong index) const; ulong& operator[](ulong index); // requires special handling // ... private member variables };
|
The methods listed above do not, of course, apply to every array class. TStringArray, for example, won't have the calculations. TNBoolArray doesn't offer the sorting as the resulting order would have so much ambiguity it would be meaningless. But where possible, every array class presents these methods.
Constructible Classes
|
Array Class
|
Named Version
|
|
Array Class
|
Named Version
|
|
TNBoolArray TSCharArray TUCharArray TSWordArray TUWordArray TSLongArray TULongArray TSHugeArray
|
TNamedNBoolArray TNamedSCharArray TNamedUCharArray TNamedSWordArray TNamedUWordArray TNamedSLongArray TNamedULongArray TNamedSHugeArray
|
|
TUHugeArray TFRealArray TFDualArray TFQuadArray TCoordArray TStringArray TLocalizerArray TTypeArray
|
TNamedUHugeArray TNamedFRealArray TNamedFDualArray TNamedFQuadArray TNamedCoordArray TDictionary TNamedLocalizerArray TCompendium
|
TDictionary of course could have been named TNamedStringArray but TDictionary seemed like the more familiar term. TCompendium is actually a named array of TDictionary objects. There are a few other templates and classes defined in this section, but they're a bit out of service due to neglect so I'm leaving them undocumented.