Exemplo n.º 1
0
ICCItem *CCodeChain::CreateFilledVector(double dScalar, TArray<int> vShape)

//	CreateFilledVector
//
//	Creates a vector filled with the given scalar

{
	int i;
	int iSize = 0;
	CCVector *pVector;
	ICCItem *pError;
	ICCItem *pItem;

	for (i = 0; i < vShape.GetCount(); i++)
	{
		if (i == 0)
			iSize = vShape[0];
		else
			iSize = iSize*vShape[i];
	};

	pItem = m_VectorPool.CreateItem(this);
	if (pItem->IsError())
		return pItem;
	pItem->Reset();
	pVector = dynamic_cast<CCVector *>(pItem);

	pVector->SetContext(this);
	pVector->SetShape(this, vShape);

	pError = pVector->SetDataArraySize(this, iSize);
	if (pError->IsError())
	{
		delete pVector;
		return pError;
	}

	TArray<double> vContentArray = pVector->GetDataArray();
	for (i = 0; i < iSize; i++)
	{
		vContentArray[i] = dScalar;
	};
	pVector->SetArrayData(this, vContentArray);

	
	pError->Discard(this);
	//	Done
	return pVector->Reference();
}
Exemplo n.º 2
0
ICCItem *CCodeChain::CreateSymbolTable (void)

//	CreateSymbolTable
//
//	Creates an item

	{
	ICCItem *pItem;

	pItem = m_SymbolTablePool.CreateItem(this);
	if (pItem->IsError())
		return pItem;

	pItem->Reset();
	return pItem->Reference();
	}
Exemplo n.º 3
0
ICCItem *CCodeChain::CreateLinkedList (void)

//	CreateLinkedList
//
//	Creates an item

	{
	ICCItem *pItem;

	pItem = m_ListPool.CreateItem(this);
	if (pItem->IsError())
		return pItem;

	pItem->Reset();
	return pItem->Reference();
	}
Exemplo n.º 4
0
ICCItem *CCodeChain::CreateVectorGivenContent(TArray<int> vShape, TArray<double> vContentArray)

//	CreateVectorGivenContent (new)
//
//	Creates a vector with given shape and content

{
	int i;
	int iSize = 0;
	CCVector *pVector;
	ICCItem *pError;
	ICCItem *pItem;

	for (i = 0; i < vShape.GetCount(); i++)
	{
		iSize = iSize * vShape[i];
	};

	pItem = m_VectorPool.CreateItem(this);
	if (pItem->IsError())
		return pItem;
	pItem->Reset();
	pVector = dynamic_cast<CCVector *>(pItem);
	pVector->SetContext(this);

	pError = pVector->SetDataArraySize(this, iSize);
	if (pError->IsError())
	{
		delete pVector;
		return pError;
	}

	pVector->SetShape(this, vShape);

	pVector->SetArrayData(this, vContentArray);

	//	Done
	pError->Discard(this);
	return pVector->Reference();
}
Exemplo n.º 5
0
ICCItem *CCodeChain::CreateVectorGivenContent(TArray<int> vShape, CCLinkedList *pContentList)

//	CreateVectorGivenContent (new)
//
//	Creates a vector with given shape and content

{
	int i;
	CCVector *pVector;
	ICCItem *pItem;

	pItem = m_VectorPool.CreateItem(this);
	if (pItem->IsError())
		return pItem;
	pItem->Reset();

	pVector = dynamic_cast<CCVector *>(pItem);
	pVector->SetContext(this);

	pVector->SetShape(this, vShape);

	pItem = pContentList->GetFlattened(this, NULL);
	if (pItem->IsError())
	{ 
		pVector->Discard(this);
		return pItem;
	};
	CCLinkedList *pFlattenedContentList = dynamic_cast<CCLinkedList *>(pItem);

	TArray<double> vDataArray;
	for (i = 0; i < pFlattenedContentList->GetCount(); i++)
	{
		vDataArray.Insert(pFlattenedContentList->GetElement(i)->GetDoubleValue());
	};
	pVector->SetArrayData(this, vDataArray);

	//	Done
	pFlattenedContentList->Discard(this);
	return pVector->Reference();
}
Exemplo n.º 6
0
ICCItem *CCodeChain::UnstreamItem (IReadStream *pStream)

//	UnstreamItem
//
//	Load the item from an open stream

	{
	ALERROR error;
	DWORD dwClass;
	ICCItem *pItem;
	ICCItem *pError;

	//	Read the object class

	if (error = pStream->Read((char *)&dwClass, sizeof(dwClass), NULL))
		return CreateSystemError(error);

	//	Instantiation an object of the right class

	if (dwClass == OBJID_CCINTEGER)
		pItem = m_IntegerPool.CreateItem(this);
	else if (dwClass == OBJID_CCDOUBLE)
		pItem = m_DoublePool.CreateItem(this);
	else if (dwClass == OBJID_CCSTRING)
		pItem = m_StringPool.CreateItem(this);
	else if (dwClass == OBJID_CCLINKEDLIST)
		pItem = m_ListPool.CreateItem(this);
	else if (dwClass == OBJID_CCPRIMITIVE)
		pItem = m_PrimitivePool.CreateItem(this);
	else if (dwClass == OBJID_CCNIL)
		pItem = m_pNil;
	else if (dwClass == OBJID_CCTRUE)
		pItem = m_pTrue;
	else if (dwClass == OBJID_CCSYMBOLTABLE)
		pItem = m_SymbolTablePool.CreateItem(this);
	else if (dwClass == OBJID_CCLAMBDA)
		pItem = m_LambdaPool.CreateItem(this);
	else if (dwClass == OBJID_CCATOMTABLE)
		pItem = m_AtomTablePool.CreateItem(this);
	else if (dwClass == OBJID_CCVECTOROLD)
		{
		pItem = new CCVectorOld(this);
		if (pItem == NULL)
			pItem = CreateMemoryError();
		}
	else if (dwClass == OBJID_CCVECTOR)
		pItem = m_VectorPool.CreateItem(this);
	else
		return CreateError(LITERAL("Unknown item type"), NULL);

	//	Check for error

	if (pItem->IsError())
		return pItem;

	//	We need to increment the reference here because the native
	//	create does not.

	pItem->Reset();
	pItem->Reference();

	//	Let the item load the rest

	pError = pItem->Unstream(this, pStream);
	if (pError->IsError())
		{
		pItem->Discard(this);
		return pError;
		}

	pError->Discard(this);

	//	Done

	return pItem;
	}