A
download AGArrayTemplates.h
Language: C++
License: GPL
Copyright: (C) 2004-2005 Petr Kozelka, PPK at seznam dot cz
LOC: 113
Project Info
mcdcplusplus(mcdc)
Server: BerliOS (SVN)
Type: svn
...(SVN)\m\mcdc\trunk\windows\
   AboutDlg.h
   ADLSearchFrame.cpp
   ADLSearchFrame.h
   ADLSProperties.cpp
   ADLSProperties.h
   Advanced3Page.cpp
   Advanced3Page.h
   AdvancedPage.cpp
   AdvancedPage.h
   AGArrayTemplates.cpp
   AGArrayTemplates.h
   AGEmotionSetup.cpp
   AGEmotionSetup.h
   AppearancePage.cpp
   AppearancePage.h
   atlctrlxp.h
   BarShader.cpp
   BarShader.h
   BrowserFrame.cpp
   BrowserFrame.h
   Bumped.cpp
   Bumped.h
   ChatCtrl.cpp
   ChatCtrl.h
   CommandDlg.cpp
   CommandDlg.h
   DebugFrame.cpp
   DebugFrame.h
   DimEdit.h
   DirectoryListingFrm.cpp
   DirectoryListingFrm.h
   DownloadPage.cpp
   DownloadPage.h
   EmoticonsDlg.cpp
   EmoticonsDlg.h
   ExListViewCtrl.cpp
   ExListViewCtrl.h
   ExtendedTrace.cpp
   ExtendedTrace.h
   FavHubProperties.cpp
   FavHubProperties.h
   FavoriteDirsPage.cpp
   FavoriteDirsPage.h
   FavoritesFrm.cpp
   FavoritesFrm.h
   FilterPage.cpp
   FilterPage.h
   FilterPageDlg.h
   FinishedFrame.cpp
   FinishedFrame.h
   FinishedULFrame.cpp
   FinishedULFrame.h
   FlatTabCtrl.h
   FulComboBox.cpp
   FulComboBox.h
   FulTabsPage.cpp
   FulTabsPage.h
   GeneralPage.cpp
   GeneralPage.h
   HashProgressDlg.h
   HelpSystem.cpp
   HelpSystem.h
   HubFrame.cpp
   HubFrame.h
   IgnoreFrame.cpp
   IgnoreFrame.h
   ImageDataObject.cpp
   ImageDataObject.h
   iTunesCOMInterface.h
   iTunesCOMInterface_i.c
   LineDlg.cpp
   LineDlg.h
   ListViewArrows.h
   LogPage.cpp
   LogPage.h
   MagnetDlg.h
   main.cpp
   MainFrm.cpp
   MainFrm.h
   McAdvancedPage.cpp
   McAdvancedPage.h
   McDCPage.cpp
   McDCPage.h
   memdc.h
   NetworkPage.cpp
   NetworkPage.h
   NotepadFrame.cpp
   NotepadFrame.h
   NotepadFrame2.cpp
   NotepadFrame2.h
   OMenu.cpp
   OMenu.h
   OperaColorsPage.cpp
   OperaColorsPage.h
   picturewindow.h
   PopupDlg.h
   PopupManager.cpp
   PopupManager.h
   Popups.cpp
   Popups.h
   PreviewDlg.cpp
   PreviewDlg.h
   PreviewPage.cpp
   PreviewPage.h
   PrivateFrame.cpp
   PrivateFrame.h
   PropertiesDlg.cpp
   PropertiesDlg.h
   PropPage.cpp
   PropPage.h
   PropPageTextStyles.cpp
   PropPageTextStyles.h
   PublicHubsFrm.cpp
   PublicHubsFrm.h
   PublicHubsListDlg.h
   QueueFrame.cpp
   QueueFrame.h
   QueuePage.cpp
   QueuePage.h
   RecentsFrm.cpp
   RecentsFrm.h
   resource.h
   SearchFrm.cpp
   SearchFrm.h
   SecurityPage.cpp
   SecurityPage.h
   SingleInstance.h
   Sntp.cpp
   Sntp.h
   Sounds.cpp
   Sounds.h
   SpyFrame.cpp
   SpyFrame.h
   StaticFrm.h
   StatsFrame.cpp
   StatsFrame.h
   stdafx.cpp
   stdafx.h
   SystemFrame.cpp
   SystemFrame.h
   TextFrame.cpp
   TextFrame.h
   ThemesPage.cpp
   ThemesPage.h
   things.cpp
   things.h
   ToolbarPage.cpp
   ToolbarPage.h
   TransferView.cpp
   TransferView.h
   TreePropertySheet.cpp
   TreePropertySheet.h
   TypedListViewCtrl.h
   UCHandler.h
   UCPage.cpp
   UCPage.h
   UlcPage.cpp
   UlcPage.h
   UploadPage.cpp
   UploadPage.h
   UploadQueueFrame.cpp
   UploadQueueFrame.h
   UPnP.cpp
   UPnP.h
   UserInfo.cpp
   UserInfo.h
   UsersFrame.cpp
   UsersFrame.h
   Winamp.h
   WinampFrame.cpp
   WinampFrame.h
   WindowsPage.cpp
   WindowsPage.h
   WinUtil.cpp
   WinUtil.h

/* 
 * Copyright (C) 2004-2005 Petr Kozelka, PPK at seznam dot cz
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#if !defined(AGARRAYTEMPLATES_H__)
#define AGARRAYTEMPLATES_H__

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// CAGPtrArray

class CAGPtrArray {
public:

// Construction
	CAGPtrArray();

// Attributes
	int GetSize() const;
	int GetUpperBound() const;
	void SetSize(int nNewSize, int nGrowBy = -1);
	void SetAllocSize(int nNewSize, int nGrowBy = -1);

// Operations
	// Clean up
	void FreeExtra();
	void RemoveAll();

	// Accessing elements
	void* GetAt(int nIndex) const;
	void SetAt(int nIndex, void* newElement);

	void*& ElementAt(int nIndex);

	// Direct Access to the element data (may return NULL)
	const void** GetData() const;
	void** GetData();

	// Potentially growing the array
	void SetAtGrow(int nIndex, void* newElement);

	int Add(void* newElement);
	int AddSpeedy(void* newElement);

	int Append(const CAGPtrArray& src);
	void Copy(const CAGPtrArray& src);

	// overloaded operator helpers
	void* operator[](int nIndex) const;
	void*& operator[](int nIndex);

	// Operations that move elements around
	void InsertAt(int nIndex, void* newElement, int nCount = 1);

	void RemoveAt(int nIndex, int nCount = 1);
	void InsertAt(int nStartIndex, CAGPtrArray* pNewArray);

// Implementation
protected:
	void** m_pData;   // the actual array of data
	int m_nSize;     // # of elements (upperBound - 1)
	int m_nMaxSize;  // max allocated
	int m_nGrowBy;   // grow amount


public:
	~CAGPtrArray();

protected:
	// local typedefs for class templates
	typedef void* BASE_TYPE;
	typedef void* BASE_ARG_TYPE;
};

// CAGTypedPtrArray

template<class TYPE>
class CAGTypedPtrArray : public CAGPtrArray {
public:
	// Accessing elements
	TYPE GetAt(int nIndex) const
		{ return (TYPE)CAGPtrArray::GetAt(nIndex); }
	TYPE& ElementAt(int nIndex)
		{ return (TYPE&)CAGPtrArray::ElementAt(nIndex); }
	void SetAt(int nIndex, TYPE ptr)
		{ CAGPtrArray::SetAt(nIndex, ptr); }

	// Potentially growing the array
	void SetAtGrow(int nIndex, TYPE newElement)
	   { CAGPtrArray::SetAtGrow(nIndex, newElement); }

	int Add(TYPE newElement)
	   { return CAGPtrArray::Add(newElement); }

	int AddSpeedy(TYPE newElement)
	   { return CAGPtrArray::AddSpeedy(newElement); }

	int Append(const CAGTypedPtrArray<TYPE>& src)
	   { return CAGPtrArray::Append(src); }

	void Copy(const CAGTypedPtrArray<TYPE>& src)
		{ CAGPtrArray::Copy(src); }

	// Operations that move elements around
	void InsertAt(int nIndex, TYPE newElement, int nCount = 1)
		{ CAGPtrArray::InsertAt(nIndex, newElement, nCount); }

	void InsertAt(int nStartIndex, CAGTypedPtrArray<TYPE>* pNewArray)
	   { CAGPtrArray::InsertAt(nStartIndex, pNewArray); }

	// overloaded operator helpers
	TYPE operator[](int nIndex) const
		{ return (TYPE)CAGPtrArray::operator[](nIndex); }
	TYPE& operator[](int nIndex)
		{ return (TYPE&)CAGPtrArray::operator[](nIndex); }
};

// CAGDestroyTypedPtrArray

template <class Type>
class CAGDestroyTypedPtrArray : public CAGTypedPtrArray<Type*> {
public:
	typedef CAGTypedPtrArray<Type*> TParentClass;

	CAGDestroyTypedPtrArray() {
	}

	virtual ~CAGDestroyTypedPtrArray() {
	}

	void RemoveAt(int nIndex, int nCount = 1, bool bDelete = true) {
		if (bDelete) {
			Type* pItem;
			for (int cnt = nIndex; cnt < nIndex+nCount; cnt++) {
				pItem = GetAt(cnt);
				if (pItem != NULL)
					delete pItem;
			}
		}
		TParentClass::RemoveAt(nIndex, nCount);
	}

	void RemoveAll(bool bDelete = true) {
		if (bDelete) {
			Type* pItem;
			for (int cnt = 0; cnt < GetSize(); cnt++) {
				pItem = GetAt(cnt);
				if (pItem != NULL)
					delete pItem;
			}
		}
		TParentClass::RemoveAll();
	}

	void RemoveAllNoDestructSize(bool bDelete = true) {
		if (bDelete) {
			Type* pItem;
			for (int cnt = 0; cnt < GetSize(); cnt++) {
				pItem = TParentClass::ElementAt(cnt);
				if (pItem != NULL) {
					delete pItem;
					TParentClass::ElementAt(cnt) = NULL;
				}
			}
		}
		m_nSize = 0;
	}

};

#endif // AGARRAYTEMPLATES_H__

/**
 * @file
 * $Id: AGArrayTemplates.h 111 2006-11-17 12:42:35Z mccm $
 */

About Koders | Resources | Downloads | Support | Black Duck | Terms of Service | DMCA | Privacy Policy | Contact Us