/**********************************************************************************************
 * 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/ItemType.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                    : ItemType
// Long Name               : ItemType
// Element Name            : ItemType
// Class Namespace         : SimpleHierarchyLib
// Namespace Alias         : 
// Schema Namespace        : 
// Mapped Class Name       : CItemType
// Mapped Class Full Name  : SimpleHierarchyLib::CItemType
// Mapped Class File Name  : CItemType
// IsAbstract              : False
// IsElement               : True
// IsComplexType           : True

namespace SimpleHierarchyLib
{

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

CItemTypePtr CItemType::CreateInstance(LPCTSTR lpctElementName/*=_T("ItemType")*/)
{
    return new SimpleHierarchyLib::CItemType(lpctElementName);
}

/*  
 * Constructor for CItemType
 *
 * 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
 */
CItemType::CItemType(LPCTSTR lpctElementName/*=_T("ItemType")*/)
 : CInstanceMonitor(_T("CItemType"))
{
    m_elementName = lpctElementName;
    Init();
}

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

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

void CItemType::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 CItemType::Init()
{
    Cleanup();

    this->m_StockCode = 0;
    this->m_Description = _T("");
    this->m_UnitCost = 0;
    this->m_Quantity = 0;
    


// ##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 CItemType::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib15::LtVariant& rValue)
{
    if (bRead)
    {
        switch(iPropertyIndex)
        {
        case 1:
                rValue.SetUI8(GetStockCode());
            break;
        case 2:
                rValue.SetString(GetDescription());
            break;
        case 3:
                rValue.SetI8(GetUnitCost());
            break;
        case 4:
                rValue.SetUI4(GetQuantity());
            break;
        default:
            throw LtXmlLib15::CLtException(_T("Unknown Property Index"));
        };
    }
    else
    {
        switch(iPropertyIndex)
        {
        case 1:
            SetStockCode(rValue.GetUI8());
            break;
        case 2:
            SetDescription(rValue.GetString());
            break;
        case 3:
            SetUnitCost(rValue.GetI8());
            break;
        case 4:
            SetQuantity(rValue.GetUI4());
            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.
 */
DWORDLONG CItemType::GetStockCode() const
{
    return this->m_StockCode;
}
void CItemType::SetStockCode(DWORDLONG value)
{ 
    LtXmlLib15::LtVariant var;
    var.SetUI8(value);
    GetClassElementInfo()[0]->CheckRestriction(var);
    this->m_StockCode = 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.
 * It is defaulted to _T("").
 */
std::tstring CItemType::GetDescription() const
{
    return this->m_Description;
}
void CItemType::SetDescription(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[1]->CheckRestriction(var);
    this->m_Description = 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.
 * It is defaulted to 0.
 */
LONGLONG CItemType::GetUnitCost() const
{
    return this->m_UnitCost;
}
void CItemType::SetUnitCost(LONGLONG value)
{ 
    LtXmlLib15::LtVariant var;
    var.SetI8(value);
    GetClassElementInfo()[2]->CheckRestriction(var);
    this->m_UnitCost = 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.
 * It is defaulted to 0.
 */
DWORD CItemType::GetQuantity() const
{
    return this->m_Quantity;
}
void CItemType::SetQuantity(DWORD value)
{ 
    LtXmlLib15::LtVariant var;
    var.SetUI4(value);
    GetClassElementInfo()[3]->CheckRestriction(var);
    this->m_Quantity = value; 
}

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

    int index = 0;
    newObject->m_StockCode = m_StockCode;
    newObject->m_Description = m_Description;
    newObject->m_UnitCost = m_UnitCost;
    newObject->m_Quantity = m_Quantity;


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

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

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

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

LtXmlLib15Data::CParentElementInfo* CItemType::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("ItemType"),                  
                                                                            _T(""), 
                                                                            true,
                                                                            false,
                                                                            -1,
                                                                            LtXmlLib15::ItemType_none,
                                                                            NULL,
                                                                            false);
        }
        m_csInit.Leave();
    }
    
    return ms_pParentElementInfo;
}

LtXmlLib15Data::CElementInfo** CItemType::GetClassElementInfo() const
{
    if (ms_ppElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_ppElementInfo == NULL)
        {
            ms_ppElementInfo = new LtXmlLib15Data::CElementInfo*[5];
        
            ms_ppElementInfo[0] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("StockCode"), _T(""), 1, false, LtXmlLib15::ItemType_ui8, 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::CElementInfoSeqPrimMnd(_T("Description"), _T(""), 2, false, LtXmlLib15::ItemType_string, NULL, LtXmlLib15::CWhitespaceUtils::WhitespaceRule_Preserve, LtXmlLib15::CPrimitiveRestrictions(_T(""), _T("-1"), _T("-1"), _T(""), _T(""), _T(""), _T(""), _T("-1"), _T("-1"), _T("-1")));
            ms_ppElementInfo[2] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("UnitCost"), _T(""), 3, false, LtXmlLib15::ItemType_i8, NULL, LtXmlLib15::CWhitespaceUtils::WhitespaceRule_Collapse, LtXmlLib15::CPrimitiveRestrictions(_T(""), _T("-1"), _T("-1"), _T(""), _T(""), _T(""), _T(""), _T("-1"), _T("-1"), _T("-1")));
            ms_ppElementInfo[3] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("Quantity"), _T(""), 4, 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[4] = NULL;
        }
        m_csInit.Leave();
    }
    return ms_ppElementInfo;
}

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