shapesmodel.cpp
来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C++ 代码 · 共 150 行
CPP
150 行
/**
*
* @brief Definition of CShapesModel
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class includes
#include "ShapesModel.h"
// CONSTANTS
const TInt KNumElements = 5;
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2 phase constructor.
* Constructs the CShapesModel using the NewLC method, popping
* the constructed object from the CleanupStack before returning it.
*
* @return The newly constructed CShapesModel
*/
CShapesModel* CShapesModel::NewL()
{
CShapesModel* self = CShapesModel::NewLC();
CleanupStack::Pop(self);
return self;
}
/**
* Symbian OS 2 phase constructor.
* Constructs the CShapesModel using the constructor and ConstructL
* method, leaving the constructed object on the CleanupStack before returning it.
*
* @return The newly constructed CShapesModel
*/
CShapesModel* CShapesModel::NewLC()
{
CShapesModel* self = new (ELeave) CShapesModel();
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
/**
* Destructor.
* Frees memory allocated to the array.
*/
CShapesModel::~CShapesModel()
{
iData.Close();
}
/**
* Standard C++ constructor
*
*/
CShapesModel::CShapesModel()
: iData(KNumElements)
{
}
/**
* Symbian OS 2nd phase constructor.
* Initializes all elements.
*/
void CShapesModel::ConstructL()
{
for (TInt i = 0; i < KNumElements; i++)
{
iData.Append(0);
}
}
/**
* Returns the number of elements
*
* @return The number of elements
*/
const TInt CShapesModel::NumElements() const
{
return iData.Count();
}
/**
* Returns the value of an element at index aIndex
* Note that there is no explicit bounds checking.
*
* @param aIndex The index of the element to be returned
* @return The element value
*/
const TInt CShapesModel::ElementAt(TInt aIndex)
{
return iData[aIndex];
}
/**
* Sets the value of an element at index aIndex
* Note that there is no explicit bounds checking.
*
* @param aValue The value the element is to be set to
* @param aIndex The index of the element to be set
*/
void CShapesModel::SetElement(TInt aValue, TInt aIndex)
{
iData[aIndex] = aValue;
}
/**
* Returns the maximum element value
*
* @return The maximum element value
*/
const TInt CShapesModel::GetMaxValue() const
{
TInt tempMax = 0;
for (TInt i = 0; i < KNumElements; i++) // Assumes that iData.Count() == KNumElements
{
if (tempMax < iData[i])
{
tempMax = iData[i];
}
}
return tempMax;
}
/**
* Returns the sum of element values
*
* @return The sum of element values
*/
const TInt CShapesModel::SumOfElements() const
{
TInt tempSum = 0;
for (TInt i = 0; i < KNumElements; i++) // Assumes that iData.Count() == KNumElements
{
tempSum += iData[i];
}
return tempSum;
}
// End of File
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?