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

namespace SimpleHierarchyLib
{

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

CAddressTypePtr CAddressType::CreateInstance(LPCTSTR lpctElementName/*=_T("AddressType")*/)
{
    return new SimpleHierarchyLib::CAddressType(lpctElementName);
}

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

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

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

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

    this->m_Forename = _T("");
    this->m_Surname = _T("");
    this->m_AddresLine1 = _T("");
    this->m_AddresLine2 = _T("");
    this->m_AddresLine3 = _T("");
    this->m_IsValidAddresLine3 = false;
    this->m_AddresLine4 = _T("");
    this->m_IsValidAddresLine4 = false;
    this->m_AddresLine5 = _T("");
    this->m_PostCode = _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 CAddressType::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib15::LtVariant& rValue)
{
    if (bRead)
    {
        switch(iPropertyIndex)
        {
        case 1:
                rValue.SetString(GetForename());
            break;
        case 2:
                rValue.SetString(GetSurname());
            break;
        case 3:
                rValue.SetString(GetAddresLine1());
            break;
        case 4:
                rValue.SetString(GetAddresLine2());
            break;
        case 5:
            if (IsValidAddresLine3())
                rValue.SetString(GetAddresLine3());
            else
                rValue.SetInvalid();
            break;
        case 6:
            if (IsValidAddresLine4())
                rValue.SetString(GetAddresLine4());
            else
                rValue.SetInvalid();
            break;
        case 7:
                rValue.SetString(GetAddresLine5());
            break;
        case 8:
                rValue.SetString(GetPostCode());
            break;
        default:
            throw LtXmlLib15::CLtException(_T("Unknown Property Index"));
        };
    }
    else
    {
        switch(iPropertyIndex)
        {
        case 1:
            SetForename(rValue.GetString());
            break;
        case 2:
            SetSurname(rValue.GetString());
            break;
        case 3:
            SetAddresLine1(rValue.GetString());
            break;
        case 4:
            SetAddresLine2(rValue.GetString());
            break;
        case 5:
            if (rValue.IsValid())
                SetAddresLine3(rValue.GetString());
            else
                SetValidAddresLine3(false);
            break;
        case 6:
            if (rValue.IsValid())
                SetAddresLine4(rValue.GetString());
            else
                SetValidAddresLine4(false);
            break;
        case 7:
            SetAddresLine5(rValue.GetString());
            break;
        case 8:
            SetPostCode(rValue.GetString());
            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 _T("").
 */
std::tstring CAddressType::GetForename() const
{
    return this->m_Forename;
}
void CAddressType::SetForename(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[0]->CheckRestriction(var);
    this->m_Forename = 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 CAddressType::GetSurname() const
{
    return this->m_Surname;
}
void CAddressType::SetSurname(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[1]->CheckRestriction(var);
    this->m_Surname = 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 CAddressType::GetAddresLine1() const
{
    return this->m_AddresLine1;
}
void CAddressType::SetAddresLine1(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[2]->CheckRestriction(var);
    this->m_AddresLine1 = 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 CAddressType::GetAddresLine2() const
{
    return this->m_AddresLine2;
}
void CAddressType::SetAddresLine2(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[3]->CheckRestriction(var);
    this->m_AddresLine2 = 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 not valid.
 */
std::tstring CAddressType::GetAddresLine3() const
{
    if (m_IsValidAddresLine3 == false)
        throw LtXmlLib15::CLtInvalidStateException(_T("The Property GetAddresLine3 is not valid. SetAddresLine3 must be called first"));
    return this->m_AddresLine3;
}
void CAddressType::SetAddresLine3(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[4]->CheckRestriction(var);
    this->m_IsValidAddresLine3 = true;

    this->m_AddresLine3 = value; 
}

/*
 * Indicates if GetAddresLine3 contains a valid value.
 *
 * true if the value for GetAddresLine3 is valid, false if not.
 * If this is set to true then the property is considered valid, and assigned its
 * default value (_T("")).
 * If its set to false then its made invalid, and subsequent calls to GetAddresLine3
 * will raise an exception.
 */
bool CAddressType::IsValidAddresLine3() const
{ 
    return m_IsValidAddresLine3;
}
void CAddressType::SetValidAddresLine3(bool value)
{ 
    if (value != m_IsValidAddresLine3)
    {
        this->m_AddresLine3 = _T("");
        m_IsValidAddresLine3 = 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 not valid.
 */
std::tstring CAddressType::GetAddresLine4() const
{
    if (m_IsValidAddresLine4 == false)
        throw LtXmlLib15::CLtInvalidStateException(_T("The Property GetAddresLine4 is not valid. SetAddresLine4 must be called first"));
    return this->m_AddresLine4;
}
void CAddressType::SetAddresLine4(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[5]->CheckRestriction(var);
    this->m_IsValidAddresLine4 = true;

    this->m_AddresLine4 = value; 
}

/*
 * Indicates if GetAddresLine4 contains a valid value.
 *
 * true if the value for GetAddresLine4 is valid, false if not.
 * If this is set to true then the property is considered valid, and assigned its
 * default value (_T("")).
 * If its set to false then its made invalid, and subsequent calls to GetAddresLine4
 * will raise an exception.
 */
bool CAddressType::IsValidAddresLine4() const
{ 
    return m_IsValidAddresLine4;
}
void CAddressType::SetValidAddresLine4(bool value)
{ 
    if (value != m_IsValidAddresLine4)
    {
        this->m_AddresLine4 = _T("");
        m_IsValidAddresLine4 = 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 CAddressType::GetAddresLine5() const
{
    return this->m_AddresLine5;
}
void CAddressType::SetAddresLine5(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[6]->CheckRestriction(var);
    this->m_AddresLine5 = 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 CAddressType::GetPostCode() const
{
    return this->m_PostCode;
}
void CAddressType::SetPostCode(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib15::CWhitespaceUtils::Preserve(value); 
    LtXmlLib15::LtVariant var;
    var.SetString(value);
    GetClassElementInfo()[7]->CheckRestriction(var);
    this->m_PostCode = value; 
}

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

    int index = 0;
    newObject->m_Forename = m_Forename;
    newObject->m_Surname = m_Surname;
    newObject->m_AddresLine1 = m_AddresLine1;
    newObject->m_AddresLine2 = m_AddresLine2;
    newObject->m_AddresLine3 = m_AddresLine3;
    newObject->m_IsValidAddresLine3 = m_IsValidAddresLine3;
    newObject->m_AddresLine4 = m_AddresLine4;
    newObject->m_IsValidAddresLine4 = m_IsValidAddresLine4;
    newObject->m_AddresLine5 = m_AddresLine5;
    newObject->m_PostCode = m_PostCode;


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

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

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

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

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

LtXmlLib15Data::CElementInfo** CAddressType::GetClassElementInfo() const
{
    if (ms_ppElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_ppElementInfo == NULL)
        {
            ms_ppElementInfo = new LtXmlLib15Data::CElementInfo*[9];
        
            ms_ppElementInfo[0] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("Forename"), _T(""), 1, 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[1] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("Surname"), _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("AddresLine1"), _T(""), 3, 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[3] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("AddresLine2"), _T(""), 4, 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[4] = new LtXmlLib15Data::CElementInfoSeqPrimOpt(_T("AddresLine3"), _T(""), 5, 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[5] = new LtXmlLib15Data::CElementInfoSeqPrimOpt(_T("AddresLine4"), _T(""), 6, 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[6] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("AddresLine5"), _T(""), 7, 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[7] = new LtXmlLib15Data::CElementInfoSeqPrimMnd(_T("PostCode"), _T(""), 8, 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[8] = NULL;
        }
        m_csInit.Leave();
    }
    return ms_ppElementInfo;
}

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