Example #1
0
ret_ CXMLLoaderActions::LoadDualityCalculate(CProgram &Program,
											 const DOMElement *pElement,
											 const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);
#endif

	//
	auto_xerces_str wsOperator	("operator");
	auto_xerces_str	sOperator	(pElement->getAttribute(wsOperator));

	EDualityCalculate Calculate;

	if (SUCCESS != GetDualityOperator(sOperator, Calculate))
		return XML_LOADER_ERROR;

	//
	DOMElement *pSub = (DOMElement *)pElement->getFirstChild();

	if (!pSub)
		return XML_LOADER_ERROR;

	CAutoPtr<CVariable> OV[3];
	size_ n = 0;

	while (pSub)
	{
		ret_ Ret = LoadVariable(Program.Data(), pSub, OV[n].Ptr(), pPDU);

		if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
			return Ret;

		if (SUCCESS == Ret)
			if (3 <= ++n)
				break;

		pSub = (DOMElement *)pSub->getNextSibling();
	}

	COptDualityCalculate *pODC = new COptDualityCalculate(
		OV[0].Ptr(),
		Calculate,
		OV[1].Ptr(),
		OV[2].Ptr());

	if (false_v == Program.AddOperator(pODC))
		return XML_LOADER_ERROR;

	return SUCCESS;
}
Example #2
0
ProblemView* ProblemView::getViewWithOptions() {
	float fontSize = 40.0f;
    ccColor3B fontFillColor = ccc3(0, 0, 0);
    
	static char* unknownCharacter = "☐";
	CCString* sOperand0 = (model->blank == 0) ?
								CCString::create(unknownCharacter) :
								CCString::createWithFormat("%d", this->model->operand[0]) ;
    CCString* sOperand1 = (model->blank == 1) ?
								CCString::create(unknownCharacter) :
								CCString::createWithFormat("%d", this->model->operand[1]);
    CCString* sProduct = (model->blank == 2) ?
								CCString::create(unknownCharacter) :
								CCString::createWithFormat("%d", this->model->product);
    
	this->operand[0] = CCLabelTTF::create(sOperand0->getCString(), "Helvetica", fontSize);
    this->operand[0]->setContentSize(CCSizeMake(40, 40));
    this->operand[0]->setPosition(ccp(50,40));
    this->operand[0]->setFontFillColor(fontFillColor);
    this->addChild(this->operand[0]);
    
    this->operand[1] = CCLabelTTF::create(sOperand1->getCString(), "Helvetica", fontSize);
    this->operand[1]->setContentSize(CCSizeMake(40, 40));
    this->operand[1]->setPosition(ccp(150,40));
    this->operand[1]->setFontFillColor(fontFillColor);
    this->addChild(this->operand[1]);
    
    const char* sOp = sOperator(this->model->op);
    this->op = CCLabelTTF::create(sOp, "Helvetica", fontSize);
    this->op->setContentSize(CCSizeMake(40, 40));
    this->op->setPosition(ccp(100,40));
    this->op->setFontFillColor(fontFillColor);
    this->addChild(this->op);
    
    this->equal = CCLabelTTF::create("=", "Helvetica", fontSize);
    this->equal->setContentSize(CCSizeMake(40, 40));
    this->equal->setPosition(ccp(200,40));
    this->equal->setFontFillColor(fontFillColor);
    this->addChild(this->equal);
    
    this->product = CCLabelTTF::create(sProduct->getCString(), "Helvetica", fontSize);
    this->product->setContentSize(CCSizeMake(40, 40));
    this->product->setPosition(ccp(250,40));
    this->product->setFontFillColor(fontFillColor);
    this->addChild(this->product);
	
	return this;
}
Example #3
0
ret_ CXMLLoaderActions::LoadExpression(const CData &Data,
									   const DOMElement *pElement,
									   CExpression *&pExpression,
									   const CPDUInfo *pPDU)
{
#ifdef _DEBUG_
	if (!pElement)
		return (PARAMETER_NULL | PARAMETER_2);

	if (pExpression)
		return (PARAMETER_NOT_NULL | PARAMETER_3);
#endif

	auto_xerces_str wsExpressionUnitary	("expression_unitary");
	auto_xerces_str wsExpressionDuality	("expression_duality");
	auto_xerces_str wsConditionUnitary	("condition_unitary");
	auto_xerces_str wsConditionDuality	("condition_duality");
	auto_xerces_str wsCalculate			("calculate");
	auto_xerces_str wsRelation			("relation");

	if (0 == XMLString::compareString(pElement->getNodeName(),
									  wsExpressionUnitary))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CExpression *pExp = null_v;

		while (pChild)
		{
			if (0 == XMLString::compareString(pChild->getNodeName(),
											  wsExpressionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsExpressionDuality)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionDuality))
			{
				if (SUCCESS != LoadExpression(Data, pChild, pExp, pPDU))
					return XML_LOADER_ERROR;

				break;
			}

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		if (!pExp)
			return XML_LOADER_ERROR;

		pExpression = (CExpression *)new CExpNot(pExp);
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsExpressionDuality))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		size_ n = 0;
		CExpression *pExp[2] = {null_v, null_v};

		while (pChild)
		{
			if (2 <= n)
				break;

			if (0 == XMLString::compareString(pChild->getNodeName(),
											  wsExpressionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsExpressionDuality)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionUnitary)
				|| 0 == XMLString::compareString(pChild->getNodeName(),
												 wsConditionDuality))
			{
				if (SUCCESS != LoadExpression(Data, pChild, pExp[n++], pPDU))
					return XML_LOADER_ERROR;
			}

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		if (2 != n)
			return XML_LOADER_ERROR;

		auto_xerces_str sRelation(pElement->getAttribute(wsRelation));

		if (0 == strcmp((const ch_1 *)sRelation, "and"))
			pExpression = (CExpression *)new CExpAnd(pExp[0], pExp[1]);
		else if (0 == strcmp((const ch_1 *)sRelation, "or"))
			pExpression = (CExpression *)new CExpOr(pExp[0], pExp[1]);
		else
			return XML_LOADER_ERROR;
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsConditionUnitary))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CAutoPtr<CVariable> v;

		while (pChild)
		{
			ret_ Ret = LoadVariable(Data, pChild, v.Ptr(), pPDU);
		
			if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
				return Ret;

			if (SUCCESS == Ret)
				break;

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		pExpression = new CExpVarUnitary(v.Ptr());
	}
	else if (0 == XMLString::compareString(pElement->getNodeName(),
										   wsConditionDuality))
	{
		DOMElement *pChild = (DOMElement *)pElement->getFirstChild();

		if (!pChild)
			return XML_LOADER_ERROR;

		CAutoPtr<CVariable> v[2];
		size_ n = 0;

		while (pChild)
		{
			ret_ Ret = LoadVariable(Data, pChild, v[n].Ptr(), pPDU);
		
			if (SUCCESS != Ret && XML_INVALID_ELEMENT != Ret)
				return Ret;

			if (SUCCESS == Ret)
				if (2 <= ++n)
					break;

			pChild = (DOMElement *)pChild->getNextSibling();
		}

		auto_xerces_str sOperator(pElement->getAttribute(wsCalculate));
		ECompareCalculate Calculate;

		if (SUCCESS != GetCompareOperator((const ch_1 *)sOperator, Calculate))
			return XML_LOADER_ERROR;

		pExpression = new CExpVarDuality(v[0].Ptr(), Calculate, v[1].Ptr());
	}

	return SUCCESS;
}