elementcarray.h

来自「series60 应用程序开发的源代码 series60 应用程序开发的源代码」· C头文件 代码 · 共 157 行

H
157
字号
#ifndef ELEMENTCARRAY_H
#define ELEMENTCARRAY_H

// INCLUDES

// System includes
#include <e32base.h>

// User includes
#include "elementlist.h"

// CLASS DECLARATION

/**
*
* @class    CElementCArray elementcarray.h
* @brief    Specialisation of CElementList to store list of CChemicalElements as a CArray
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
class CElementCArray : public CElementList
{
public:
    /**
    * Destructor
    */
    ~CElementCArray();

    /**
    * Two-phase constructor
    * @return A newly constructed object
    */
    static CElementCArray* NewL();
    
    /**
    * Two-phase constructor
    * @return A newly constructed object, a pointer to which is left on the cleanup stack
    */
    static CElementCArray* NewLC();
    

    //From CElementList
public:
    /**
    * Getter for number of elements stored in the list
    * @return the number of elements stored in the list
    */
    TInt NumberOfElements() const;

    /**
    * Returns the element at the specified zero based index--const overload
    * @param aIndex The zero based index of the element required. Must be greater than zero, and less than
    * NumberOfElements()-1
    * @return A const reference to the element specified by aIndex
    * @panic KElementListPanicElementIndexOutOfRange if aIndex < 0 or aIndex > NumberOfElements()-1
    */
    const CChemicalElement& At(TInt aIndex) const;

    /**
    * Returns the element at the specified zero based index--non-const overload
    * @param aIndex The zero based index of the element required. Must be greater than zero, and less than
    * NumberOfElements()-1
    * @return A non-const (i.e. modifiable) reference to the element specified by aIndex
    * @panic KPanicElementIndexOutOfRange if aIndex < 0 or aIndex > NumberOfElements()-1
    */
    CChemicalElement& At(TInt aIndex);

    /**
    * Appends the given element onto the end of the list. Note that ownership of the element is passed to the
    * list, as denoted by the use of a CChemicalElement*.
    * @param aElement The element to be appended to the end of the list. Note its ownership is transferred, so
    * responsibility for aElement's destruction is no longer the responsibility of the caller.
    * @panic KElementListPanicNullElement If aElement==0
    */
    void AppendL(const CChemicalElement* aElement);

    /**
    * Deletes all of the elements owned by the list, and returns the memory allocated to them to the global heap.
    * Effectively resets the list to be empty.
    */
    void DeleteAllElements();

    /**
    * Searches the list for an element with name aName, and returns its zero-based index if found.
    * @param aName The name to search for.
    * @return The zero-based index of the element within the list.
    * @leave KErrNotFound If an element with name aName is not found.
    */
    TInt FindElementByNameL(const TDesC& aName) const;

    /**
    * Searches the list for an element with symbol aSymbol, and returns its zero-based index if found.
    * @param aSymbol The symbol to search for.
    * @return The zero-based index of the element within the list.
    * @leave KErrNotFound If an element with symbol aSymbol is not found.
    */
    TInt FindElementBySymbolL(const TDesC& aSymbol) const;

    /**
    * Searches the list for an element with atomic number aAtomicNumber, and returns its zero-based index if found.
    * @param aName The atomic number to search for.
    * @return The zero-based index of the element within the list.
    * @leave KErrNotFound If an element with atomic number aAtomicNumber is not found.
    */
    TInt FindElementByAtomicNumberL(TInt aAtomicNumber) const;

    /**
    * UNSUPPORTED--cannot sort by name as it is stored in the element by pointer, rather than value.
    * @leave KErrNotSupported ALWAYS
    */
    void SortByNameL();

    /**
    * Re-orders the list in ascending symbol order (i.e. alphabetical by symbol)
    * @leave KErrGeneral if the stack overflows during sorting
    */
    void SortBySymbolL();

    /**
    * Re-orders the list in ascending atomic number order (i.e. smallest atomic number first)
    * @leave KErrGeneral if the stack overflows during sorting
    */
    void SortByAtomicNumberL();

    /**
    * UNSUPPORTED--cannot sort CArray types on floating point elements
    * @leave KErrNotSupported ALWAYS
    */
    void SortByRelativeAtomicMassL();

private:
    //Work around for CArrayPtr find and sort issue
    class TKeyArrayPtr : public TKeyArrayFix
    {
    public:
        inline TKeyArrayPtr(TInt aOffset, TKeyCmpText aType) : TKeyArrayFix(aOffset, aType) {};
        inline TKeyArrayPtr(TInt aOffset, TKeyCmpText aType, TInt aLength) :
            TKeyArrayFix(aOffset, aType, aLength) {};
        inline TKeyArrayPtr(TInt aOffset, TKeyCmpNumeric aType) : TKeyArrayFix(aOffset, aType) {};
        virtual TAny* At(TInt aIndex) const;
    };

private:
    CElementCArray();
    void ConstructL();

    TInt DoFindL(TKeyArrayPtr& aKey, const TDesC& aName, const TDesC& aSymbol, TInt aAtomicNumber) const;


private:
    CArrayPtrFlat<CChemicalElement>*    iElementArray;
};
#endif // #ifndef ELEMENTCARRAY_H

// End of File

⌨️ 快捷键说明

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