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

📄 el_coll.cpp

📁 PQDIF软件包(SDK,Software Development Kit),它能转换、生成并且显示PQDIF文件.对于开发电力系统的数据输出非常有用。
💻 CPP
字号:
/*
**  CPQDIF_E_Collection class. Implements the PQDIF collection element.
**  --------------------------------------------------------------------------
**
**  File name:          $Workfile: el_coll.cpp $
**  Last modified:      $Modtime: 8/05/98 9:16a $
**  Last modified by:   $Author: Rob $
**
**  VCS archive path:   $Archive: /Hank/DMM/FirmWare/Level3/ObDatMgr/el_coll.cpp $
**  VCS revision:       $Revision: 10 $ 
*/
#include "PQDIF_classes.h"



//  Local constants
const char cTerminator = '\0';


//  Construction
//  ============

CPQDIF_E_Collection::CPQDIF_E_Collection()
{
    //  No init required
}


CPQDIF_E_Collection::~CPQDIF_E_Collection()
{
    //  Everything is automatically destroyed
    long    count = GetCount();
    long    idx;
    CPQDIF_Element *    pel;

    //  Destroy all objects in the array
    for( idx = 0; idx < count; idx++ )
    {
        pel = GetElement( idx );
        ASSERT_VALID( pel );
        if( pel )
        {
            delete pel;
        }
    }   //  for( idx )
}


long CPQDIF_E_Collection::GetCount( void ) const
{
    return m_array.size();
}


CPQDIF_Element * CPQDIF_E_Collection::GetElement( long index )
{
    CPQDIF_Element *    pel = NULL;

    if( index >= 0 && index < GetCount() )
    {
        pel = m_array[ index ];
    }

    return pel;
}


const CPQDIF_Element * CPQDIF_E_Collection::GetElement( long index ) const
{
    const   CPQDIF_Element *    pel = NULL;

    if( index >= 0 && index < GetCount() )
    {
        pel = m_array[ index ];
    }

    return pel;
}


CPQDIF_Element * CPQDIF_E_Collection::GetElement( const GUID& tag )
{
    CPQDIF_Element *    pelReturn = NULL;
    long        count;
    long        idx;

    CPQDIF_Element *    pelToCompare = NULL;
    GUID                tagToCompare;

    //  See if this tag is in here
    count = GetCount();
    for( idx = 0; idx < count; idx++ )
    {
        pelToCompare = GetElement( idx );
        if( pelToCompare )
        {
            tagToCompare = pelToCompare->GetTag();

            //  Matching tags?
            if( PQDIF_IsEqualGUID( tagToCompare, tag ) )
            {
                //  Yup! Return it!
                pelReturn = pelToCompare;
                break;
            }
        }
    }

    return pelReturn;
}


const CPQDIF_Element * CPQDIF_E_Collection::GetElement( const GUID& tag ) const
{
    const   CPQDIF_Element *    pelReturn = NULL;
            long        count;
            long        idx;

    const   CPQDIF_Element *    pelToCompare = NULL;
            GUID                tagToCompare;

    //  See if this tag is in here
    count = GetCount();
    for( idx = 0; idx < count; idx++ )
    {
        pelToCompare = GetElement( idx );
        if( pelToCompare )
        {
            tagToCompare = pelToCompare->GetTag();

            //  Matching tags?
            if( PQDIF_IsEqualGUID( tagToCompare, tag ) )
            {
                //  Yup! Return it!
                pelReturn = pelToCompare;
                break;
            }
        }
    }

    return pelReturn;
}


bool CPQDIF_E_Collection::GetChanged( void ) const
{
    bool    changed = m_changed;

        //  If any ONE object has been changed, return TRUE.
    if( !changed )
    {
                long    count = GetCount();
                long    idx;
        const   CPQDIF_Element *    pel = NULL;

        //  See if any objects in our array have changed...
        for( idx = 0; idx < count; idx++ )
        {
            pel = GetElement( idx );
            ASSERT_VALID( pel );
            if( pel )
            {
                if( pel->GetChanged() )
                {
                    changed = TRUE;
                    break;
                }
            }
        }   //  for( idx )
    }

    return changed;
}


void CPQDIF_E_Collection::SetChanged( bool changed )
{
    long                count = GetCount();
    long                idx;
    CPQDIF_Element *    pel;

    m_changed = changed;

    //  Do the same thing to the objects we own
    for( idx = 0; idx < count; idx++ )
    {
        pel = GetElement( idx );
        ASSERT_VALID( pel );
        if( pel )
        {
            pel->SetChanged( changed );
        }
    }   //  for( idx )

    return;
}


void CPQDIF_E_Collection::Add( CPQDIF_Element * pel )
{
    m_array.push_back( pel );
    m_changed = true;
}


void CPQDIF_E_Collection::InsertAt( long index, CPQDIF_Element * pel )
{
//    ASSERT( index <= GetCount() );
    if( index >= 0 && index <= GetCount() )
{
        CArrayElements::iterator where = m_array.begin();
        where += index;

        m_array.insert( where, pel );

        m_changed = true;
}
}


//  Should this delete the element or not?
void CPQDIF_E_Collection::RemoveAt( long index )
{
//    ASSERT( index < GetCount() );
    if( index >= 0 && index < GetCount() )
    {
        CArrayElements::iterator where = m_array.begin();
        where += index;

        //  Delete the element? No, for now; this was the original behavior.
        //CPQDIF_Element * pel = m_array[ where ];
        //if( pel )
        //    delete pel;

        //  Remove it from the list.
        m_array.erase( where );

        m_changed = true;
    }
}


void CPQDIF_E_Collection::AddOrReplace( CPQDIF_Element * pel )
{
    long        count;
    long        idx;

    CPQDIF_Element *    pelToCompare = NULL;
    GUID                tagToAdd;
    GUID                tagToCompare;

    //  Init
    count = GetCount();
    tagToAdd = pel->GetTag();

    //  See if this tag already exists
    for( idx = 0; idx < count; idx++ )
    {
        pelToCompare = GetElement( idx );
        if( pelToCompare )
        {
            tagToCompare = pelToCompare->GetTag();

            //  Matching tags?
            if( PQDIF_IsEqualGUID( tagToCompare, tagToAdd ) )
            {
                //  Yup! Remove this entry.
                delete pelToCompare;
                RemoveAt( idx );
                break;
            }
        }
    }

    //  Either way, add the new one
    Add( pel );

    return;
}


void CPQDIF_E_Collection::SetVectorString
            ( 
            const   GUID&   tagElement,
            const   char *  text,
                    bool    allowReplace
            )
{
    CPQDIF_E_Vector *   pvectString;

    if( text )
    {
        //  Create the new vector to hold the string
        pvectString = (CPQDIF_E_Vector *) theFactory.NewElement( ID_ELEMENT_TYPE_VECTOR );
        if( pvectString )
        {
            //  Set it up ...
            pvectString->SetTag( tagElement );
            pvectString->SetPhysicalType( ID_PHYS_TYPE_CHAR1 );
            pvectString->SetValues( text );

            //  Add it
            if( allowReplace )
                AddOrReplace( pvectString );
            else
                Add( pvectString );
        }
    }
}


//  Parameterized SetVector...() functions
//  ======================================
#define SETVECTOR( nametype, type, idtype ) \
void CPQDIF_E_Collection::SetVector##nametype \
        (   const   GUID&   tagElement, \
            const   type *  values, \
                    long    count, \
                    bool    allowReplace ) \
{ \
    CPQDIF_E_Vector *   pvect; \
    if( values ) \
    { \
        /*  Create the new vector to hold the string */ \
        pvect = (CPQDIF_E_Vector *) theFactory.NewElement( ID_ELEMENT_TYPE_VECTOR ); \
        if( pvect ) \
        { \
            /*  Set it up ... */ \
            pvect->SetTag( tagElement ); \
            pvect->SetPhysicalType( idtype ); \
            pvect->SetValues##nametype( values, count ); \
            /*  Add it */ \
            if( allowReplace ) \
                AddOrReplace( pvect ); \
            else \
                Add( pvect ); \
        } \
    } \
}


SETVECTOR( INT1, INT1, ID_PHYS_TYPE_INTEGER1 );
SETVECTOR( INT2, INT2, ID_PHYS_TYPE_INTEGER2 );
SETVECTOR( INT4, INT4, ID_PHYS_TYPE_INTEGER4 );
SETVECTOR( UINT4, UINT4, ID_PHYS_TYPE_UNS_INTEGER4 );
SETVECTOR( REAL4, REAL4, ID_PHYS_TYPE_REAL4 );
SETVECTOR( REAL8, REAL8, ID_PHYS_TYPE_REAL8 );
SETVECTOR( TimeStamp, TIMESTAMPPQDIF, ID_PHYS_TYPE_TIMESTAMPPQDIF );


bool CPQDIF_E_Collection::GetVectorString
            ( 
            const   GUID&   tagElement,
                    char *  text,
                    long    max
            ) const
{
            bool                status = false;
    const   CPQDIF_Element *    pel;
            string              values;

    pel = GetElement( tagElement );
    if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR )
    {
        const CPQDIF_E_Vector *   pvect = (const CPQDIF_E_Vector *) pel;
        status = pvect->GetValues( values );
        if( status )
        {
            strncpy( text, values.c_str(), max );
            text[ max - 1 ] = cTerminator;
        }
    }

    return status;
}


//  Parameterized GetVector...() functions
//  ======================================
#define GETVECTOR( nametype, type ) \
long CPQDIF_E_Collection::GetVector##nametype \
            (  \
            const   GUID&   tagElement, \
                    type *  values, \
                    long    max \
            ) const \
{ \
            long                sizeActual = 0; \
    const   CPQDIF_Element *    pel; \
    pel = GetElement( tagElement ); \
    if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_VECTOR ) \
    { \
        const CPQDIF_E_Vector *   pvect = (const CPQDIF_E_Vector *) pel; \
        sizeActual = pvect->GetValues##nametype( values, max ); \
    } \
    return sizeActual; \
}


GETVECTOR( INT1, INT1 );
GETVECTOR( INT2, INT2 );
GETVECTOR( INT4, INT4 );
GETVECTOR( UINT4, UINT4 );
GETVECTOR( REAL4, REAL4 );
GETVECTOR( REAL8, REAL8 );
GETVECTOR( TimeStamp, TIMESTAMPPQDIF );


//  Parameterized SetScalar...() functions
//  ======================================
#define SETSCALAR( nametype, type ) \
void CPQDIF_E_Collection::SetScalar##nametype \
            (  \
            const   GUID&   tagElement, \
                    type    value, \
                    bool    allowReplace \
            ) \
{ \
    CPQDIF_E_Scalar *   psc; \
    psc = (CPQDIF_E_Scalar *) theFactory.NewElement( ID_ELEMENT_TYPE_SCALAR ); \
    if( psc ) \
    { \
        psc->SetTag( tagElement ); \
        psc->SetValue##nametype( value ); \
        if( allowReplace ) \
            AddOrReplace( psc ); \
        else \
            Add( psc ); \
    } \
}


SETSCALAR( BOOL4, bool )
SETSCALAR( INT2, INT2 )
SETSCALAR( UINT2, UINT2 )
SETSCALAR( INT4, INT4 )
SETSCALAR( UINT4, UINT4 )
SETSCALAR( REAL4, REAL4 )
SETSCALAR( REAL8, REAL8 )
SETSCALAR( COMPLEX8, COMPLEX8 )
SETSCALAR( COMPLEX16, COMPLEX16 )
SETSCALAR( GUID, GUID )
SETSCALAR( TimeStamp, TIMESTAMPPQDIF )


void CPQDIF_E_Collection::copy( const CPQDIF_E_Collection& obj )
{
    CPQDIF_Element::copy( obj );

    m_array = obj.m_array;
}


//  Parameterized GetScalar...() functions
//  ======================================
#define GETSCALAR( nametype, type ) \
bool CPQDIF_E_Collection::GetScalar##nametype \
        ( \
        const   GUID&       tagElement, \
                type&       value \
        ) const \
{ \
    bool    status = false; \
    const CPQDIF_Element *    pel; \
    pel = GetElement( tagElement ); \
    if( pel && pel->GetElementType() == ID_ELEMENT_TYPE_SCALAR ) \
    { \
        const CPQDIF_E_Scalar *   psc = (const CPQDIF_E_Scalar *) pel; \
        status = psc->GetValue##nametype( value ); \
    } \
    return status; \
}


GETSCALAR( BOOL4, bool )
GETSCALAR( INT2, INT2 )
GETSCALAR( UINT2, UINT2 )
GETSCALAR( INT4, INT4 )
GETSCALAR( UINT4, UINT4 )
GETSCALAR( REAL4, REAL4 )
GETSCALAR( REAL8, REAL8 )
GETSCALAR( COMPLEX8, COMPLEX8 )
GETSCALAR( COMPLEX16, COMPLEX16 )
GETSCALAR( GUID, GUID )
GETSCALAR( TimeStamp, TIMESTAMPPQDIF )

⌨️ 快捷键说明

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