/**********************************************************************************************
 * 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\MusicStore\Schema\MusicStore.xsd
 **********************************************************************************************/
#include "StdAfx.h" 
#pragma warning (push) 
#pragma warning (disable:4251)  // template export warning 
#pragma warning (disable:4786)  // long debug names 
#include "../MusicStoreLib.h" 
#include "../MusicStoreLib/SearchResponse.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                    : SearchResponse
// Long Name               : SearchResponse
// Element Name            : SearchResponse
// Class Namespace         : MusicStoreLib
// Namespace Alias         : 
// Schema Namespace        : 
// Mapped Class Name       : CSearchResponse
// Mapped Class Full Name  : MusicStoreLib::CSearchResponse
// Mapped Class File Name  : CSearchResponse
// IsAbstract              : False
// IsElement               : True
// IsComplexType           : False

namespace MusicStoreLib
{

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

CSearchResponsePtr CSearchResponse::CreateInstance(LPCTSTR lpctElementName/*=_T("SearchResponse")*/)
{
    return new MusicStoreLib::CSearchResponse(lpctElementName);
}

/*  
 * Constructor for CSearchResponse
 *
 * 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\MusicStore\Schema\MusicStore.xsd
 */
CSearchResponse::CSearchResponse(LPCTSTR lpctElementName/*=_T("SearchResponse")*/)
 : CInstanceMonitor(_T("CSearchResponse"))
{
    m_elementName = lpctElementName;
    Init();
}

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

void CSearchResponse::Cleanup()
{
    // unregister for any events we have asked for
    // cos there'll be no one left to hear soon
}

void CSearchResponse::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\MusicStore\Schema\MusicStore.xsd.
 */
void CSearchResponse::Init()
{
    Cleanup();

    this->m_Result = NULL;
    this->m_Error = 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 CSearchResponse::ClearChoice(LPCTSTR lpctSelectedElement)
{
    this->m_Result = NULL;
    this->m_Error = NULL;

    m_validElement = lpctSelectedElement;
}

void CSearchResponse::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib15::LtVariant& rValue)
{
    if (bRead)
    {
        switch(iPropertyIndex)
        {
        case 1:
                rValue.SetXmlObject(GetResult().Ptr());
            break;
        case 2:
                rValue.SetXmlObject(GetError().Ptr());
            break;
        default:
            throw LtXmlLib15::CLtException(_T("Unknown Property Index"));
        };
    }
    else
    {
        switch(iPropertyIndex)
        {
        case 1:
            SetResult(dynamic_cast<MusicStoreLib::CResult*>(rValue.GetXmlObject().Ptr()));
            break;
        case 2:
            SetError(dynamic_cast<MusicStoreLib::CError*>(rValue.GetXmlObject().Ptr()));
            break;
        default:
            throw LtXmlLib15::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
 */
MusicStoreLib::CResultPtr CSearchResponse::GetResult() const
{ 
    return this->m_Result;  
}
void CSearchResponse::SetResult(MusicStoreLib::CResult* value)
{ 
    // Ensure only on element is populated at a time
    ClearChoice(value == NULL?_T(""):_T("Result"));
    if (value == NULL)
        this->m_Result = NULL;
    else
    {
        SetElementName(value, _T("Result"));
        this->m_Result = 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.
 * 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
 */
MusicStoreLib::CErrorPtr CSearchResponse::GetError() const
{ 
    return this->m_Error;  
}
void CSearchResponse::SetError(MusicStoreLib::CError* value)
{ 
    // Ensure only on element is populated at a time
    ClearChoice(value == NULL?_T(""):_T("Error"));
    if (value == NULL)
        this->m_Error = NULL;
    else
    {
        SetElementName(value, _T("Error"));
        this->m_Error = value; 
    }
}

std::tstring CSearchResponse::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)
 */
MusicStoreLib::CSearchResponsePtr CSearchResponse::Clone() const
{
    MusicStoreLib::CSearchResponsePtr newObject = CreateInstance(m_elementName.c_str());

    int index = 0;
    newObject->m_Result = NULL;
    if (m_Result != NULL)
        newObject->m_Result = dynamic_cast<MusicStoreLib::CResult*>(m_Result->Clone().Ptr());
    newObject->m_Error = NULL;
    if (m_Error != NULL)
        newObject->m_Error = dynamic_cast<MusicStoreLib::CError*>(m_Error->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 CSearchResponse::GetTargetNamespace() const
{
    return _T("");
}   

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

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

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

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

LtXmlLib15Data::CElementInfo** CSearchResponse::GetClassElementInfo() const
{
    if (ms_ppElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_ppElementInfo == NULL)
        {
            ms_ppElementInfo = new LtXmlLib15Data::CElementInfo*[3];
        
            ms_ppElementInfo[0] = new LtXmlLib15Data::CElementInfoChoiceClsOpt(_T("Result"), _T(""), 1, LtXmlLib15Data::XmlElementType_ELEMENT, (LtXmlLib15Data::pfnCreateClassDef)MusicStoreLib::CClassFactory::CreateClass, MusicStoreLib::CClassFactory::ClsName_CResult);
            ms_ppElementInfo[1] = new LtXmlLib15Data::CElementInfoChoiceClsOpt(_T("Error"), _T(""), 2, LtXmlLib15Data::XmlElementType_ELEMENT, (LtXmlLib15Data::pfnCreateClassDef)MusicStoreLib::CClassFactory::CreateClass, MusicStoreLib::CClassFactory::ClsName_CError);
            ms_ppElementInfo[2] = NULL;
        }
        m_csInit.Leave();
    }
    return ms_ppElementInfo;
}

LtXmlLib15Data::CAttributeInfo**    CSearchResponse::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