#ifndef __COLLMGR_HPP__ #define __COLLMGR_HPP__ /*++ Copyright (C) 2000 Microsoft Corporation All rights reserved. Module Name: collmgr.hpp Abstract: This file contains the declaration of a generic linked list which could encapsulate any data type even if complex ones. The list is defined as a manager and a node. The manager manages the given nodes of that type. Author: Khaled Sedky (khaleds) 21-Jun-2000 Revision History: --*/ #ifndef __LDERROR_HPP__ #include "lderror.hpp" #endif #ifndef __LDMGR_HPP__ #include "ldmgr.hpp" #endif // // Forward Declarations // template class TLstNd; template class TLstMgr; // // E here is the element and C is a major content in this element. // or in other words the index of the element . It could be described // as the component by which the element is created or by which it // is compared against.C is the type used as a key for comparisons. // template class TLstNd { // // Public methods of the class // public: friend class TLstMgr; TLstNd( VOID ); // // Copy Constructor // TLstNd( IN CONST TLstNd& ); // // Copy constructor based on the Element saved // in the list // TLstNd( IN const E& ); TLstNd( IN E* ); // // A Copy constructor based on the // component // TLstNd( IN const C& ); ~TLstNd( VOID ); const E& operator=( IN const E& ); BOOL operator==( IN const E& ) const; BOOL operator==( IN const C& ) const; E& operator*( VOID ); E* SetNodeData( IN E* ); // // Private members and helper functions (if any) // private: E* m_pD; TLstNd *m_pNext; TLstNd *m_pPrev; }; template class TLstMgr : public TClassID, public TLd64BitDllsErrorHndlr { // // Public methods of the class // public: friend TLstNd; // // To optimize the overhead of allocating // and Freeing memroy , the user of this // class might resort to using the FreeList // support which enable him to recycle nodes // when they are not longer required. // enum EListType { KFreeListSupport, KNoFreeListSupport, }; // // Based on the index of the collection, Entries, // maybe or may not be unique. Based on this Flag // being set in the constructor, the List search // criteria is decided and so is the Appending // algorithm // enum EEntriesType { KUniqueEntries = 0, KNonUniqueEntries }; TLstMgr( IN typename TLstMgr::EEntriesType ThisListEntriesType = TLstMgr::KNonUniqueEntries, IN typename TLstMgr::EListType ThisListType = TLstMgr::KNoFreeListSupport, IN OUT HRESULT* hRes = NULL ); ~TLstMgr( VOID ); TLstNd* AppendListByElem( IN const E& ); TLstNd* AppendListByElem( IN E* ); TLstNd* AppendListByElem( IN const C & ); HRESULT RmvElemFromList( IN const E& ); HRESULT RmvElemFromList( IN const C& ); HRESULT RmvElemAtPosFromList( IN DWORD ); HRESULT RmvTail( VOID ); HRESULT RmvHead( VOID ); HRESULT DestructList( VOID ); E& GetElementAtPos( IN DWORD ) const; E* GetElementAtPosByRef( IN DWORD ) const; E& operator[]( IN DWORD ) const; TLstNd* ElementInList( IN const C& ) const; BOOL HaveElements( VOID ) const; DWORD GetNumOfListNodes( VOID ) const; // // Private members and helper functions (if any) // private: TLstNd *m_pHead; TLstNd *m_pTail; DWORD m_cNumOfNodes; BOOL m_bUnique; // // To protect the linked list data members // in a multithread environment. // CRITICAL_SECTION *m_pLockSem; }; template class TLstItrtr : public TClassID { public: TLstItrtr( IN const TLstMgr& ); ~TLstItrtr(); TLstNd& operator*( VOID ); TLstNd& operator++( VOID ); const TLstNd operator++( int ); TLstNd& operator--( VOID ); const TLstNd operator--( int ); private: TLstMgr *m_pItrtdMgrPrxy; TLstNd *m_pCrntNode; }; // // This is an abstract class which never // get instantiated. Any Element other than // primitive Data types , has to inherit from // this class . There are some mandatory // methods that need to be implemented // class TGenericElement : public TRefCntMgr { public: // // A BOOL variable indicating Validity // of the object should be defined here. // This should be set by SetValidity and // queried by Validate. // TGenericElement() {}; // // We internally create the elements in // the list to be independent of the client // and that is when we call the equal operator // /* virtual const TGenericElement& operator=( IN const TGenericElement& ); // // Since many of the interfaces supplied by the // List Manager rely on comparisons between the // internally maintained elements , so we need // an == opoperator and a ! operator. // virtual BOOL operator==( IN const TGenericElement& ) const; virtual BOOL operator!( VOID ) const;*/ // // Some times we might return a dummy invalid // element to invalidate the result of a list // manager method // virtual VOID SetValidity( IN DWORD ) = 0; virtual BOOL Validate( VOID ) const = 0; }; // // Since our iimplementation of C++ does not have a #pragma implementation , // so I am including the implementation file directly in the header file // #include "collmgr.cxx" #endif //__COLLMGR_HPP__