// This is a part of the Microsoft Foundation Classes C++ library. // Copyright (c) 1992-2001 Microsoft Corporation, All Rights Reserved // All rights reserved. // // This source code is only intended as a supplement to the // Microsoft Foundation Classes Reference and related // electronic documentation provided with the library. // See these sources for detailed information regarding the // Microsoft Foundation Classes product. #ifndef __PROVCONT_H #define __PROVCONT_H #include template class ProvList { private: CCriticalSection * criticalSection ; CList clist ; protected: public: ProvList ( BOOL threadSafeArg = FALSE ) ; virtual ~ProvList () ; int GetCount() const; BOOL IsEmpty() const; TYPE& GetHead(); TYPE GetHead() const; TYPE& GetTail(); TYPE GetTail() const; TYPE RemoveHead(); TYPE RemoveTail(); POSITION AddHead(ARG_TYPE newElement); POSITION AddTail(ARG_TYPE newElement); void AddHead(ProvList* pNewList); void AddTail(ProvList* pNewList); void RemoveAll(); POSITION GetHeadPosition() const; POSITION GetTailPosition() const; TYPE& GetNext(POSITION& rPosition); TYPE GetNext(POSITION& rPosition) const; TYPE& GetPrev(POSITION& rPosition); TYPE GetPrev(POSITION& rPosition) const; TYPE& GetAt(POSITION position); TYPE GetAt(POSITION position) const; void SetAt(POSITION pos, ARG_TYPE newElement); void RemoveAt(POSITION position); POSITION InsertBefore(POSITION position, ARG_TYPE newElement); POSITION InsertAfter(POSITION position, ARG_TYPE newElement); POSITION Find(ARG_TYPE searchValue, POSITION startAfter = NULL) const; POSITION FindIndex(int nIndex) const; } ; template ProvList :: ProvList ( BOOL threadSafeArg ) : criticalSection ( NULL ) { if ( threadSafeArg ) criticalSection = new CCriticalSection ; else criticalSection = NULL ; } template ProvList :: ~ProvList () { if ( criticalSection ) delete criticalSection ; } template int ProvList :: GetCount() const { if ( criticalSection ) { criticalSection->Lock () ; int count = clist.GetCount () ; criticalSection->Unlock () ; return count ; } else { return clist.GetCount () ; } } template BOOL ProvList :: IsEmpty() const { if ( criticalSection ) { criticalSection->Lock () ; BOOL isEmpty = clist.IsEmpty () ; criticalSection->Unlock () ; return isEmpty ; } else { return clist.IsEmpty () ; } } template TYPE &ProvList :: GetHead () { if ( criticalSection ) { criticalSection->Lock () ; TYPE &head = clist.GetHead () ; criticalSection->Unlock () ; return head; } else { return clist.GetHead () ; } } template TYPE ProvList :: GetHead () const { if ( criticalSection ) { criticalSection->Lock () ; TYPE head = clist.GetHead () ; criticalSection->Unlock () ; return head ; } else { return clist.GetHead () ; } } template TYPE &ProvList :: GetTail() { if ( criticalSection ) { criticalSection->Lock () ; TYPE &tail = clist.GetTail () ; criticalSection->Unlock () ; return tail ; } else { return clist.GetTail () ; } } template TYPE ProvList :: GetTail() const { if ( criticalSection ) { criticalSection->Lock () ; TYPE tail = clist.GetTail () ; criticalSection->Unlock () ; return tail ; } else { return clist.GetTail () ; } } template TYPE ProvList :: RemoveHead() { if ( criticalSection ) { criticalSection->Lock () ; TYPE head = clist.RemoveHead () ; criticalSection->Unlock () ; return head ; } else { return clist.RemoveHead () ; } } template TYPE ProvList :: RemoveTail() { if ( criticalSection ) { criticalSection->Lock () ; TYPE tail = clist.RemoveTail () ; criticalSection->Unlock () ; return tail ; } else { return clist.RemoveTail () ; } } template POSITION ProvList :: AddHead(ARG_TYPE newElement) { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.AddHead ( newElement ) ; criticalSection->Unlock () ; return position ; } else { return clist.AddHead ( newElement ) ; } } template POSITION ProvList :: AddTail(ARG_TYPE newElement) { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.AddTail ( newElement ) ; criticalSection->Unlock () ; return position ; } else { return clist.AddTail ( newElement ) ; } } template void ProvList :: AddHead(ProvList *pNewList) { if ( criticalSection ) { criticalSection->Lock () ; clist.AddHead ( pNewList->clist ) ; criticalSection->Unlock () ; } else { clist.AddHead ( pNewList->clist ) ; } } template void ProvList :: AddTail(ProvList *pNewList) { if ( criticalSection ) { criticalSection->Lock () ; clist.AddTail ( pNewList->clist ) ; criticalSection->Unlock () ; } else { clist.AddTail ( pNewList->clist ) ; } } template void ProvList :: RemoveAll () { if ( criticalSection ) { criticalSection->Lock () ; clist.RemoveAll () ; criticalSection->Unlock () ; } else { clist.RemoveAll () ; } } template POSITION ProvList :: GetHeadPosition() const { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.GetHeadPosition () ; criticalSection->Unlock () ; return position ; } else { return clist.GetHeadPosition () ; } } template POSITION ProvList :: GetTailPosition() const { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.GetTailPosition () ; criticalSection->Unlock () ; return position ; } else { return clist.GetTailPosition () ; } } template TYPE& ProvList :: GetNext(POSITION& rPosition) { if ( criticalSection ) { criticalSection->Lock () ; TYPE &type = clist.GetNext ( rPosition ) ; criticalSection->Unlock () ; return type ; } else { return clist.GetNext ( rPosition ) ; } } template TYPE ProvList :: GetNext(POSITION& rPosition) const { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = clist.GetNext ( rPosition ) ; criticalSection->Unlock () ; return type ; } else { return clist.GetNext ( rPosition ) ; } } template TYPE& ProvList :: GetPrev(POSITION& rPosition) { if ( criticalSection ) { criticalSection->Lock () ; TYPE &type = clist.GetPrev ( rPosition ) ; criticalSection->Unlock () ; return type ; } else { return clist.GetPrev ( rPosition ) ; } } template TYPE ProvList :: GetPrev(POSITION& rPosition) const { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = clist.GetPrev ( rPosition ) ; criticalSection->Unlock () ; return type ; } else { return clist.GetPrev ( rPosition ) ; } } template TYPE& ProvList :: GetAt(POSITION rPosition) { if ( criticalSection ) { criticalSection->Lock () ; TYPE &type = clist.GetAt ( rPosition ) ; criticalSection->Unlock () ; return type ; } else { return clist.GetAt ( rPosition ) ; } } template TYPE ProvList :: GetAt(POSITION rPosition) const { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = clist.GetAt ( rPosition ) ; criticalSection->Unlock () ; return type ; } else { return clist.GetAt ( rPosition ) ; } } template void ProvList :: SetAt(POSITION pos, ARG_TYPE newElement) { if ( criticalSection ) { criticalSection->Lock () ; clist.SetAt ( pos , newElement ) ; criticalSection->Unlock () ; } else { clist.SetAt ( pos , newElement ) ; } } template void ProvList :: RemoveAt(POSITION position) { if ( criticalSection ) { criticalSection->Lock () ; clist.RemoveAt ( position ) ; criticalSection->Unlock () ; } else { clist.RemoveAt ( position ) ; } } template POSITION ProvList :: InsertBefore(POSITION position, ARG_TYPE newElement) { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.InsertBefore ( position , newElement ) ; criticalSection->Unlock () ; return position ; } else { return clist.InsertBefore ( position , newElement ) ; } } template POSITION ProvList :: InsertAfter(POSITION position, ARG_TYPE newElement) { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.InsertAfter ( position , newElement ) ; criticalSection->Unlock () ; return position ; } else { return clist.InsertAfter ( position , newElement ) ; } } template POSITION ProvList :: Find(ARG_TYPE searchValue, POSITION startAfter ) const { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.Find ( searchValue , startAfter ) ; criticalSection->Unlock () ; return position ; } else { return clist.Find ( searchValue , startAfter ) ; } } template POSITION ProvList :: FindIndex(int nIndex) const { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = clist.Find ( nIndex ) ; criticalSection->Unlock () ; return position ; } else { return clist.Find ( nIndex ) ; } } template class ProvStack : public ProvList { private: CCriticalSection * criticalSection ; protected: public: ProvStack ( BOOL threadSafeArg = FALSE ) ; virtual ~ProvStack () ; void Add ( ARG_TYPE type ) ; TYPE Get () ; TYPE Delete () ; } ; template ProvStack :: ProvStack ( BOOL threadSafeArg ) : ProvList ( FALSE ) , criticalSection ( NULL ) { if ( threadSafeArg ) criticalSection = new CCriticalSection ; else criticalSection = NULL ; } template ProvStack :: ~ProvStack () { if ( criticalSection ) delete criticalSection ; } template void ProvStack :: Add ( ARG_TYPE type ) { if ( criticalSection ) { criticalSection->Lock () ; AddHead ( type ) ; criticalSection->Unlock () ; } else { AddHead ( type ) ; } } template TYPE ProvStack :: Get () { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = GetHead () ; criticalSection->Unlock () ; return type ; } else { return GetHead () ; } } template TYPE ProvStack :: Delete () { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = RemoveHead () ; criticalSection->Unlock () ; return type ; } else { return RemoveHead () ; } } template class ProvQueue : public ProvList { private: CCriticalSection * criticalSection ; protected: public: ProvQueue ( BOOL threadSafeArg = FALSE ) ; virtual ~ProvQueue () ; void Add ( ARG_TYPE type ) ; TYPE Get () ; TYPE Delete () ; void Rotate () ; } ; template ProvQueue :: ProvQueue ( BOOL threadSafeArg ) : ProvList ( FALSE ) , criticalSection ( NULL ) { if ( threadSafeArg ) criticalSection = new CCriticalSection ; else criticalSection = NULL ; } template ProvQueue :: ~ProvQueue () { if ( criticalSection ) delete criticalSection ; } template void ProvQueue :: Add ( ARG_TYPE type ) { if ( criticalSection ) { criticalSection->Lock () ; AddTail ( type ) ; criticalSection->Unlock () ; } else { AddTail ( type ) ; } } template TYPE ProvQueue :: Get () { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = GetHead () ; criticalSection->Unlock () ; return type ; } else { return GetHead () ; } } template TYPE ProvQueue :: Delete () { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = RemoveHead () ; criticalSection->Unlock () ; return type ; } else { return RemoveHead () ; } } template void ProvQueue :: Rotate () { if ( criticalSection ) { criticalSection->Lock () ; TYPE type = Delete () ; Add ( type ) ; criticalSection->Unlock () ; } else { TYPE type = Delete () ; Add ( type ) ; } } template class ProvMap { private: CCriticalSection * criticalSection ; CMap cmap ; protected: public: ProvMap ( BOOL threadSafe = FALSE ) ; virtual ~ProvMap () ; int GetCount () const ; BOOL IsEmpty () const ; BOOL Lookup(ARG_KEY key, VALUE& rValue) const ; VALUE& operator[](ARG_KEY key) ; void SetAt(ARG_KEY key, ARG_VALUE newValue) ; BOOL RemoveKey(ARG_KEY key) ; void RemoveAll () ; POSITION GetStartPosition() const ; void GetNextAssoc(POSITION& rNextPosition, KEY& rKey, VALUE& rValue) const ; } ; template ProvMap :: ProvMap ( BOOL threadSafeArg ) : criticalSection ( NULL ) { if ( threadSafeArg ) criticalSection = new CCriticalSection ; else criticalSection = FALSE ; } template ProvMap :: ~ProvMap () { if ( criticalSection ) delete criticalSection ; } template int ProvMap :: GetCount() const { if ( criticalSection ) { criticalSection->Lock () ; int count = cmap.GetCount () ; criticalSection->Unlock () ; return count ; } else { return cmap.GetCount () ; } } template BOOL ProvMap :: IsEmpty() const { if ( criticalSection ) { criticalSection->Lock () ; BOOL isEmpty = cmap.IsEmpty () ; criticalSection->Unlock () ; return isEmpty ; } else { return cmap.IsEmpty () ; } } template BOOL ProvMap :: Lookup(ARG_KEY key, VALUE& rValue) const { if ( criticalSection ) { criticalSection->Lock () ; BOOL lookup = cmap.Lookup ( key , rValue ) ; criticalSection->Unlock () ; return lookup ; } else { return cmap.Lookup ( key , rValue ) ; } } template VALUE& ProvMap :: operator[](ARG_KEY key) { if ( criticalSection ) { criticalSection->Lock () ; VALUE &value = cmap.operator [] ( key ) ; criticalSection->Unlock () ; return value ; } else { return cmap.operator [] ( key ) ; } } template void ProvMap :: SetAt(ARG_KEY key, ARG_VALUE newValue) { if ( criticalSection ) { criticalSection->Lock () ; cmap.SetAt ( key , newValue ) ; criticalSection->Unlock () ; } else { cmap.SetAt ( key , newValue ) ; } } template BOOL ProvMap :: RemoveKey(ARG_KEY key) { if ( criticalSection ) { criticalSection->Lock () ; BOOL removeKey = cmap.RemoveKey ( key ) ; criticalSection->Unlock () ; return removeKey ; } else { return cmap.RemoveKey ( key ) ; } } template void ProvMap :: RemoveAll() { if ( criticalSection ) { criticalSection->Lock () ; cmap.RemoveAll () ; criticalSection->Unlock () ; } else { cmap.RemoveAll () ; } } template POSITION ProvMap :: GetStartPosition() const { if ( criticalSection ) { criticalSection->Lock () ; POSITION position = cmap.GetStartPosition () ; criticalSection->Unlock () ; return position ; } else { return cmap.GetStartPosition () ; } } template void ProvMap :: GetNextAssoc(POSITION& rNextPosition, KEY& rKey, VALUE& rValue) const { if ( criticalSection ) { criticalSection->Lock () ; cmap.GetNextAssoc ( rNextPosition , rKey , rValue ) ; criticalSection->Unlock () ; } else { cmap.GetNextAssoc ( rNextPosition , rKey , rValue ) ; } } #endif // __PROVCONT_H