#include "c4d_memory.h"
#include "c4d_basecontainer.h"
#include "c4d_file.h"
#include "c4d_baselist.h"

#ifdef	__C4D_NO_NEW_DELETE__
void* BaseContainer::operator new(size_t,const std::nothrow_t&,int line,const CHAR *file) throw()
{
	return C4DOS.Bc->Alloc(NOTOK);
}

void BaseContainer::operator delete(void *del,int line, const CHAR *file)
{
	C4DOS.Bc->Free((BaseContainer*)del);
}

void BaseContainer::operator delete(void* del)
{
	C4DOS.Bc->Free((BaseContainer*)del);
}
#endif

BaseContainer::BaseContainer(void)
{
	BcCall(SDKInit,NOTOK,NULL);
}

BaseContainer::BaseContainer(LONG id)
{
	BcCall(SDKInit,id,NULL);
}

BaseContainer::BaseContainer(const BaseContainer &src)
{
	BcCall(SDKInit,NOTOK,&src);
} 

BaseContainer::~BaseContainer(void)
{
	FlushAll();
}

const BaseContainer& BaseContainer::operator = (const BaseContainer& n)
{
	n.CopyTo(this,COPYFLAGS_0,NULL); 
	return *this;
}

Bool BaseContainer::operator == (const BaseContainer &c) const
{
	return C4DOS.Bc->Compare(*this,c);
}

Bool BaseContainer::operator != (const BaseContainer &c) const
{
	return !C4DOS.Bc->Compare(*this,c);
}

BaseLink *BaseContainer::GetBaseLink (LONG id) const
{
	const GeData &dat = GetData(id);
	return dat.GetBaseLink();
}

BaseObject *BaseContainer::GetObjectLink(LONG id, const BaseDocument *doc) const
{
	return (BaseObject*)GetLink(id,doc,Obase);
}

BaseMaterial *BaseContainer::GetMaterialLink(LONG id, const BaseDocument *doc) const
{
	return (BaseMaterial*)GetLink(id,doc,Mbase);
}

const CustomDataType*	BaseContainer::GetCustomDataType(LONG id,LONG datatype) const
{
	const GeData &dat = GetData(id);
	return dat.GetCustomDataType(datatype);
}

void BaseContainer::MergeContainer(const BaseContainer &src)
{
	BcCall(Merge,src);	
}

LONG BaseContainer::GetType(LONG id) const
{
	const GeData *d = BcCall(GetDataPointer,id);
	if (!d) return DA_NIL;
	return d->GetType();
}

