| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401 |
- /*
- ** Command & Conquer Red Alert(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /* $Header: /CounterStrike/LINK.CPP 1 3/03/97 10:25a Joe_bostic $ */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : Command & Conquer *
- * *
- * File Name : LINK.CPP *
- * *
- * Programmer : Joe L. Bostic *
- * *
- * Start Date : 01/15/95 *
- * *
- * Last Update : January 19, 1995 [JLB] *
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * LinkClass::Add -- This object adds itself to the given list *
- * LinkClass::Add_Head -- This gadget makes itself the head of the given list. *
- * LinkClass::Add_Tail -- Add myself to the end of the given list. *
- * LinkClass::Get_Next -- Fetches the next object in list. *
- * LinkClass::Get_Prev -- Fetches previous object in linked list. *
- * LinkClass::Head_Of_List -- Finds the head of the list. *
- * LinkClass::LinkClass -- Copy constructor for linked list object. *
- * LinkClass::Remove -- Removes the specified object from the list. *
- * LinkClass::Tail_Of_List -- Scans for the object at the end of the list. *
- * LinkClass::Zap -- Forces the link pointers to NULL. *
- * LinkClass::operator= -- Assignment operator for linked list class object. *
- * LinkClass::~LinkClass -- Default destructor for linked list object. *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #include "function.h"
- #include "link.h"
- /***********************************************************************************************
- * LinkClass::LinkClass -- Copy constructor for linked list object. *
- * *
- * This copy constructor, unlike the assignment operator, doesn't have to deal with an *
- * already initialized and legal link object to the left of the "=". It merely puts the *
- * destination object into the same list as the source object. *
- * *
- * INPUT: link -- Reference to the object on the right of the "=". *
- * *
- * OUTPUT: none *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/16/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass::LinkClass(LinkClass const & link) :
- Next(0), Prev(0)
- {
- /*
- ** Add this object to the same list that the copy object
- ** resides in.
- */
- Add((LinkClass &)link);
- }
- /***********************************************************************************************
- * LinkClass::~LinkClass -- Default destructor for linked list object. *
- * *
- * This default destructor will remove the object from any linked list it may be part of. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: none *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/15/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass::~LinkClass(void)
- {
- Remove();
- }
- /***********************************************************************************************
- * LinkClass::Zap -- Forces the link pointers to NULL. *
- * *
- * This routine will "zap" out the link pointers. This is usually necessary when the link *
- * pointers start in an undefined state, but we KNOW that they aren't pointing to anything *
- * valid. In such a case it becomes necessary to zap them so that when the object is added *
- * to a list, it will be added correctly. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: none *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/19/1995 JLB : Created. *
- *=============================================================================================*/
- void LinkClass::Zap(void)
- {
- Next = 0;
- Prev = 0;
- }
- /***********************************************************************************************
- * LinkClass::operator= -- Assignment operator for linked list class object. *
- * *
- * The assignment operator makes sure that the previous and next pointers remain valid. *
- * Because this class only consists of pointers, the assignment operator doesn't actually *
- * transfer any data from the source object. It merely makes the destination object part *
- * of the same list as the source object. In essence, this is transferring information *
- * but not the actual values. *
- * *
- * If the destination object is already part of another list, it is removed from that list *
- * before being added to the source object's list. This ensures that either list remains *
- * in a valid condition. *
- * *
- * INPUT: link -- The object to the right of the "=" operator. *
- * *
- * OUTPUT: Returns a reference to the rightmost object -- per standard assignment rules. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/16/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass & LinkClass::operator = (LinkClass const & link)
- {
- if (&link == this) return(*this);
- Remove();
- Add((LinkClass &)link);
- return(*this);
- }
- /***********************************************************************************************
- * LinkClass::Get_Next -- Fetches the next object in list. *
- * *
- * This routine will return with a pointer to the next object in the list. If there are *
- * no more objects, then NULL is returned. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: Returns with pointer to next object in list or NULL if at end of list. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/15/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass * LinkClass::Get_Next(void) const
- {
- return(Next);
- }
- /***********************************************************************************************
- * LinkClass::Get_Prev -- Fetches previous object in linked list. *
- * *
- * Use this routine to get a pointer to the previous object in the linked list. If there *
- * are no previous objects (such as at the head of the list), then NULL is returned. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: Returns with a pointer to the previous object in the list or NULL if none. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/15/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass * LinkClass::Get_Prev(void) const
- {
- return(Prev);
- }
- /***********************************************************************************************
- * LinkClass::Head_Of_List -- Finds the head of the list. *
- * *
- * Use this routine to scan for and return a reference to the object at the head of the *
- * list. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: Returns with a reference to the object at the head of the list. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/19/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass & LinkClass::Head_Of_List(void)
- {
- LinkClass * link = this;
- while (link->Prev) {
- link = link->Prev;
- if (link == this) break; // Safety check
- }
- return(*link);
- }
- /***********************************************************************************************
- * LinkClass::Tail_Of_List -- Scans for the object at the end of the list. *
- * *
- * Use this routine to scan for and return a reference to the object at the end of the *
- * list. *
- * *
- * INPUT: none *
- * *
- * OUTPUT: Returns with a reference to the object at the end of the list. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/19/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass & LinkClass::Tail_Of_List(void)
- {
- LinkClass * link = this;
- while (link->Next) {
- link = link->Next;
- if (link == this) break; // Safety check
- }
- return(*link);
- }
- /***********************************************************************************************
- * LinkClass::Add -- This object adds itself to the given list *
- * *
- * Use this routine to add a link object to the list, but to be added right after the *
- * given link. This allows inserting a link in the middle of the chain. A quite necessary *
- * ability if the chain is order dependant (e.g., the gadget system). *
- * *
- * INPUT: list -- gadget object to add this one to *
- * *
- * OUTPUT: Returns with a pointer to the head of the list. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/19/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass & LinkClass::Add(LinkClass & list)
- {
- LinkClass * ptr;
- /*
- ** Save ptr to next gadget.
- */
- ptr = list.Next;
- /*
- ** Link myself in after 'list'.
- */
- list.Next = this;
- Prev = &list;
- /*
- ** Link myself to next gadget, if there is one.
- */
- Next = ptr;
- if (ptr) {
- ptr->Prev = this;
- }
- return(Head_Of_List());
- }
- /***********************************************************************************************
- * LinkClass::Add_Head -- This gadget makes itself the head of the given list. *
- * *
- * INPUT: list -- the list to make myself the head of *
- * *
- * OUTPUT: Returns with a reference to the object at the head of the list. This should be *
- * the same object that is passed in. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/19/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass & LinkClass::Add_Head(LinkClass & list)
- {
- LinkClass * ptr;
- /*
- ** Get head of given list.
- */
- ptr = &list.Head_Of_List();
- /*
- ** Link myself in front of it.
- */
- ptr->Prev = this;
- Next = ptr;
- Prev = NULL;
- return(*this);
- }
- /***********************************************************************************************
- * LinkClass::Add_Tail -- Add myself to the end of the given list. *
- * *
- * INPUT: list -- list to add myself to *
- * *
- * OUTPUT: the head of the list *
- * *
- * WARNINGS: The previous and next pointers for the added object MUST have been properly *
- * initialized for this routine to work correctly. *
- * *
- * HISTORY: *
- * 01/15/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass & LinkClass::Add_Tail(LinkClass & list)
- {
- LinkClass * ptr;
- /*
- ** Get head of given list.
- */
- ptr = &list.Tail_Of_List();
- /*
- ** Link myself in front of it.
- */
- ptr->Next = this;
- Prev = ptr;
- Next = NULL;
- return(Head_Of_List());
- }
- /***********************************************************************************************
- * LinkClass::Remove -- Removes the specified object from the list. *
- * *
- * This routine will remove the specified object from the list of objects. Because of the *
- * previous and next pointers, it is possible to remove an object from the list without *
- * knowing the head of the list. To do this, just call Remove() with the parameter of *
- * "this". *
- * *
- * INPUT: none *
- * *
- * OUTPUT: Returns with the new head of list. *
- * *
- * WARNINGS: none *
- * *
- * HISTORY: *
- * 01/15/1995 JLB : Created. *
- *=============================================================================================*/
- LinkClass * LinkClass::Remove(void)
- {
- LinkClass * head = &Head_Of_List();
- LinkClass * tail = &Tail_Of_List();
- if (Prev) {
- Prev->Next = Next;
- }
- if (Next) {
- Next->Prev = Prev;
- }
- Prev = 0;
- Next = 0;
- if (head==this) {
- if (tail==this) {
- return(0);
- }
- return(&tail->Head_Of_List());
- }
- return(head);
- }
|