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

📄 shapelistmanager.cpp

📁 最新官方例子,图形,描述副,基本控件,通讯协议,等等,
💻 CPP
字号:
/**
 * 
 * @brief Definition of CShapeListManager
 *
 * Copyright (c) EMCC Software Ltd 2003
 * @version 1.0
 */

// INCLUDE FILES

// Class Includes
#include	"ShapeListManager.h"

// User Includes
#include	"rectangle.h"
#include	"circle.h"

using namespace NShapes;


// ================= MEMBER FUNCTIONS =======================

/**
@function	NewLC
@abstract	Creates a new instance of the engine.
@result	Returns the engine
**/
EXPORT_C CShapeListManager* CShapeListManager::NewLC()
	{
	CShapeListManager*	self = new (ELeave) CShapeListManager;
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
	}

/**
@function	NewL
@abstract	Creates a new instance of the engine.
@result	Returns the engine
**/
EXPORT_C CShapeListManager* CShapeListManager::NewL()
	{
	CShapeListManager*	self = CShapeListManager::NewLC();
    CleanupStack::Pop(self);
    return self;
	}

/**
@function	CShapeListManager
@abstract	Performs any first stage construction
**/
EXPORT_C CShapeListManager::CShapeListManager()
    {
	//	No implementation required
    }

EXPORT_C CShapeListManager::~CShapeListManager()
    {
    iShapeList.ResetAndDestroy();
    }

/**
@function	ConstructL
@abstract	Performs any second stage construction
**/
EXPORT_C void CShapeListManager::ConstructL()
    {
	//	No implementation required
    }

/**
@function	Clear
@abstract	Clears the list of shapes. 
**/
EXPORT_C void CShapeListManager::Clear()
	{
	iNextShapeIndex = 0;	//	The first shape in the list
    iShapeList.ResetAndDestroy();
	}

/**
@function	AddShape
@abstract	Adds a shape to the list
@param aShape the object to add to the list. 
**/
EXPORT_C void CShapeListManager::AddShapeL(TShape* aShape)
    {
	TInt error = iShapeList.Append(aShape);

	if (error != KErrNone)
		{
		delete aShape;
		User::Leave(error);
		}
    }

/**
@function RemoveShape
@abstract Removes shape from the list
@param aShape the object to remove from the list
**/
EXPORT_C void CShapeListManager::RemoveShapeL(TShape* aShape)
	{
	TInt itemIndex = iShapeList.Find(aShape);
	iShapeList.Remove(itemIndex);
	delete aShape;
	}

/**
@function	GetNextShape
@abstract	Returns the next shape in the list and increments the next shape 
index. If there is no such shape, then it returns NULL, and resets the next shape index.
**/
EXPORT_C TShape* CShapeListManager::GetNextShape()
    {
    if (iShapeList.Count() > 0) 
		{
        if (iNextShapeIndex < iShapeList.Count()) 
			{
            TShape* shape = iShapeList[iNextShapeIndex];
            ++iNextShapeIndex;
            return shape;
			}
		//	Gone past the end, so reset the index
        iNextShapeIndex = 0;
		}
    return NULL;
    }

/**
@function	StoreL
@abstract	Stores the instance to the specified store
@param aStore the store to stream the object to
@result Returns the id of the store within the stream.
**/
EXPORT_C TStreamId CShapeListManager::StoreL(CStreamStore& aStore) const
    {
    RStoreWriteStream stream;

	// Create a stream within the store
    TStreamId id = stream.CreateLC(aStore);

	// Write the data to the stream
    ExternalizeL(stream); 
    stream.CommitL();

    CleanupStack::PopAndDestroy(); // the stream

    return id; // return the stream ID          
    }

/**
@function	ExternalizeL
@abstract	Stores the instance to the specified stream
@param aStream the stream to stream the object to
**/
EXPORT_C void CShapeListManager::ExternalizeL(RWriteStream& aStream) const
    {
    TInt count = iShapeList.Count();

    aStream.WriteInt16L((TInt16)count);

    for (TInt index = 0; index < count; ++index)
        {
        const TShape* shape = iShapeList[index];
        shape->ExternalizeL(aStream);
        }
    }


EXPORT_C TInt CShapeListManager::DataSize()
	{
	TInt size = sizeof(TInt16);
	TInt count = iShapeList.Count();
	for(TInt index = 0; index < count; ++index)
		{	
		const TShape* shape = iShapeList[index];
		size += shape->StorageSize();
	
		}
	return size;
	}

/**
@function	RestoreL
@abstract	Restores the instance from the specified stream within the specified 
store
@param aStore the store containing the data
@param aStreamId the id of the stream within the store
**/
EXPORT_C void CShapeListManager::RestoreL(const CStreamStore& aStore, const TStreamId& aStreamId)
    {
    Clear();

    RStoreReadStream stream;
	// Open the stream
    stream.OpenLC(aStore, aStreamId);

	// Read the data from the stream
    InternalizeL(stream); 

    CleanupStack::PopAndDestroy(); // the stream
    }

/**
@function	InternalizeL
@abstract	Restores the instance from the specified stream
@param aStream the stream to stream the object from
**/
EXPORT_C void CShapeListManager::InternalizeL(RReadStream& aStream)
    {

    TInt count = aStream.ReadInt16L();
    for (TInt index = 0; index < count; ++index)
        {
        TShape* shape = NULL;
        switch (TShape::ReadShapeTypeL(aStream))
            {
            case KRectangle :
                shape = new (ELeave) TRectangle();
                break;
            case KCircle :
                shape = new (ELeave) TCircle();
                break;
            default :
                User::Leave(KErrCorrupt);
            }
	    CleanupStack::PushL(shape);
        shape->InternalizeL(aStream);
		User::LeaveIfError(iShapeList.Append(shape));
	    CleanupStack::Pop(shape);	//	Now owned by iShapeList
        }
    }



// ================= OTHER EXPORTED FUNCTIONS ==============

// requirement for E32 DLLs
EXPORT_C TInt E32Dll(TDllReason)
	{
	return KErrNone;
	}

⌨️ 快捷键说明

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