MyRootObject.cpp
/**********************************************************************************************
 * Copyright (c) 2001-2025 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 19.0.14.11049
 * Using Schema: Cardinality.xsd
 **********************************************************************************************/
#include "StdAfx.h" 
#pragma warning (push) 
#pragma warning (disable:4251)  // template export warning 
#pragma warning (disable:4786)  // long debug names 
#include "../CardinalityLib.h" 
#include "../CardinalityLib/MyRootObject.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                    : MyRootObject
// Long Name               : MyRootObject
// Element Name            : MyRootObject
// Class Namespace         : CardinalityLib
// Namespace Alias         : 
// Schema Namespace        : 
// Mapped Class Name       : CMyRootObject
// Mapped Class Full Name  : CardinalityLib::CMyRootObject
// Mapped Class File Name  : CMyRootObject
// IsAbstract              : False
// IsElement               : True
// IsComplexType           : False

namespace CardinalityLib
{

LtXmlLib21Data::CParentElementInfo* CMyRootObject::ms_pParentElementInfo = NULL;
LtXmlLib21Data::CAttributeInfo** CMyRootObject::ms_ppAttributeInfo = NULL;
LtXmlLib21Data::CElementInfo** CMyRootObject::ms_ppElementInfo = NULL;

CMyRootObjectPtr CMyRootObject::CreateInstance(LPCTSTR lpctElementName/*=_T("MyRootObject")*/)
{
    return new CardinalityLib::CMyRootObject(lpctElementName);
}

/*  
 * Constructor for CMyRootObject
 *
 * 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 Cardinality.xsd
 */
CMyRootObject::CMyRootObject(LPCTSTR lpctElementName/*=_T("MyRootObject")*/)
 : CInstanceMonitor(_T("CMyRootObject"))
 , m_ASimpleDateMandatoryElement(LtXmlLib21::CDateTime::dt_date)
 , m_ASimpleDateOptionalElement(LtXmlLib21::CDateTime::dt_date)
{
    m_elementName = lpctElementName;
    Init();
}

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

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

void CMyRootObject::OnEvent(LtXmlLib21::CXmlObjectBase* pMsgSource, LtXmlLib21::IEventSink::MsgType eMsgType, void* pData)
{
    if (eMsgType == LtXmlLib21::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 Cardinality.xsd.
 */
void CMyRootObject::Init()
{
    Cleanup();

    this->m_ASimpleStringMandatoryElement = _T("");
    this->m_ASimpleDateMandatoryElement = LtXmlLib21::CDateTime(LtXmlLib21::CDateTime::dt_date);
    this->m_AComplexMandatoryElement = dynamic_cast<CardinalityLib::CAComplexMandatoryElement*>(CardinalityLib::CClassFactory::CreateClass(CardinalityLib::CClassFactory::ClsName_CAComplexMandatoryElement, _T("AComplexMandatoryElement")).Ptr());
    this->m_ASimpleStringOptionalElement = _T("");
    this->m_IsValidASimpleStringOptionalElement = false;
    this->m_ASimpleDateOptionalElement = LtXmlLib21::CDateTime(LtXmlLib21::CDateTime::dt_date);
    this->m_IsValidASimpleDateOptionalElement = false;
    this->m_AComplexOptionalElement = NULL;
    this->m_ASimpleStringCollectionElement = new LtXmlLib21::CstringCol(_T("ASimpleStringCollectionElement"), _T(""), 0, -1, _T(""), -1, -1, _T(""), _T(""), _T(""), _T(""), -1, -1, -1, LtXmlLib21::CWhitespaceUtils::WhitespaceRule_Preserve, NULL);
    this->m_ASimpleDateCollectionElement = new LtXmlLib21::CdateCol(_T("ASimpleDateCollectionElement"), _T(""), 0, -1, _T(""), -1, -1, _T(""), _T(""), _T(""), _T(""), -1, -1, -1, LtXmlLib21::CWhitespaceUtils::WhitespaceRule_Collapse, NULL);
    this->m_AComplexCollectionElement = dynamic_cast<CardinalityLib::CAComplexCollectionElementCol*>(CardinalityLib::CClassFactory::CreateClassCollection(CardinalityLib::CClassFactory::ClsName_CAComplexCollectionElementCol, _T("AComplexCollectionElement"), _T(""), 0, -1).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 CMyRootObject::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib21::LtVariant& rValue)
{
    if (bRead)
    {
        switch(iPropertyIndex)
        {
        case 1:
                rValue.SetString(GetASimpleStringMandatoryElement());
            break;
        case 2:
                rValue.SetDate(GetASimpleDateMandatoryElement());
            break;
        case 3:
                rValue.SetXmlObject(GetAComplexMandatoryElement().Ptr());
            break;
        case 4:
            if (IsValidASimpleStringOptionalElement())
                rValue.SetString(GetASimpleStringOptionalElement());
            else
                rValue.SetInvalid();
            break;
        case 5:
            if (IsValidASimpleDateOptionalElement())
                rValue.SetDate(GetASimpleDateOptionalElement());
            else
                rValue.SetInvalid();
            break;
        case 6:
                rValue.SetXmlObject(GetAComplexOptionalElement().Ptr());
            break;
        case 7:
            rValue.SetXmlCollection(GetASimpleStringCollectionElement());
            break;
        case 8:
            rValue.SetXmlCollection(GetASimpleDateCollectionElement());
            break;
        case 9:
            rValue.SetXmlCollection(GetAComplexCollectionElement().Ptr());
            break;
        default:
            throw LtXmlLib21::CLtException(_T("Unknown Property Index"));
        };
    }
    else
    {
        switch(iPropertyIndex)
        {
        case 1:
            SetASimpleStringMandatoryElement(rValue.GetString());
            break;
        case 2:
            SetASimpleDateMandatoryElement(rValue.GetDate());
            break;
        case 3:
            SetAComplexMandatoryElement(dynamic_cast<CardinalityLib::CAComplexMandatoryElement*>(rValue.GetXmlObject().Ptr()));
            break;
        case 4:
            if (rValue.IsValid())
                SetASimpleStringOptionalElement(rValue.GetString());
            else
                SetValidASimpleStringOptionalElement(false);
            break;
        case 5:
            if (rValue.IsValid())
                SetASimpleDateOptionalElement(rValue.GetDate());
            else
                SetValidASimpleDateOptionalElement(false);
            break;
        case 6:
            SetAComplexOptionalElement(dynamic_cast<CardinalityLib::CAComplexOptionalElement*>(rValue.GetXmlObject().Ptr()));
            break;
        case 7:
            throw LtXmlLib21::CLtException(_T("Collections can not be set"));
            break;
        case 8:
            throw LtXmlLib21::CLtException(_T("Collections can not be set"));
            break;
        case 9:
            throw LtXmlLib21::CLtException(_T("Collections can not be set"));
            break;
        default:
            throw LtXmlLib21::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 CMyRootObject::GetASimpleStringMandatoryElement() const
{
    return this->m_ASimpleStringMandatoryElement;
}
void CMyRootObject::SetASimpleStringMandatoryElement(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib21::CWhitespaceUtils::Preserve(value); 
    this->m_ASimpleStringMandatoryElement = 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 LtXmlLib21::CDateTime(LtXmlLib21::CDateTime::dt_date).
 */
LtXmlLib21::CDateTime CMyRootObject::GetASimpleDateMandatoryElement() const
{
    return this->m_ASimpleDateMandatoryElement;
}
void CMyRootObject::SetASimpleDateMandatoryElement(LtXmlLib21::CDateTime value)
{ 
    this->m_ASimpleDateMandatoryElement.SetDateTime(value, this->m_ASimpleDateMandatoryElement.GetType()); 
}

/*
 * 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.
 */
CardinalityLib::CAComplexMandatoryElementPtr CMyRootObject::GetAComplexMandatoryElement() const
{ 
    return this->m_AComplexMandatoryElement;  
}
void CMyRootObject::SetAComplexMandatoryElement(CardinalityLib::CAComplexMandatoryElement* value)
{ 
    Throw_IfPropertyIsNull(value, _T("AComplexMandatoryElement"));
    if (value != NULL)
        SetElementName(value, _T("AComplexMandatoryElement"));
    this->m_AComplexMandatoryElement = 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 CMyRootObject::GetASimpleStringOptionalElement() const
{
    if (m_IsValidASimpleStringOptionalElement == false)
        throw LtXmlLib21::CLtInvalidStateException(_T("The Property GetASimpleStringOptionalElement is not valid. SetASimpleStringOptionalElement must be called first"));
    return this->m_ASimpleStringOptionalElement;
}
void CMyRootObject::SetASimpleStringOptionalElement(std::tstring value)
{ 
    // Apply whitespace rules appropriately
    value = LtXmlLib21::CWhitespaceUtils::Preserve(value); 
    this->m_IsValidASimpleStringOptionalElement = true;

    this->m_ASimpleStringOptionalElement = value; 
}

/*
 * Indicates if GetASimpleStringOptionalElement contains a valid value.
 *
 * true if the value for GetASimpleStringOptionalElement 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 GetASimpleStringOptionalElement
 * will raise an exception.
 */
bool CMyRootObject::IsValidASimpleStringOptionalElement() const
{ 
    return m_IsValidASimpleStringOptionalElement;
}
void CMyRootObject::SetValidASimpleStringOptionalElement(bool value)
{ 
    if (value != m_IsValidASimpleStringOptionalElement)
    {
        this->m_ASimpleStringOptionalElement = _T("");
        m_IsValidASimpleStringOptionalElement = 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.
 */
LtXmlLib21::CDateTime CMyRootObject::GetASimpleDateOptionalElement() const
{
    if (m_IsValidASimpleDateOptionalElement == false)
        throw LtXmlLib21::CLtInvalidStateException(_T("The Property GetASimpleDateOptionalElement is not valid. SetASimpleDateOptionalElement must be called first"));
    return this->m_ASimpleDateOptionalElement;
}
void CMyRootObject::SetASimpleDateOptionalElement(LtXmlLib21::CDateTime value)
{ 
    this->m_IsValidASimpleDateOptionalElement = true;

    this->m_ASimpleDateOptionalElement.SetDateTime(value, m_ASimpleDateOptionalElement.GetType()); 
}

/*
 * Indicates if GetASimpleDateOptionalElement contains a valid value.
 *
 * true if the value for GetASimpleDateOptionalElement is valid, false if not.
 * If this is set to true then the property is considered valid, and assigned its
 * default value (LtXmlLib21::CDateTime(LtXmlLib21::CDateTime::dt_date)).
 * If its set to false then its made invalid, and subsequent calls to GetASimpleDateOptionalElement
 * will raise an exception.
 */
bool CMyRootObject::IsValidASimpleDateOptionalElement() const
{ 
    return m_IsValidASimpleDateOptionalElement;
}
void CMyRootObject::SetValidASimpleDateOptionalElement(bool value)
{ 
    if (value != m_IsValidASimpleDateOptionalElement)
    {
        this->m_ASimpleDateOptionalElement = LtXmlLib21::CDateTime(LtXmlLib21::CDateTime::dt_date);
        m_IsValidASimpleDateOptionalElement = 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.
 */
CardinalityLib::CAComplexOptionalElementPtr CMyRootObject::GetAComplexOptionalElement() const
{ 
    return this->m_AComplexOptionalElement;  
}
void CMyRootObject::SetAComplexOptionalElement(CardinalityLib::CAComplexOptionalElement* value)
{ 
    if (value == NULL)
        this->m_AComplexOptionalElement = NULL;
    else
    {
        SetElementName(value, _T("AComplexOptionalElement"));
        this->m_AComplexOptionalElement = value; 
    }
}

/*
 * A collection of tstrings
 *
 * 
 * This property is represented as an Element in the XML.
 * This collection may contain 0 to Many tstrings.
 */
LtXmlLib21::CstringColPtr CMyRootObject::GetASimpleStringCollectionElement() const
{
    return this->m_ASimpleStringCollectionElement;
}

/*
 * A collection of CDateTimes
 *
 * 
 * This property is represented as an Element in the XML.
 * This collection may contain 0 to Many CDateTimes.
 */
LtXmlLib21::CdateColPtr CMyRootObject::GetASimpleDateCollectionElement() const
{
    return this->m_ASimpleDateCollectionElement;
}

/*
 * A collection of CMyRootObjects
 *
 * 
 * This property is represented as an Element in the XML.
 * This collection may contain 0 to Many objects.
 */
CardinalityLib::CAComplexCollectionElementColPtr CMyRootObject::GetAComplexCollectionElement() const
{
    return this->m_AComplexCollectionElement; 
}

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

    int index = 0;
    newObject->m_ASimpleStringMandatoryElement = m_ASimpleStringMandatoryElement;
    newObject->m_ASimpleDateMandatoryElement = m_ASimpleDateMandatoryElement;
    newObject->m_AComplexMandatoryElement = NULL;
    if (m_AComplexMandatoryElement != NULL)
        newObject->m_AComplexMandatoryElement = dynamic_cast<CardinalityLib::CAComplexMandatoryElement*>(m_AComplexMandatoryElement->Clone().Ptr());
    newObject->m_ASimpleStringOptionalElement = m_ASimpleStringOptionalElement;
    newObject->m_IsValidASimpleStringOptionalElement = m_IsValidASimpleStringOptionalElement;
    newObject->m_ASimpleDateOptionalElement = m_ASimpleDateOptionalElement;
    newObject->m_IsValidASimpleDateOptionalElement = m_IsValidASimpleDateOptionalElement;
    newObject->m_AComplexOptionalElement = NULL;
    if (m_AComplexOptionalElement != NULL)
        newObject->m_AComplexOptionalElement = dynamic_cast<CardinalityLib::CAComplexOptionalElement*>(m_AComplexOptionalElement->Clone().Ptr());
    for (index = 0; index < m_ASimpleStringCollectionElement->GetCount(); index++)
        newObject->m_ASimpleStringCollectionElement->Add(m_ASimpleStringCollectionElement->Item(index));
    for (index = 0; index < m_ASimpleDateCollectionElement->GetCount(); index++)
        newObject->m_ASimpleDateCollectionElement->Add(m_ASimpleDateCollectionElement->Item(index));
    for (index = 0; index < m_AComplexCollectionElement->GetCount(); index++)
        newObject->m_AComplexCollectionElement->Add(dynamic_cast<CardinalityLib::CAComplexCollectionElement*>(m_AComplexCollectionElement->Item(index)->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 CMyRootObject::GetTargetNamespace() const
{
    return _T("");
}   

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

LtXmlLib21::CXmlObjectBase* CMyRootObject::GetBase()
{
    return this;
}   

void CMyRootObject::CleanMetaData()
{
    LtXmlLib21::CXmlGeneratedClass::CleanMetaData(ms_pParentElementInfo, ms_ppElementInfo, ms_ppAttributeInfo);
}

LtXmlLib21Data::CParentElementInfo* CMyRootObject::GetClassInfo() const
{
    if (ms_pParentElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_pParentElementInfo == NULL)
        {
            ms_pParentElementInfo = new LtXmlLib21Data::CParentElementInfo(
                                                                            LtXmlLib21Data::XmlElementGroupType_SEQUENCE,
                                                                            LtXmlLib21Data::XmlElementType_ELEMENT, 
                                                                            _T("MyRootObject"),                  
                                                                            _T(""), 
                                                                            true,
                                                                            false,
                                                                            -1,
                                                                            LtXmlLib21::ItemType_none,
                                                                            LtXmlLib21::CWhitespaceUtils::WhitespaceRule_None,
                                                                            NULL,
                                                                            false);
        }
        m_csInit.Leave();
    }
    
    return ms_pParentElementInfo;
}

LtXmlLib21Data::CElementInfo** CMyRootObject::GetClassElementInfo() const
{
    if (ms_ppElementInfo == NULL)
    {
        m_csInit.Enter();
        if (ms_ppElementInfo == NULL)
        {
            ms_ppElementInfo = new LtXmlLib21Data::CElementInfo*[10];
        
            ms_ppElementInfo[0] = new LtXmlLib21Data::CElementInfoSeqPrimMnd(_T("ASimpleStringMandatoryElement"), _T(""), 1, false, LtXmlLib21::ItemType_string, NULL, LtXmlLib21::CWhitespaceUtils::WhitespaceRule_Preserve, LtXmlLib21::CPrimitiveRestrictions(_T(""), -1, -1, _T(""), _T(""), _T(""), _T(""), -1, -1, -1), NULL);
            ms_ppElementInfo[1] = new LtXmlLib21Data::CElementInfoSeqPrimMnd(_T("ASimpleDateMandatoryElement"), _T(""), 2, false, LtXmlLib21::ItemType_date, NULL, LtXmlLib21::CWhitespaceUtils::WhitespaceRule_Collapse, LtXmlLib21::CPrimitiveRestrictions(_T(""), -1, -1, _T(""), _T(""), _T(""), _T(""), -1, -1, -1), NULL);
            ms_ppElementInfo[2] = new LtXmlLib21Data::CElementInfoSeqClsMnd(_T("AComplexMandatoryElement"), _T(""), 3, LtXmlLib21Data::XmlElementType_ELEMENT, (LtXmlLib21Data::pfnCreateClassDef)&CardinalityLib::CClassFactory::CreateClass, CardinalityLib::CClassFactory::ClsName_CAComplexMandatoryElement, true);
            ms_ppElementInfo[3] = new LtXmlLib21Data::CElementInfoSeqPrimOpt(_T("ASimpleStringOptionalElement"), _T(""), 4, false, LtXmlLib21::ItemType_string, NULL, LtXmlLib21::CWhitespaceUtils::WhitespaceRule_Preserve, LtXmlLib21::CPrimitiveRestrictions(_T(""), -1, -1, _T(""), _T(""), _T(""), _T(""), -1, -1, -1), NULL);
            ms_ppElementInfo[4] = new LtXmlLib21Data::CElementInfoSeqPrimOpt(_T("ASimpleDateOptionalElement"), _T(""), 5, false, LtXmlLib21::ItemType_date, NULL, LtXmlLib21::CWhitespaceUtils::WhitespaceRule_Collapse, LtXmlLib21::CPrimitiveRestrictions(_T(""), -1, -1, _T(""), _T(""), _T(""), _T(""), -1, -1, -1), NULL);
            ms_ppElementInfo[5] = new LtXmlLib21Data::CElementInfoSeqClsOpt(_T("AComplexOptionalElement"), _T(""), 6, LtXmlLib21Data::XmlElementType_ELEMENT, (LtXmlLib21Data::pfnCreateClassDef)&CardinalityLib::CClassFactory::CreateClass, CardinalityLib::CClassFactory::ClsName_CAComplexOptionalElement);
            ms_ppElementInfo[6] = new LtXmlLib21Data::CElementInfoSeqPrimCol(_T("ASimpleStringCollectionElement"), _T(""), 7);
            ms_ppElementInfo[7] = new LtXmlLib21Data::CElementInfoSeqPrimCol(_T("ASimpleDateCollectionElement"), _T(""), 8);
            ms_ppElementInfo[8] = new LtXmlLib21Data::CElementInfoSeqClsCol(_T("AComplexCollectionElement"), _T(""), 9, LtXmlLib21Data::XmlElementType_ELEMENT);
            ms_ppElementInfo[9] = NULL;
        }
        m_csInit.Leave();
    }
    return ms_ppElementInfo;
}

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