/**********************************************************************************************
 * Copyright (c) 2001-2017 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 15.0.1.7161
 * Using Schema: D:\Development2017\Liquid\Tools\DataBindingSamples\Samples\SimpleHierarchy\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/Invoice.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                    : Invoice
// Long Name               : Invoice
// Element Name            : Invoice
// Class Namespace         : SimpleHierarchyLib
// Namespace Alias         : 
// Schema Namespace        : 
// Mapped Class Name       : CInvoice
// Mapped Class Full Name  : SimpleHierarchyLib::CInvoice
// Mapped Class File Name  : CInvoice
// IsAbstract              : False
// IsElement               : True
// IsComplexType           : False

namespace SimpleHierarchyLib
{

LtXmlLib15Data::CParentElementInfo* CInvoice::ms_pParentElementInfo = NULL;
LtXmlLib15Data::CAttributeInfo** CInvoice::ms_ppAttributeInfo = NULL;
LtXmlLib15Data::CElementInfo** CInvoice::ms_ppElementInfo = NULL;

CInvoicePtr CInvoice::CreateInstance(LPCTSTR lpctElementName/*=_T("Invoice")*/)
{
    return new SimpleHierarchyLib::CInvoice(lpctElementName);
}

/*  
 * Constructor for CInvoice
 *
 * 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 D:\Development2017\Liquid\Tools\DataBindingSamples\Samples\SimpleHierarchy\Schema\SimpleHierarchy.xsd
 */
CInvoice::CInvoice(LPCTSTR lpctElementName/*=_T("Invoice")*/)
 : CInstanceMonitor(_T("CInvoice"))
{
    m_elementName = lpctElementName;
    Init();
}

CInvoice::~CInvoice()
{
    Cleanup();
}

void CInvoice::Cleanup()
{
    // unregister for any events we have asked for
    // cos there'll be no one left to hear soon
    this->m_Item = NULL;
}

void CInvoice::OnEvent(LtXmlLib15::CXmlObjectBase* pMsgSource, LtXmlLib15::IEventSink::MsgType eMsgType, void* pData)
{
    if (eMsgType == LtXmlLib15::IEventSink::MT_CollectionChangeEvent)
    {
    }
}

/*
 * 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 D:\Development2017\Liquid\Tools\DataBindingSamples\Samples\SimpleHierarchy\Schema\SimpleHierarchy.xsd.
 */
void CInvoice::Init()
{
    Cleanup();

    this->m_InvoiceNo = 0;
    this->m_DeliveryAddress = dynamic_cast<SimpleHierarchyLib::CAddressType*>(SimpleHierarchyLib::CClassFactory::CreateClass(SimpleHierarchyLib::CClassFactory::ClsName_CAddressType, _T("DeliveryAddress")).Ptr());
    this->m_BillingAddress = NULL;
    this->m_Item = dynamic_cast<SimpleHierarchyLib::CItemTypeCol*>(SimpleHierarchyLib::CClassFactory::CreateClassCollection(SimpleHierarchyLib::CClassFactory::ClsName_CItemTypeCol, _T("Item"), _T(""), 1, -1).Ptr());
    this->m_Payment = dynamic_cast<SimpleHierarchyLib::CPayment*>(SimpleHierarchyLib::CClassFactory::CreateClass(SimpleHierarchyLib::CClassFactory::ClsName_CPayment, _T("Payment")).Ptr());
    


// ##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 CInvoice::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib15::LtVariant& rValue)
{
    if (bRead)
    {
        switch(iPropertyIndex)
        {
        case 1:
                rValue.SetUI4(GetInvoiceNo());
            break;
        case 2:
                rValue.SetXmlObject(GetDeliveryAddress().Ptr());
            break;
        case 3:
                rValue.SetXmlObject(GetBillingAddress().Ptr());
            break;
        case 4:
            rValue.SetXmlCollection(GetItem().Ptr());
            break;
        case 5:
                rValue.SetXmlObject(GetPayment().Ptr());
            break;
        default:
            throw LtXmlLib15::CLtException(_T("Unknown Property Index"));
        };
    }
    else
    {
        switch(iPropertyIndex)
        {
        case 1:
            SetInvoiceNo(rValue.GetUI4());
            break;
        case 2:
            SetDeliveryAddress(dynamic_cast<SimpleHierarchyLib::CAddressType*>(rValue.GetXmlObject().Ptr()));
            break;
        case 3:
            SetBillingAddress(dynamic_cast<SimpleHierarchyLib::CAddressType*>(rValue.GetXmlObject().Ptr()));
            break;
        case 4:
            throw LtXmlLib15::CLtException(_T("Collections can not be set"));
            break;
        case 5:
            SetPayment(dynamic_cast<SimpleHierarchyLib::CPayment*>(rValue.GetXmlObject().Ptr()));
            break;
        default:
            throw LtXmlLib15::CLtException(_T("Unknown Property Index"));
        }
    }
}

/*
 * Represents a mandatory Element in the XML document
 *
 * 
 * This property is represented as an Element in the XML.
 * It is mandatory and therefore must be populated within the XML.
 * It is defaulted to 0.
 */
DWORD CInvoice::GetInvoiceNo() const
{
    return this->m_InvoiceNo;
}
void CInvoice::SetInvoiceNo(DWORD value)
{ 
    LtXmlLib15::LtVariant var;
    var.SetUI4(value);
    GetClassElementInfo()[0]->CheckRestriction(var);
    this->m_InvoiceNo = value; 
}

/*
 * Represents a mandatory Element in the XML document
 *
 * 
 * This property is represented as an Element in the XML.
 * It is mandatory and therefore must be populated within the XML.
 * If this property is set, then the object will be COPIED. If the property is set to NULL an exception is raised.
 */
SimpleHierarchyLib::CAddressTypePtr CInvoice::GetDeliveryAddress() const
{ 
    return this->m_DeliveryAddress;  
}
void CInvoice::SetDeliveryAddress(SimpleHierarchyLib::CAddressType* value)
{ 
    Throw_IfPropertyIsNull(value, _T("DeliveryAddress"));
    if (value != NULL)
        SetElementName(value, _T("DeliveryAddress"));
    this->m_DeliveryAddress = value; 
}

/*
 * 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.
 */
SimpleHierarchyLib::CAddressTypePtr CInvoice::GetBillingAddress() const
{ 
    return this->m_BillingAddress;  
}
void CInvoice::SetBillingAddress(SimpleHierarchyLib::CAddressType* value)
{ 
    if (value == NULL)
        this->m_BillingAddress = NULL;
    else
    {
        SetElementName(value, _T("BillingAddress"));
        this->m_BillingAddress = value; 
    }
}

/*
 * A collection of CInvoices
 *
 * 
 * This property is represented as an Element in the XML.
 * This collection may contain 1 to Many objects.
 */
SimpleHierarchyLib::CItemTypeColPtr CInvoice::GetItem() const
{
    return this->m_Item; 
}

/*
 * Represents a mandatory Element in the XML document
 *
 * 
 * This property is represented as an Element in the XML.
 * It is mandatory and therefore must be populated within the XML.
 * If this property is set, then the object will be COPIED. If the property is set to NULL an exception is raised.
 */
SimpleHierarchyLib::CPaymentPtr CInvoice::GetPayment() const
{ 
    return this->m_Payment;  
}
void CInvoice::SetPayment(SimpleHierarchyLib::CPayment* value)
{ 
    Throw_IfPropertyIsNull(value, _T("Payment"));
    if (value != NULL)
        SetElementName(value, _T("Payment"));
    this->m_Payment = value; 
}

/*
 * Allows the class to be copied
 * Performs a 'deep copy' of all the data in the class (and its children)
 */
SimpleHierarchyLib::CInvoicePtr CInvoice::Clone() const
{
    SimpleHierarchyLib::CInvoicePtr newObject = CreateInstance(m_elementName.c_str());

    int index = 0;
    newObject->m_InvoiceNo = m_InvoiceNo;
    newObject->m_DeliveryAddress = NULL;
    if (m_DeliveryAddress != NULL)
        newObject->m_DeliveryAddress = dynamic_cast<SimpleHierarchyLib::CAddressType*>(m_DeliveryAddress->Clone().Ptr());
    newObject->m_BillingAddress = NULL;
    if (m_BillingAddress != NULL)
        newObject->m_BillingAddress = dynamic_cast<SimpleHierarchyLib::CAddressType*>(m_BillingAddress->Clone().Ptr());
    for (index = 0; index < m_Item->GetCount(); index++)
        newObject->m_Item->Add(dynamic_cast<SimpleHierarchyLib::CItemType*>(m_Item->Item(index)->Clone().Ptr()));
    newObject->m_Payment = NULL;
    if (m_Payment != NULL)
        newObject->m_Payment = dynamic_cast<SimpleHierarchyLib::CPayment*>(m_Payment->Clone().Ptr());


// ##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 CInvoice::GetTargetNamespace() const
{
    return _T("");
}   

std::tstring CInvoice::GetNamespace() const
{
    return _T("");
}   

LtXmlLib15::CXmlObjectBase* CInvoice::GetBase()
{
    return this;
}   

void CInvoice::CleanMetaData()
{
    LtXmlLib15::CXmlGeneratedClass::CleanMetaData(ms_pParentElementInfo, ms_ppElementInfo, ms_ppAttributeInfo);
}

LtXmlLib15Data::CParentElementInfo* CInvoice::GetClassInfo() const
{
    if (ms_pParentElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_pParentElementInfo == NULL)
        {
            ms_pParentElementInfo = new LtXmlLib15Data::CParentElementInfo(
                                                                            LtXmlLib15Data::XmlElementGroupType_SEQUENCE,
                                                                            LtXmlLib15Data::XmlElementType_ELEMENT, 
                                                                            _T("Invoice"),                   
                                                                            _T(""), 
                                                                            true,
                                                                            false,
                                                                            -1,
                                                                            LtXmlLib15::ItemType_none,
                                                                            NULL,
                                                                            false);
        }
        m_csInit.Leave();
    }
    
    return ms_pParentElementInfo;
}

LtXmlLib15Data::CElementInfo** CInvoice::GetClassElementInfo() const
{
    if (ms_ppElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_ppElementInfo == NULL)
        {
            ms_ppElementInfo = new LtXmlLib15Data::CElementInfo*[6];
        
            ms_ppElementInfo[0] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("InvoiceNo"), _T(""), 1, false, LtXmlLib15::ItemType_ui4, NULL, LtXmlLib15::CWhitespaceUtils::WhitespaceRule_Collapse, LtXmlLib15::CPrimitiveRestrictions(_T(""), _T("-1"), _T("-1"), _T(""), _T(""), _T(""), _T(""), _T("-1"), _T("-1"), _T("-1")));
            ms_ppElementInfo[1] = new LtXmlLib15Data::CElementInfoSeqClsMnd(_T("DeliveryAddress"), _T(""), 2, LtXmlLib15Data::XmlElementType_ELEMENT, (LtXmlLib15Data::pfnCreateClassDef)&SimpleHierarchyLib::CClassFactory::CreateClass, SimpleHierarchyLib::CClassFactory::ClsName_CAddressType, true);
            ms_ppElementInfo[2] = new LtXmlLib15Data::CElementInfoSeqClsOpt(_T("BillingAddress"), _T(""), 3, LtXmlLib15Data::XmlElementType_ELEMENT, (LtXmlLib15Data::pfnCreateClassDef)&SimpleHierarchyLib::CClassFactory::CreateClass, SimpleHierarchyLib::CClassFactory::ClsName_CAddressType);
            ms_ppElementInfo[3] = new LtXmlLib15Data::CElementInfoSeqClsCol(_T("Item"), _T(""), 4, LtXmlLib15Data::XmlElementType_ELEMENT);
            ms_ppElementInfo[4] = new LtXmlLib15Data::CElementInfoSeqClsMnd(_T("Payment"), _T(""), 5, LtXmlLib15Data::XmlElementType_ELEMENT, (LtXmlLib15Data::pfnCreateClassDef)&SimpleHierarchyLib::CClassFactory::CreateClass, SimpleHierarchyLib::CClassFactory::ClsName_CPayment, true);
            ms_ppElementInfo[5] = NULL;
        }
        m_csInit.Leave();
    }
    return ms_ppElementInfo;
}

LtXmlLib15Data::CAttributeInfo**    CInvoice::GetClassAttributeInfo() const
{
    if (ms_ppAttributeInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_ppAttributeInfo == NULL)
        {
            ms_ppAttributeInfo = new LtXmlLib15Data::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