In This Topic
#include "StdAfx.h"
#pragma warning( disable : 4786 )
#pragma warning( disable : 4251 )
#include "../SimpleHierarchyLib.h"
#include "../SimpleHierarchyLib/VouchersCol.h"
#include "../SimpleHierarchyLib/Vouchers.h"
namespace SimpleHierarchyLib
{
CVouchersCol::CVouchersCol(LPCTSTR lpctElementName, LPCTSTR lpctNamespaceUri, int minOccurs, int maxOccurs)
: CXmlCollectionCommonBase(lpctElementName, lpctNamespaceUri, minOccurs, maxOccurs), CInstanceMonitor(_T("CVouchersCol"))
{
}
void CVouchersCol::Add(SimpleHierarchyLib::CVouchers* pCls)
{
SetElementName(pCls, m_elementName.c_str());
AppendItem(pCls);
}
void CVouchersCol::AddAt(int index, SimpleHierarchyLib::CVouchers* pCls)
{
SetElementName(pCls, m_elementName.c_str());
AddItemAt(index, pCls);
}
SimpleHierarchyLib::CVouchersPtr CVouchersCol::Add()
{
CSmartPtr<LtXmlLib21::CXmlObjectBase> spCls = SimpleHierarchyLib::CClassFactory::CreateClass(SimpleHierarchyLib::CClassFactory::ClsName_CVouchers, m_elementName.c_str());
AppendItem(spCls);
return dynamic_cast<SimpleHierarchyLib::CVouchers*>(spCls.Ptr());
}
CSmartPtr<SimpleHierarchyLib::CVouchers> CVouchersCol::Item(int index) const
{
return dynamic_cast<SimpleHierarchyLib::CVouchers*>(GetNodeAtIndex(index)->spObj.Ptr());
}
void CVouchersCol::Remove(SimpleHierarchyLib::CVouchers* pCls)
{
RemoveNode(GetNodeForItem(pCls));
}
void CVouchersCol::ToXml_Int(LtXmlLib21::CXmlWriter* xmlOut, bool bRegisterNamespaces, LPCTSTR lpctNamespaceUri, const LtXmlLib21::CSerializationContext& context, bool isOptionalChoice) const
{
ValidateCount(context);
LtXmlLib21::CNode* pNode = m_pHead;
while(pNode != NULL)
{
LtXmlLib21::CXmlObjectBase::ToXml_Int((pNode->spObj)->GetBase(), xmlOut, false, lpctNamespaceUri, context, isOptionalChoice);
pNode = pNode->pNext;
}
}
LtXmlLib21::CXmlElement* CVouchersCol::FromXml_Int(LtXmlLib21::CXmlElement* pXmlParent, LtXmlLib21::CXmlElement* pXmlChild, const LtXmlLib21::CSerializationContext& context, bool isOptionalChoice)
{
// go through the nodes until we run out of ones that match
while (pXmlChild != NULL)
{
if (!DoesElementNameMatch(context, pXmlChild, m_elementName.c_str(), GetNamespace().c_str()))
break;
CSmartPtr<LtXmlLib21::CXmlObjectBase> spObj = SimpleHierarchyLib::CClassFactory::CreateClass(SimpleHierarchyLib::CClassFactory::ClsName_CVouchers, m_elementName.c_str());
LtXmlLib21::CXmlObjectBase::FromXml_Int(spObj->GetBase(), pXmlChild, pXmlChild->GetFirstElement(), context);
AppendItem(spObj.Ptr());
pXmlChild = pXmlChild->GetNextSiblingElement();
}
return pXmlChild;
}
CVouchersCol::iterator CVouchersCol::begin()
{
return m_pHead;
}
CVouchersCol::iterator CVouchersCol::end()
{
return NULL;
}
};