In This Topic
#include "StdAfx.h"
#pragma warning (push)
#pragma warning (disable:4251)
#pragma warning (disable:4786)
#include "../SimpleHierarchyLib.h"
#include "../SimpleHierarchyLib/Payment.h"
namespace SimpleHierarchyLib
{
LtXmlLib20Data::CParentElementInfo* CPayment::ms_pParentElementInfo = NULL;
LtXmlLib20Data::CAttributeInfo** CPayment::ms_ppAttributeInfo = NULL;
LtXmlLib20Data::CElementInfo** CPayment::ms_ppElementInfo = NULL;
CPaymentPtr CPayment::CreateInstance(LPCTSTR lpctElementName)
{
return new SimpleHierarchyLib::CPayment(lpctElementName);
}
CPayment::CPayment(LPCTSTR lpctElementName)
: CInstanceMonitor(_T("CPayment"))
{
m_elementName = lpctElementName;
Init();
}
CPayment::~CPayment()
{
Cleanup();
}
void CPayment::Cleanup()
{
// unregister for any events we have asked for
// cos there'll be no one left to hear soon
if (this->m_Vouchers != NULL)
this->m_Vouchers->RemoveEventListener(this);
this->m_Vouchers = NULL;
}
void CPayment::OnEvent(LtXmlLib20::CXmlObjectBase* pMsgSource, LtXmlLib20::IEventSink::MsgType eMsgType, void* pData)
{
if (eMsgType == LtXmlLib20::IEventSink::MT_CollectionChangeEvent)
{
if (this->m_Vouchers != NULL && this->m_Vouchers->GetBase() == pMsgSource)
{
ClearChoice(this->m_Vouchers->GetCount()==0?_T(""):_T("Vouchers"));
}
}
}
void CPayment::Init()
{
Cleanup();
this->m_VISA = NULL;
this->m_Vouchers = dynamic_cast<SimpleHierarchyLib::CVouchersCol*>(SimpleHierarchyLib::CClassFactory::CreateClassCollection(SimpleHierarchyLib::CClassFactory::ClsName_CVouchersCol, _T("Vouchers"), _T(""), 1, -1).Ptr());
this->m_Vouchers->AddEventListener(this);
this->m_Cash = NULL;
m_validElement = _T("");
}
void CPayment::ClearChoice(LPCTSTR lpctSelectedElement)
{
this->m_VISA = NULL;
if (this->m_Vouchers != NULL)
{
if (_tcscmp(_T("Vouchers"), lpctSelectedElement) != 0)
this->m_Vouchers->Clear();
}
this->m_Cash = NULL;
m_validElement = lpctSelectedElement;
}
void CPayment::AccessProperty(int iPropertyIndex, bool bRead, LtXmlLib20::LtVariant& rValue)
{
if (bRead)
{
switch(iPropertyIndex)
{
case 1:
rValue.SetXmlObject(GetVISA().Ptr());
break;
case 2:
rValue.SetXmlCollection(GetVouchers().Ptr());
break;
case 3:
rValue.SetXmlObject(GetCash().Ptr());
break;
default:
throw LtXmlLib20::CLtException(_T("Unknown Property Index"));
};
}
else
{
switch(iPropertyIndex)
{
case 1:
SetVISA(dynamic_cast<SimpleHierarchyLib::CVISA*>(rValue.GetXmlObject().Ptr()));
break;
case 2:
throw LtXmlLib20::CLtException(_T("Collections can not be set"));
break;
case 3:
SetCash(dynamic_cast<LtXmlLib20::CElement*>(rValue.GetXmlObject().Ptr()));
break;
default:
throw LtXmlLib20::CLtException(_T("Unknown Property Index"));
}
}
}
SimpleHierarchyLib::CVISAPtr CPayment::GetVISA() const
{
return this->m_VISA;
}
void CPayment::SetVISA(SimpleHierarchyLib::CVISA* value)
{
// Ensure only on element is populated at a time
ClearChoice(value == NULL?_T(""):_T("VISA"));
if (value == NULL)
this->m_VISA = NULL;
else
{
SetElementName(value, _T("VISA"));
this->m_VISA = value;
}
}
SimpleHierarchyLib::CVouchersColPtr CPayment::GetVouchers() const
{
return this->m_Vouchers;
}
LtXmlLib20::CElementPtr CPayment::GetCash() const
{
return this->m_Cash;
}
void CPayment::SetCash(LtXmlLib20::CElement* value)
{
if (value != NULL)
TestNamespace(value->GetNamespace().c_str(), _T("##any"), _T(""));
ClearChoice(value==NULL?_T(""):_T("Cash"));
this->m_Cash = value;
}
std::tstring CPayment::GetChoiceSelectedElement() const
{
return m_validElement;
}
SimpleHierarchyLib::CPaymentPtr CPayment::Clone() const
{
SimpleHierarchyLib::CPaymentPtr newObject = CreateInstance(m_elementName.c_str());
int index = 0;
newObject->m_VISA = NULL;
if (m_VISA != NULL)
newObject->m_VISA = dynamic_cast<SimpleHierarchyLib::CVISA*>(m_VISA->Clone().Ptr());
for (index = 0; index < m_Vouchers->GetCount(); index++)
newObject->m_Vouchers->Add(dynamic_cast<SimpleHierarchyLib::CVouchers*>(m_Vouchers->Item(index)->Clone().Ptr()));
newObject->m_Cash = NULL;
if (m_Cash != NULL)
newObject->m_Cash = dynamic_cast<LtXmlLib20::CElement*>(m_Cash->Clone().Ptr());
newObject->m_validElement = m_validElement;
return newObject.Ptr();
}
std::tstring CPayment::GetTargetNamespace() const
{
return _T("");
}
std::tstring CPayment::GetNamespace() const
{
return _T("");
}
LtXmlLib20::CXmlObjectBase* CPayment::GetBase()
{
return this;
}
void CPayment::CleanMetaData()
{
LtXmlLib20::CXmlGeneratedClass::CleanMetaData(ms_pParentElementInfo, ms_ppElementInfo, ms_ppAttributeInfo);
}
LtXmlLib20Data::CParentElementInfo* CPayment::GetClassInfo() const
{
if (ms_pParentElementInfo == NULL)
{
m_csInit.Enter();
if (ms_pParentElementInfo == NULL)
{
ms_pParentElementInfo = new LtXmlLib20Data::CParentElementInfo(
LtXmlLib20Data::XmlElementGroupType_CHOICE,
LtXmlLib20Data::XmlElementType_ELEMENT,
_T("Payment"),
_T(""),
true,
false,
-1,
LtXmlLib20::ItemType_none,
LtXmlLib20::CWhitespaceUtils::WhitespaceRule_None,
NULL,
false);
}
m_csInit.Leave();
}
return ms_pParentElementInfo;
}
LtXmlLib20Data::CElementInfo** CPayment::GetClassElementInfo() const
{
if (ms_ppElementInfo == NULL)
{
m_csInit.Enter();
if (ms_ppElementInfo == NULL)
{
ms_ppElementInfo = new LtXmlLib20Data::CElementInfo*[4];
ms_ppElementInfo[0] = new LtXmlLib20Data::CElementInfoChoiceClsOpt(_T("VISA"), _T(""), 1, LtXmlLib20Data::XmlElementType_ELEMENT, (LtXmlLib20Data::pfnCreateClassDef)SimpleHierarchyLib::CClassFactory::CreateClass, SimpleHierarchyLib::CClassFactory::ClsName_CVISA);
ms_ppElementInfo[1] = new LtXmlLib20Data::CElementInfoChoiceClsCol(_T("Vouchers"), _T(""), 2, LtXmlLib20Data::XmlElementType_ELEMENT);
ms_ppElementInfo[2] = new LtXmlLib20Data::CElementInfoChoiceUntpdOpt(_T("Cash"), _T(""), 3, _T("##any"), _T(""));
ms_ppElementInfo[3] = NULL;
}
m_csInit.Leave();
}
return ms_ppElementInfo;
}
LtXmlLib20Data::CAttributeInfo** CPayment::GetClassAttributeInfo() const
{
if (ms_ppAttributeInfo == NULL)
{
m_csInit.Enter();
if (ms_ppAttributeInfo == NULL)
{
ms_ppAttributeInfo = new LtXmlLib20Data::CAttributeInfo*[1];
ms_ppAttributeInfo[0] = NULL;
}
m_csInit.Leave();
}
return ms_ppAttributeInfo;
}
};