⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 array.h

📁 barcode readers [ from Image]
💻 H
字号:
//
// CArray
//   A simple fixed-length array suitable for use with CleanupStack.
//
//   I needed a way to allocate an array of objects and have them
//   managed through CleanupStack, including running the object destructors
//   when the array is destroyed. There didn't seem to be any
//   way to do this with the Symbian SDK, that I could find. 
//   So this is it.
//
//   To create an array of length n of objects of type T
//      T* pArray = CArray<T>::NewL(n);
//   To put it on the stack:
//      CleanupStack::PushL(pArray);
//   To destroy it:
//      CleanupStack::PopAndDestroy(pArray);
//
// Copyright (c) 2006 by Jon A. Webb (Contact via GMail; username is jonawebb)
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// 
// This library 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
// Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

#ifndef Array_h
#define Array_h

#include <e32base.h>

namespace Core
{
	template<class T>
		class CArray : public CBase
			{
				// Lifecycle
			private:
				CArray() : 
				iMemory(NULL)
				{
				}

				void ConstructL(int nElements)
				{
					iMemory = new (ELeave) T [nElements];
					inCount = nElements;
				}
			public:
				static CArray* NewL(int nElements)
				{
					CArray<T>* pMe = new (ELeave) CArray<T>;
					CleanupStack::PushL(pMe);
					pMe->ConstructL(nElements);
					CleanupStack::Pop();
					return pMe;
				}
				virtual ~CArray()
				{
					delete [] iMemory;
				}

				// Operations -- index into the array. 
			public:
				virtual const T& operator[](int index) const
				{
					return iMemory[index];
				}
				virtual T& operator[](int index)
				{
					return iMemory[index];
				}
				// Accessors
			public:
				int Count() const 
				{
					return inCount;
				}
			private:
				int inCount;
				T* iMemory;
			};
};

#endif Array_h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -