Files
TeslaRel410/CODE/RP/MUNGA/TABLE.HPP
T
CydandClaude Fable 5 fdd9ac9d97 Initial import: Tesla Release 4.10 (Tesla:BattleTech & Tesla:Red Planet)
Archival snapshot of the Virtual World Entertainment Tesla cockpit
software, 1994-1996: MUNGA engine and L4 pod layer source (Borland
C++ 5.0), BT/RP game code, and game content (models, audio, maps,
gauges, Division renderer data). Includes third-party libraries:
Division dVS/DPL graphics, HMI SOS audio, WATTCP networking.

Files are preserved byte-for-byte (.gitattributes disables all
line-ending conversion). README.md documents the layout, target
hardware, and toolchain.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-02 13:21:58 -05:00

560 lines
14 KiB
C++

//===========================================================================//
// File: table.hh //
// Project: MUNGA Brick: Connection Library //
// Contents: Interface specification for Tables //
//---------------------------------------------------------------------------//
// Date Who Modification //
// -------- --- ---------------------------------------------------------- //
// 09/30/94 ECH Initial coding. //
// 11/02/94 JMA Made compatible with SGI CC, merged with iterator //
// 11/03/94 ECH Made compatible with BC4.0 //
// 11/05/94 JMA Made compatible with GNU C++ //
// 12/12/94 ECH Changed release handling //
//---------------------------------------------------------------------------//
// Copyright (C) 1994-1995, Virtual World Entertainment, Inc. //
// PROPRIETARY AND CONFIDENTIAL //
//===========================================================================//
#if !defined(TABLE_HPP)
# define TABLE_HPP
# if !defined(SRTSKT_HPP)
# include <srtskt.hpp>
# endif
# if !defined(MEMBLOCK_HPP)
# include <memblock.hpp>
# endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableEntry ~~~~~~~~~~~~~~~~~~~~~~~~~~~
class Table;
class TableEntry:
public Link
{
public:
TableEntry(
Table *table,
Plug *plug
);
~TableEntry();
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableEntryOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define TABLEENTRY_MEMORYBLOCK_ALLOCATION (100)
template <class V> class TableEntryOf:
public TableEntry
{
public:
TableEntryOf(
Table *table,
Plug *plug,
const V &value
);
~TableEntryOf();
void*
operator new(size_t);
void
operator delete(void *where);
V
GetValue()
{return value;}
V*
GetValuePointer()
{return &value;}
private:
static MemoryBlock
*allocatedMemory;
static CollectionSize
allocationCount;
V value;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableEntryOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class V> MemoryBlock*
TableEntryOf<V>::allocatedMemory = NULL;
template <class V> CollectionSize
TableEntryOf<V>::allocationCount = 0;
template <class V>
TableEntryOf<V>::TableEntryOf(
Table *table,
Plug *plug,
const V &value
):
TableEntry(table, plug)
{
this->value = value;
}
template <class V>
TableEntryOf<V>::~TableEntryOf()
{
}
template <class V> void*
TableEntryOf<V>::operator new(size_t)
{
Verify(allocationCount >= 0);
if (allocationCount++ == 0)
{
allocatedMemory =
new MemoryBlock(
sizeof(TableEntryOf<V>),
TABLEENTRY_MEMORYBLOCK_ALLOCATION,
TABLEENTRY_MEMORYBLOCK_ALLOCATION,
"TableEntryOf"
);
Register_Object(allocatedMemory);
}
Verify(allocationCount < INT_MAX);
Check(allocatedMemory);
return allocatedMemory->New();
}
template <class V> void
TableEntryOf<V>::operator delete(void *where)
{
Check(allocatedMemory);
allocatedMemory->Delete(where);
if (--allocationCount == 0)
{
Unregister_Object(allocatedMemory);
delete allocatedMemory;
allocatedMemory = NULL;
}
Verify(allocationCount >= 0);
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ Table ~~~~~~~~~~~~~~~~~~~~~~~~~~~
const IteratorPosition TableNullIndex = -1;
class Table:
public SortedSocket
{
friend class TableEntry;
friend class TableIterator;
public:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Public interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
//
//--------------------------------------------------------------------
// Constructor, Destructor and testing
//--------------------------------------------------------------------
//
Table(
Node *node,
Logical has_unique_entries
);
~Table();
Logical
TestInstance() const;
static Logical
TestClass();
static Logical
ProfileClass();
protected:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Protected interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
void
AddImplementation(Plug *plug);
void
AddValueImplementation(
Plug *plug,
const void *value
);
Plug
*FindImplementation(const void *value);
private:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Private interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
virtual TableEntry
*MakeTableEntry(
Plug *plug,
const void *value
);
virtual int
CompareTableEntries(
TableEntry *entry1,
TableEntry *entry2
);
virtual int
CompareValueToTableEntry(
const void *value,
TableEntry *entry
);
void
AddTableEntry(TableEntry *entry);
void
SortTableEntries();
IteratorPosition
SearchForValue(const void *value);
IteratorPosition
SearchForTableEntry(TableEntry *entry);
void
RemoveNthTableEntry(CollectionSize index);
//
//--------------------------------------------------------------------
// Private data
//--------------------------------------------------------------------
//
TableEntry **array;
CollectionSize numItems;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T, class V> class TableOf:
public Table
{
public:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Public interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
TableOf(
Node *node,
Logical has_unique_entries
);
~TableOf();
//
//--------------------------------------------------------------------
// Socket methods (see Socket for full listing)
//--------------------------------------------------------------------
//
void
AddValue(
T plug,
const V &value
)
{AddValueImplementation(plug, &value);}
T
Find(const V &value)
{return (T)FindImplementation(&value);}
private:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Private interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
TableEntry*
MakeTableEntry(
Plug *plug,
const void *value
)
{return new TableEntryOf<V>(this, plug, *(V*)value);}
int
CompareTableEntries(
TableEntry *entry1,
TableEntry *entry2
);
int
CompareValueToTableEntry(
const void *value,
TableEntry *entry
);
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T, class V>
TableOf<T, V>::TableOf(
Node *node,
Logical has_unique_entries
):
Table(
node,
has_unique_entries
)
{
}
template <class T, class V>
TableOf<T, V>::~TableOf()
{
}
#if 0
template <class T, class V> int
TableOf<T, V>::CompareTableEntries(
TableEntry *entry1,
TableEntry *entry2
)
{
V result =
(V)(Cast_Object(TableEntryOf<V>*, entry1)->GetValue() -
Cast_Object(TableEntryOf<V>*, entry2)->GetValue());
if (result == (V)0)
return 0;
return (result > (V)0) ? 1 : -1;
}
#else
template <class T, class V> int
TableOf<T, V>::CompareTableEntries(
TableEntry *entry1,
TableEntry *entry2
)
{
V *ptr1 = Cast_Object(TableEntryOf<V>*, entry1)->GetValuePointer();
V *ptr2 = Cast_Object(TableEntryOf<V>*, entry2)->GetValuePointer();
Check_Pointer(ptr1);
Check_Pointer(ptr2);
if (*ptr1 == *ptr2)
return 0;
else
return ((*ptr1 > *ptr2) ? 1 : -1);
}
#endif
#if 0
template <class T, class V> int
TableOf<T, V>::CompareValueToTableEntry(
const void *value,
TableEntry *link
)
{
Check_Pointer(value);
V result =
(V)(*(V*)value - Cast_Object(TableEntryOf<V>*, link)->GetValue());
if (result == (V)0)
return 0;
return (result > (V)0) ? 1 : -1;
}
#else
template <class T, class V> int
TableOf<T, V>::CompareValueToTableEntry(
const void *value,
TableEntry *link
)
{
Check_Pointer(value);
V *ptr = Cast_Object(TableEntryOf<V>*, link)->GetValuePointer();
Check_Pointer(ptr);
if (*(V*)value == *ptr)
return 0;
else
return (*(V*)value > *ptr) ? 1 : -1;
}
#endif
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableIterator ~~~~~~~~~~~~~~~~~~~~~~~~~~~
class TableIterator:
public SortedIterator
{
public:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Public interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
//
//--------------------------------------------------------------------
// Constructors, Destructor and testing
//--------------------------------------------------------------------
//
TableIterator(Table *table);
~TableIterator();
Logical
TestInstance() const;
//
//--------------------------------------------------------------------
// Iterator methods (see Iterator for full listing)
//--------------------------------------------------------------------
//
void
First();
void
Last();
void
Next();
void
Previous();
CollectionSize
GetSize();
void
Remove();
protected:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Protected interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
void*
ReadAndNextImplementation();
void*
ReadAndPreviousImplementation();
void*
GetCurrentImplementation();
void*
GetNthImplementation(CollectionSize index);
Plug*
FindImplementation(const void *value);
TableEntry*
GetCurrentEntry()
{return NthEntry(currentPosition);}
private:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Private interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
void
ReceiveMemo(
IteratorMemo memo,
void *content
);
TableEntry*
NthEntry(CollectionSize index)
#if DEBUG_LEVEL>0
;
#else
{return array[index];}
#endif
void
IncrementPosition()
{if (++currentPosition >= numItems) currentPosition = TableNullIndex;}
void
DecrementPosition()
{if (--currentPosition < 0) currentPosition = TableNullIndex;}
//
//--------------------------------------------------------------------
// Private data
//--------------------------------------------------------------------
//
TableEntry **array;
CollectionSize numItems;
IteratorPosition currentPosition;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableIteratorOf ~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T, class V> class TableIteratorOf:
public TableIterator
{
public:
//
//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Public interface
//--------------------------------------------------------------------
//--------------------------------------------------------------------
//
//
//--------------------------------------------------------------------
// Constructors and Destructor
//--------------------------------------------------------------------
//
TableIteratorOf(TableOf<T, V> *table);
TableIteratorOf(TableOf<T, V> &table);
~TableIteratorOf();
//
//--------------------------------------------------------------------
// Iterator methods (see Iterator for full listing)
//--------------------------------------------------------------------
//
T
ReadAndNext()
{return (T)ReadAndNextImplementation();}
T
ReadAndPrevious()
{return (T)ReadAndPreviousImplementation();}
T
GetCurrent()
{return (T)GetCurrentImplementation();}
T
GetNth(CollectionSize index)
{return (T)GetNthImplementation(index);}
T
Find(const V &value)
{return (T)FindImplementation(&value);}
V
GetValue()
{return Cast_Object(TableEntryOf<V>*, GetCurrentEntry())->GetValue();}
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~ TableIteratorOf templates ~~~~~~~~~~~~~~~~~~~~~~~~~~~
template <class T, class V>
TableIteratorOf<T, V>::TableIteratorOf(TableOf<T, V> *table):
TableIterator(table)
{
}
template <class T, class V>
TableIteratorOf<T, V>::TableIteratorOf(TableOf<T, V> &table):
TableIterator(&table)
{
}
template <class T, class V>
TableIteratorOf<T, V>::~TableIteratorOf()
{
}
#endif