AComplexCollectionElementCol.cpp
In This Topic
#include "StdAfx.h"
#pragma warning( disable : 4786 )
#pragma warning( disable : 4251 )
#include "../CardinalityLib.h"
#include "../CardinalityLib/AComplexCollectionElementCol.h"
#include "../CardinalityLib/AComplexCollectionElement.h"
namespace CardinalityLib
{
CAComplexCollectionElementCol::CAComplexCollectionElementCol(LPCTSTR lpctElementName, LPCTSTR lpctNamespaceUri, int minOccurs, int maxOccurs)
: CXmlCollectionCommonBase(lpctElementName, lpctNamespaceUri, minOccurs, maxOccurs), CInstanceMonitor(_T("CAComplexCollectionElementCol"))
{
}
void CAComplexCollectionElementCol::Add(CardinalityLib::CAComplexCollectionElement* pCls)
{
SetElementName(pCls, m_elementName.c_str());
AppendItem(pCls);
}
void CAComplexCollectionElementCol::AddAt(int index, CardinalityLib::CAComplexCollectionElement* pCls)
{
SetElementName(pCls, m_elementName.c_str());
AddItemAt(index, pCls);
}
CardinalityLib::CAComplexCollectionElementPtr CAComplexCollectionElementCol::Add()
{
CSmartPtr<LtXmlLib20::CXmlObjectBase> spCls = CardinalityLib::CClassFactory::CreateClass(CardinalityLib::CClassFactory::ClsName_CAComplexCollectionElement, m_elementName.c_str());
AppendItem(spCls);
return dynamic_cast<CardinalityLib::CAComplexCollectionElement*>(spCls.Ptr());
}
CSmartPtr<CardinalityLib::CAComplexCollectionElement> CAComplexCollectionElementCol::Item(int index) const
{
return dynamic_cast<CardinalityLib::CAComplexCollectionElement*>(GetNodeAtIndex(index)->spObj.Ptr());
}
void CAComplexCollectionElementCol::Remove(CardinalityLib::CAComplexCollectionElement* pCls)
{
RemoveNode(GetNodeForItem(pCls));
}
void CAComplexCollectionElementCol::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* CAComplexCollectionElementCol::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 = CardinalityLib::CClassFactory::CreateClass(CardinalityLib::CClassFactory::ClsName_CAComplexCollectionElement, m_elementName.c_str());
LtXmlLib20::CXmlObjectBase::FromXml_Int(spObj->GetBase(), pXmlChild, pXmlChild->GetFirstElement(), context);
AppendItem(spObj.Ptr());
pXmlChild = pXmlChild->GetNextSiblingElement();
}
return pXmlChild;
}
CAComplexCollectionElementCol::iterator CAComplexCollectionElementCol::begin()
{
return m_pHead;
}
CAComplexCollectionElementCol::iterator CAComplexCollectionElementCol::end()
{
return NULL;
}
};