chemicalelement.h

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

H
195
字号
#ifndef CHEMICALELEMENT_H
#define CHEMICALELEMENT_H

// INCLUDES

// System includes
#include <e32base.h>
#include <s32strm.h>

// CONSTANTS
const TInt KMaxSymbolLength = 3;    //The maximum number of characters in a chemical element's Symbol

// CLASS DECLARATION

/**
*
* @class    CChemicalElement chemicalelement.h
* @brief    Class to represent a chemical element. Allows the storage of the element's name, its 
*            chemical symbol (up to KMaxSymbolLength in size), its atomic number (A), its relative 
*            atomic mass (Z), its type (metallic, * semi-metallic or non-metallic) and whether or not 
*            it is radioactive (i.e. has no stable isotopes). Public accessor functions are provided
*            for all of the above data, as are standard functions for streaming in and out.
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

class CChemicalElement : public CBase
{
    friend class CElementCArray;    //Necessary to allow _FOFF macro access to the private data members for searching
public:
    /**
    * An enumeration of the 3 elemental types: metallic, semi-metallic and non-metallic. An element must
    * be one and only one of these types.
    */
    enum TElementType {EMetallic, ESemimetallic, ENonmetallic};

public:
    /**
    * Destructor
    */
    ~CChemicalElement();

    /**
    * Canonical NewL factory function. Returns a newly constructed instance of CChemicalElement in a leave-safe
    * manner.
    * @param aName The name of the chemical element.
    * @param aSymbol The chemical symbol of the element (maximum size = KMaxSymbolLength)
    * @param aAtomicNumber The integer atomic number of the element (i.e. the number of protons in the element's nucleus)
    * @param aRelativeAtomicMass The mass in grammes of one mole of atoms of the element
    * @param aType The type of element, one of: EMetallic, ESemimetallic, ENonmetallic as defined in the enumeration
    * TElementType
    * @param aRadioactive A boolean that is true if the element has no stable isotopes.
    * @return Pointer to the newly constructed instance.
    */
    static CChemicalElement* NewL(const TDesC& aName, const TDesC& aSymbol, TInt aAtomicNumber, 
        TReal aRelativeAtomicMass, TElementType aType = EMetallic, TBool aRadioactive = EFalse);
    
    /**
    * Canonical NewLC factory function. Returns a newly constructed instance of CChemicalElement in a leave-safe
    * manner, leaving a pointer to the instance pushed on the cleanup stack.
    * @param aName The name of the chemical element.
    * @param aSymbol The chemical symbol of the element (maximum size = KMaxSymbolLength)
    * @param aAtomicNumber The integer atomic number of the element (i.e. the number of protons in the element's nucleus)
    * @param aRelativeAtomicMass The mass in grammes of one mole of atoms of the element
    * @param aType The type of element, one of: EMetallic, ESemimetallic, ENonmetallic as defined in the enumeration
    * TElementType
    * @param aRadioactive A boolean that is true if the element has no stable isotopes.
    * @return Pointer to the newly constructed instance, also left on the cleanup stack.
    */
    static CChemicalElement* NewLC(const TDesC& aName, const TDesC& aSymbol, TInt aAtomicNumber, 
        TReal aRelativeAtomicMass, TElementType aType = EMetallic, TBool aRadioactive = EFalse);

    /**
    * NewL factory function to construct CChemicalElement from a read stream
    * @param aStream stream to read the CChemicalElement from
    * @return Pointer to a newly constructed instance
    */
    static CChemicalElement* NewL(RReadStream& aStream);

    /**
    * NewL factory function to construct CChemicalElement from a read stream, leaving a pointer pushed on the cleanup stack
    * @param aStream stream to read the CChemicalElement from
    * @return Pointer to a newly constructed instance, also left on the cleanup stack.
    */
    static CChemicalElement* NewLC(RReadStream& aStream);

    /**
    * Getter function for the element's name
    * @return The element's name
    */
    const TDesC& Name() const;

    /**
    * Getter function for the element's symbol
    * @param aSymbol the element's symbol
    */
    void GetSymbol(TDes& aSymbol) const;

    /**
    * Getter function for the element's symbol
    * @return The element's symbol
    */
    const TDesC& Symbol() const;

    /**
    * Getter function for the element's atomic number
    * @return The element's atomic number (an integer)
    */
    TInt AtomicNumber() const;

    /**
    * Getter function for the element's relative atomic mass
    * @return The element's relative atomic mass (a real number)
    */
    const TReal& RelativeAtomicMass() const;

    /**
    * Getter function for the element's type
    * @return An enumeration (of type TElementType) of the element's type (i.e. metallic, semi-metallic, non-metallic)
    */
    TElementType Type() const;

    /**
    * Getter function for the element's radioactivity
    * @return A boolean value that is true if the element has no stable isotopes
    */
    TBool Radioactive() const;

    /**
    * Setter function for the element's name. May leave if there is insufficient memory to allocate the name.
    * param aName The element's new name.
    */
    void SetNameL(const TDesC& aName);

    /**
    * Setter function for the element's symbol.
    * param aSymbol The element's new symbol.
    */
    void SetSymbol(const TDesC& aSymbol);

    /**
    * Setter function for the element's atomic number.
    * param aAtomicNumber The element's new atomic number.
    */
    void SetAtomicNumber(TInt aAtomicNumber);

    /**
    * Setter function for the element's relative atomic mass.
    * param aRelativeAtomicMass The element's new relative atomic mass.
    */
    void SetRelativeAtomicMass(const TReal& aRelativeAtomicMass);

    /**
    * Setter function for the element's type.
    * param aType The element's new type mass.
    */
    void SetType(TElementType aType);

    /**
    * Setter function for the element's radioactivity.
    * param aRadioactive The element's radioactivity.
    */
    void SetRadioactive(TBool aRadioactive);

    /**
    * Function to externalise the element into a write stream
    * param aStream the write stream to externalise to
    */
    void ExternalizeL(RWriteStream& aStream) const;

    /**
    * Function to internalise the element from a read stream
    * param aStream the write stream to internalise from
    */
    void InternalizeL(RReadStream& aStream);

private:
    void ConstructL(const TDesC& aName);
    CChemicalElement(const TDesC& aSymbol, TInt aAtomicNumber, TReal aRelativeAtomicMass,
        TElementType aType, TBool aRadioactive);
    CChemicalElement();

private:
    HBufC*                        iName;
    TBufC<KMaxSymbolLength>        iSymbol;
    TInt                        iAtomicNumber;
    TReal                        iRelativeAtomicMass;
    TElementType                iType;
    TBool                        iRadioactive;    //i.e. has no stable isotope
};

#endif // #ifndef CHEMICALELEMENT_H
    
// End of File

⌨️ 快捷键说明

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