In This Topic
#include "StdAfx.h"
#pragma warning( disable : 4786 )
#pragma warning( disable : 4251 )
#include "../SimpleHierarchyLib.h"
#include "../SimpleHierarchyLib/ItemTypeCol.h"
#include "../SimpleHierarchyLib/ItemType.h"
namespace SimpleHierarchyLib
{
CItemTypeCol::CItemTypeCol(LPCTSTR lpctElementName, LPCTSTR lpctNamespaceUri, int minOccurs, int maxOccurs)
: CXmlCollectionCommonBase(lpctElementName, lpctNamespaceUri, minOccurs, maxOccurs), CInstanceMonitor(_T("CItemTypeCol"))
{
}
void CItemTypeCol::Add(SimpleHierarchyLib::CItemType* pCls)
{
SetElementName(pCls, m_elementName.c_str());
AppendItem(pCls);
}
void CItemTypeCol::AddAt(int index, SimpleHierarchyLib::CItemType* pCls)
{
SetElementName(pCls, m_elementName.c_str());
AddItemAt(index, pCls);
}
SimpleHierarchyLib::CItemTypePtr CItemTypeCol::Add()
{
CSmartPtr<LtXmlLib20::CXmlObjectBase> spCls = SimpleHierarchyLib::CClassFactory::CreateClass(SimpleHierarchyLib::CClassFactory::ClsName_CItemType, m_elementName.c_str());
AppendItem(spCls);
return dynamic_cast<SimpleHierarchyLib::CItemType*>(spCls.Ptr());
}
CSmartPtr<SimpleHierarchyLib::CItemType> CItemTypeCol::Item(int index) const
{
return dynamic_cast<SimpleHierarchyLib::CItemType*>(GetNodeAtIndex(index)->spObj.Ptr());
}
void CItemTypeCol::Remove(SimpleHierarchyLib::CItemType* pCls)
{
RemoveNode(GetNodeForItem(pCls));
}
void CItemTypeCol::ToXml_Int(LtXmlLib20::CXmlWriter* xmlOut, bool bRegisterNamespaces, LPCTSTR lpctNamespaceUri, const LtXmlLib20::CSerializationContext& context, bool isOptionalChoice) const
{
ValidateCount(context);
LtXmlLib20::CNode* pNode = m_pHead;
while(pNode != NULL)
{
LtXmlLib20::CXmlObjectBase::ToXml_Int((pNode->spObj)->GetBase(), xmlOut, false, lpctNamespaceUri, context, isOptionalChoice);
pNode = pNode->pNext;
}
}
LtXmlLib20::CXmlElement* CItemTypeCol::FromXml_Int(LtXmlLib20::CXmlElement* pXmlParent, LtXmlLib20::CXmlElement* pXmlChild, const LtXmlLib20::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<LtXmlLib20::CXmlObjectBase> spObj = SimpleHierarchyLib::CClassFactory::CreateClass(SimpleHierarchyLib::CClassFactory::ClsName_CItemType, m_elementName.c_str());
LtXmlLib20::CXmlObjectBase::FromXml_Int(spObj->GetBase(), pXmlChild, pXmlChild->GetFirstElement(), context);
AppendItem(spObj.Ptr());
pXmlChild = pXmlChild->GetNextSiblingElement();
}
return pXmlChild;
}
CItemTypeCol::iterator CItemTypeCol::begin()
{
return m_pHead;
}
CItemTypeCol::iterator CItemTypeCol::end()
{
return NULL;
}
};