VR-Forces 4.0.4 Class Documentation
include/gdb/slList.h
Go to the documentation of this file.
00001 /*********************************************************************
00002 ** Copyright (c) 1999 MaK Technologies, Inc.
00003 ** All rights reserved.
00004 *********************************************************************/
00005 /*********************************************************************
00006 ** $RCSfile: slList.h,v $ $Revision: 1.7 $ $State: Exp $
00007 *********************************************************************/
00008 
00009 #ifndef slList_H_
00010 #define slList_H_
00011 
00012 #include "gdb/gdbDefines.h"
00013 #include <vlutil/vlMachineTypes.h>
00014 
00015 //forward declaration
00016 class DtSimpleListItem;
00017 
00018 // class DtSimpleList:
00019 //
00020 // DtSimpleList is fashioned after DtList in VR-Link. However, it provides
00021 // a singly-linked list for situations where a simple traversal of the 
00022 // list is all that is required.  
00023 // @note This class has no virtual functions on purpose to reduce the size
00024 // of the items as DtGroups use DtSimpleLists to hold their children, which
00025 // means at least one DtSimpleList for every type of group node in the 
00026 // scene, which adds up for large scenes.  Additionally, other classes should
00027 // @b not be derived from this class as it is just a container.
00028 // 
00029 class DT_DLL_gdb DtSimpleList
00030 {
00031 public:
00032 
00033    // constructor
00034    DtSimpleList();
00035 
00036    // destructor
00037    // Note: ~DtSimpleList() does not free memory of data associated
00038    // with the items. It only frees the items.
00039    ~DtSimpleList();
00040 
00041    // returns first item on list
00042    DtSimpleListItem* first() const;
00043 
00044    // returns last item on list
00045    DtSimpleListItem* last() const;
00046 
00047    // returns size of list
00048    unsigned int count() const; 
00049 
00050    // add an element to the end of the list
00051    DtSimpleListItem* add(void* data);  
00052 
00053    // add an element to the beginning of the list 
00054    DtSimpleListItem* addToStart(void* data);  
00055 
00056    // add an element to the end of the list
00057    DtSimpleListItem* addToEnd(void* data);  
00058 
00059    // add an element with specified data component to list, appearing 
00060    // immediately after list element specified as 'after'  
00061    DtSimpleListItem* addAfter(void* data, DtSimpleListItem* after);
00062 
00063    // Note: remove does not free memory of data associated
00064    // with the item. It only frees the item. The data is
00065    // returned to the caller for deletion if required. 
00066    void* remove(DtSimpleListItem* item);
00067 
00068 
00069    // Does NOT delete the data in the list.  Merely removes the data
00070    // from the list.  Data must be deleted later.  
00071    void removeAll();
00072 
00073    // return list element whose data component is as specified.   
00074    DtSimpleListItem* itemLookup(void* data) const;
00075 
00076    // The sort method sorts the items according to a user-defined comparison 
00077    // function. If the comparison function is compare(), then compare(e1,e2)
00078    // should return an int value <0 if e1<e2, 0 if e1=e2, and >0 if e1>e2.
00079    // The parameters e1 and e2 are void pointers to raw data type.
00080    // The items are sorted in increasing order.
00081 
00082    void sort(int(* compare)(const void *e1,const void *e2));
00083 
00084    // If a copy constructor is implemented, the assignment operator should
00085    // also be implemented.  Should generally implement both of them anyway to
00086    // avoid memory problems due to inappropriate compiler provided defaults.
00087    // Access varies so need to put proper access keyword above these 
00088    // declarations.
00089 
00090    // copy constructor
00091    DtSimpleList(const DtSimpleList& orig);
00092 
00093    // assignment operator
00094    DtSimpleList& operator=(const DtSimpleList& orig);
00095 
00096 
00097 protected:
00098 
00099    // add list item to appear immediately after list item 'after'
00100    void addToList(DtSimpleListItem* item, DtSimpleListItem* after);
00101 
00102    // remove specified item from list
00103    void removeFromList(DtSimpleListItem* item);
00104 
00105 protected:
00106 
00107    DtSimpleListItem* myFirst;
00108    DtSimpleListItem* myLast;
00109    unsigned int myCount;   
00110 
00111 };
00112 
00113 
00114 inline DtSimpleListItem* DtSimpleList::first() const 
00115 { 
00116    return myFirst; 
00117 }
00118 
00119 inline DtSimpleListItem* DtSimpleList::last() const 
00120 { 
00121    return myLast; 
00122 }
00123 
00124 inline unsigned int DtSimpleList::count() const
00125 { 
00126    return myCount; 
00127 }
00128 
00129 // add an element to the end of the list
00130 inline DtSimpleListItem* DtSimpleList::add(void* data) 
00131 {   
00132    return addAfter(data, myLast); 
00133 }
00134 
00135 // add an elemnt to the beginning of the list 
00136 inline DtSimpleListItem* DtSimpleList::addToStart(void* data)  
00137 {
00138    return addAfter(data, 0);  
00139 }
00140 
00141 // add an element to the end of the list
00142 inline DtSimpleListItem* DtSimpleList::addToEnd(void* data)  
00143 {
00144    return addAfter(data, myLast); 
00145 }
00146 
00147 #endif

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)