Liquid XML Data Binder 2020
In This Topic
    Payment.cpp
    In This Topic
    /**********************************************************************************************
     * Copyright (c) 2001-2020 Liquid Technologies Limited. All rights reserved.
     * See www.liquid-technologies.com for product details.
     *
     * Please see products End User License Agreement for distribution permissions.
     *
     * WARNING: THIS FILE IS GENERATED
     * Changes made outside of ##HAND_CODED_BLOCK_START blocks will be overwritten
     *
     * Generation  :  by Liquid XML Data Binder 17.0.1.9233
     * Using Schema: SimpleHierarchy.xsd
     **********************************************************************************************/
    #include "StdAfx.h" 
    #pragma warning (push) 
    #pragma warning (disable:4251)  // template export warning 
    #pragma warning (disable:4786)  // long debug names 
    #include "../SimpleHierarchyLib.h" 
    #include "../SimpleHierarchyLib/Payment.h" 
    
    // ##HAND_CODED_BLOCK_START ID="Additional Includes"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
    // Add Additional Includes here...
    
    // ##HAND_CODED_BLOCK_END ID="Additional Includes"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
    // Name                    : Payment
    // Long Name               : Payment
    // Element Name            : Payment
    // Class Namespace         : SimpleHierarchyLib
    // Namespace Alias         : 
    // Schema Namespace        : 
    // Mapped Class Name       : CPayment
    // Mapped Class Full Name  : SimpleHierarchyLib::CPayment
    // Mapped Class File Name  : CPayment
    // IsAbstract              : False
    // IsElement               : True
    // IsComplexType           : True
    
    namespace SimpleHierarchyLib
    {
    
    LtXmlLib18Data::CParentElementInfo* CPayment::ms_pParentElementInfo = NULL;
    LtXmlLib18Data::CAttributeInfo** CPayment::ms_ppAttributeInfo = NULL;
    LtXmlLib18Data::CElementInfo** CPayment::ms_ppElementInfo = NULL;
    
    CPaymentPtr CPayment::CreateInstance(LPCTSTR lpctElementName/*=_T("Payment")*/)
    {
        return new SimpleHierarchyLib::CPayment(lpctElementName);
    }
    
    /*  
     * Constructor for CPayment
     *
     * The class is created with all the mandatory fields populated with the
     * default data.
     * All Collection objects are created.
     * However any 1-n relationships (these are represented as collections) are
     * empty. To comply with the schema these must be populated before the xml
     * obtained from ToXml is valid against the schema SimpleHierarchy.xsd
     */
    CPayment::CPayment(LPCTSTR lpctElementName/*=_T("Payment")*/)
     : CInstanceMonitor(_T("CPayment"))
    {
        m_elementName = lpctElementName;
        Init();
    }
    
    CPayment::~CPayment()
    {
        Cleanup();
    }
    
    void CPayment::Cleanup()
    {
        // unregister for any events we have asked for
        // cos there'll be no one left to hear soon
        if (this->m_Vouchers != NULL)
            this->m_Vouchers->RemoveEventListener(this);
        this->m_Vouchers = NULL;
    }
    
    void CPayment::OnEvent(LtXmlLib18::CXmlObjectBase* pMsgSource, LtXmlLib18::IEventSink::MsgType eMsgType, void* pData)
    {
        if (eMsgType == LtXmlLib18::IEventSink::MT_CollectionChangeEvent)
        {
            if (this->m_Vouchers != NULL && this->m_Vouchers->GetBase() == pMsgSource)
            {
                // The class represents a choice, so prevent more than one element from being selected
                ClearChoice(this->m_Vouchers->GetCount()==0?_T(""):_T("Vouchers"));
            }
        }
    }
    
    /*
     * Initializes the class
     *
     * The Creates all the mandatory fields (populated with the default data) 
     * All Collection object are created.
     * However any 1-n relationships (these are represented as collections) are
     * empty. To comply with the schema these must be populated before the xml
     * obtained from ToXml is valid against the schema SimpleHierarchy.xsd.
     */
    void CPayment::Init()
    {
        Cleanup();
    
        this->m_VISA = NULL;
        this->m_Vouchers = dynamic_cast<SimpleHierarchyLib::CVouchersCol*>(SimpleHierarchyLib::CClassFactory::CreateClassCollection(SimpleHierarchyLib::CClassFactory::ClsName_CVouchersCol, _T("Vouchers"), _T(""), 1, -1).Ptr());
        this->m_Vouchers->AddEventListener(this);
        this->m_Cash = NULL;
        
        m_validElement = _T("");
    
    
    // ##HAND_CODED_BLOCK_START ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
    // Add Additional Init Settings...
    
    // ##HAND_CODED_BLOCK_END ID="Additional Inits"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    }
        
    void CPayment::ClearChoice(LPCTSTR lpctSelectedElement)
    {
        this->m_VISA = NULL;
        if (this->m_Vouchers != NULL)
        {
            if (_tcscmp(_T("Vouchers"), lpctSelectedElement) != 0)
                this->m_Vouchers->Clear();
        }
        this->m_Cash = NULL;
    
        m_validElement = lpctSelectedElement;
    }
    
    void CPayment::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib18::LtVariant& rValue)
    {
        if (bRead)
        {
            switch(iPropertyIndex)
            {
            case 1:
                    rValue.SetXmlObject(GetVISA().Ptr());
                break;
            case 2:
                rValue.SetXmlCollection(GetVouchers().Ptr());
                break;
            case 3:
                    rValue.SetXmlObject(GetCash().Ptr());
                break;
            default:
                throw LtXmlLib18::CLtException(_T("Unknown Property Index"));
            };
        }
        else
        {
            switch(iPropertyIndex)
            {
            case 1:
                SetVISA(dynamic_cast<SimpleHierarchyLib::CVISA*>(rValue.GetXmlObject().Ptr()));
                break;
            case 2:
                throw LtXmlLib18::CLtException(_T("Collections can not be set"));
                break;
            case 3:
                SetCash(dynamic_cast<LtXmlLib18::CElement*>(rValue.GetXmlObject().Ptr()));
                break;
            default:
                throw LtXmlLib18::CLtException(_T("Unknown Property Index"));
            }
        }
    }
    
    /*
     * Represents an optional Element in the XML document
     *
     * 
     * This property is represented as an Element in the XML.
     * It is optional, initially it is NULL.
     * Only one Element within this class may be set at a time, setting this property when another element is already set will raise an exception. setting this property to NULL will allow another element to be selected
     */
    SimpleHierarchyLib::CVISAPtr CPayment::GetVISA() const
    { 
        return this->m_VISA;  
    }
    void CPayment::SetVISA(SimpleHierarchyLib::CVISA* value)
    { 
        // Ensure only on element is populated at a time
        ClearChoice(value == NULL?_T(""):_T("VISA"));
        if (value == NULL)
            this->m_VISA = NULL;
        else
        {
            SetElementName(value, _T("VISA"));
            this->m_VISA = value; 
        }
    }
    
    /*
     * A collection of CPayments
     *
     * 
     * This property is represented as an Element in the XML.
     * This collection may contain 1 to Many objects.
     * Only one Element within this class may be set at a time. This collection (as a whole is counted as an element) may contain 0 or 1 to Many entries. Emptying the collection allows a different element to be the selected one. If there is already a selected element, and an item is added to this collection then an exception will be raised
     */
    SimpleHierarchyLib::CVouchersColPtr CPayment::GetVouchers() const
    {
        return this->m_Vouchers; 
    }
    
    /*
     * Represents an optional untyped element in the XML document
     *
     * 
     * It is optional, initially it is null.
     * Only one Element within this class may be set at a time, setting this property when another element is already set will raise an exception. setting this property to null will allow another element to be selected
     */
    LtXmlLib18::CElementPtr CPayment::GetCash() const
    { 
        return this->m_Cash;  
    }
    void CPayment::SetCash(LtXmlLib18::CElement* value)
    { 
        if (value != NULL)
            TestNamespace(value->GetNamespace().c_str(), _T("##any"), _T(""));
        ClearChoice(value==NULL?_T(""):_T("Cash"));
        this->m_Cash = value; 
    }
    
    std::tstring CPayment::GetChoiceSelectedElement() const
    {
        return m_validElement; 
    }
    
    /*
     * Allows the class to be copied
     * Performs a 'deep copy' of all the data in the class (and its children)
     */
    SimpleHierarchyLib::CPaymentPtr CPayment::Clone() const
    {
        SimpleHierarchyLib::CPaymentPtr newObject = CreateInstance(m_elementName.c_str());
    
        int index = 0;
        newObject->m_VISA = NULL;
        if (m_VISA != NULL)
            newObject->m_VISA = dynamic_cast<SimpleHierarchyLib::CVISA*>(m_VISA->Clone().Ptr());
        for (index = 0; index < m_Vouchers->GetCount(); index++)
            newObject->m_Vouchers->Add(dynamic_cast<SimpleHierarchyLib::CVouchers*>(m_Vouchers->Item(index)->Clone().Ptr()));
        newObject->m_Cash = NULL;
        if (m_Cash != NULL)
            newObject->m_Cash = dynamic_cast<LtXmlLib18::CElement*>(m_Cash->Clone().Ptr());
    
        newObject->m_validElement = m_validElement;
    
    // ##HAND_CODED_BLOCK_START ID="Additional clone"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
    // Add Additional clone code here...
    
    // ##HAND_CODED_BLOCK_END ID="Additional clone"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
        return newObject.Ptr();
    }
    
    std::tstring CPayment::GetTargetNamespace() const
    {
        return _T("");
    }   
    
    std::tstring CPayment::GetNamespace() const
    {
        return _T("");
    }   
    
    LtXmlLib18::CXmlObjectBase* CPayment::GetBase()
    {
        return this;
    }   
    
    void CPayment::CleanMetaData()
    {
        LtXmlLib18::CXmlGeneratedClass::CleanMetaData(ms_pParentElementInfo, ms_ppElementInfo, ms_ppAttributeInfo);
    }
    
    LtXmlLib18Data::CParentElementInfo* CPayment::GetClassInfo() const
    {
        if (ms_pParentElementInfo == NULL)
        {
            m_csInit.Enter();
            if (ms_pParentElementInfo == NULL)
            {
                ms_pParentElementInfo = new LtXmlLib18Data::CParentElementInfo(
                                                                                LtXmlLib18Data::XmlElementGroupType_CHOICE,
                                                                                LtXmlLib18Data::XmlElementType_ELEMENT, 
                                                                                _T("Payment"),                   
                                                                                _T(""), 
                                                                                true,
                                                                                false,
                                                                                -1,
                                                                                LtXmlLib18::ItemType_none,
                                                                                NULL,
                                                                                false);
            }
            m_csInit.Leave();
        }
        
        return ms_pParentElementInfo;
    }
    
    LtXmlLib18Data::CElementInfo** CPayment::GetClassElementInfo() const
    {
        if (ms_ppElementInfo == NULL)
        {
            m_csInit.Enter();
            if (ms_ppElementInfo == NULL)
            {
                ms_ppElementInfo = new LtXmlLib18Data::CElementInfo*[4];
            
                ms_ppElementInfo[0] = new LtXmlLib18Data::CElementInfoChoiceClsOpt(_T("VISA"), _T(""), 1, LtXmlLib18Data::XmlElementType_ELEMENT, (LtXmlLib18Data::pfnCreateClassDef)SimpleHierarchyLib::CClassFactory::CreateClass, SimpleHierarchyLib::CClassFactory::ClsName_CVISA);
                ms_ppElementInfo[1] = new LtXmlLib18Data::CElementInfoChoiceClsCol(_T("Vouchers"), _T(""), 2, LtXmlLib18Data::XmlElementType_ELEMENT);
                ms_ppElementInfo[2] = new LtXmlLib18Data::CElementInfoChoiceUntpdOpt(_T("Cash"), _T(""), 3, _T("##any"), _T(""));
                ms_ppElementInfo[3] = NULL;
            }
            m_csInit.Leave();
        }
        return ms_ppElementInfo;
    }
    
    LtXmlLib18Data::CAttributeInfo**    CPayment::GetClassAttributeInfo() const
    {
        if (ms_ppAttributeInfo == NULL)
        {
            m_csInit.Enter();
            if (ms_ppAttributeInfo == NULL)
            {
                ms_ppAttributeInfo = new LtXmlLib18Data::CAttributeInfo*[1];
                ms_ppAttributeInfo[0] = NULL;
            }
            m_csInit.Leave();
        }
        return ms_ppAttributeInfo;
    }
    
    // ##HAND_CODED_BLOCK_START ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
    // Add Additional Methods here...
    
    // ##HAND_CODED_BLOCK_END ID="Additional Methods"## DO NOT MODIFY ANYTHING OUTSIDE OF THESE TAGS
    
    }; // namespace