當前位置: 首頁>>代碼示例>>C++>>正文


C++ shared_ptr::getSign方法代碼示例

本文整理匯總了C++中tr1::shared_ptr::getSign方法的典型用法代碼示例。如果您正苦於以下問題:C++ shared_ptr::getSign方法的具體用法?C++ shared_ptr::getSign怎麽用?C++ shared_ptr::getSign使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tr1::shared_ptr的用法示例。


在下文中一共展示了shared_ptr::getSign方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。

示例1: calcSign

// Returns char identifying sign resulting from multiplication or division of two numbers
//
// Returns:
// char 			'+' or '-'
char Exponent::calcSign(tr1::shared_ptr<AbstractNumber> number){
	if(sign == number->getSign()){
		return '+';
	}
	else{
		return '-';
	}
}
開發者ID:kylelin47,項目名稱:COP-Project,代碼行數:12,代碼來源:Exponent.cpp

示例2: if

// Adds number to this and returns the sum
//
// Parameters:
// shared_ptr<AbstractNumber> number	number being added
//
// Returns:
// shared_ptr<AbstractNumber> 			resulting sum of addition
 tr1::shared_ptr<AbstractNumber> Exponent::add(tr1::shared_ptr<AbstractNumber> number){
 	// Checks for cancellation
 	number = number->simplify();
 	if(abs(toDouble() - number->toDouble()) < 0.000001 &&
 	   this->getSign() != number->getSign()){
 		tr1::shared_ptr<AbstractNumber> r(new SmartInteger(0));

 	    return r;
 	}
 	// Checks for duplication/simplification
 	else if(abs(toDouble() - number->toDouble()) < 0.000001 &&
 			this->getSign() == number->getSign()){
 		vector< tr1::shared_ptr<AbstractNumber> > MultVector;
		tr1::shared_ptr<AbstractNumber> i(new SmartInteger(2));
		MultVector.push_back(i);
		tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
		MultVector.push_back(me);
		tr1::shared_ptr<AbstractNumber> r(new MultExpression(MultVector, '+'));

	    return r;
  	}

    //Can't tell if they add or not
 	else if(number->getName() == "SumExpression" ||
            number->getName() == "MultExpression"){
 	    return number->add(shared_from_this());
 	}
    // Duplication necessary for simplification
 	// Assuming number is in simplest form

 	// No simplification possible
	else{
		vector< tr1::shared_ptr<AbstractNumber> > SumVector;
		tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
		SumVector.push_back(me);
		SumVector.push_back(number);
		tr1::shared_ptr<AbstractNumber> r(new SumExpression(SumVector));

	    return r;
	}

}
開發者ID:kylelin47,項目名稱:COP-Project,代碼行數:49,代碼來源:Exponent.cpp

示例3: if

tr1::shared_ptr<AbstractNumber> E::divide(tr1::shared_ptr<AbstractNumber>number){
    char newSign = '-';
    if (getSign() == number->getSign())
    {
        newSign = '+';
    }
		if (number -> getName() == "E")
		{

			if (newSign == '+')
			{
				tr1::shared_ptr<AbstractNumber> output(new SmartInteger(1));
				return output;
			}

			else
			{
				tr1::shared_ptr<AbstractNumber> output(new SmartInteger(-1));
				return output;
			}

		}

		else if (number -> getName() == "Exponent")
		{
		    tr1::shared_ptr<Exponent> numExp = tr1::static_pointer_cast<Exponent>(number);
			if (numExp -> getValue("base") -> getName() == "E")
			{
				tr1::shared_ptr<AbstractNumber> num(new SmartInteger(1));
				tr1::shared_ptr<AbstractNumber> exp = number->getValue("power");
				tr1::shared_ptr<AbstractNumber> exp2(new SmartInteger(-1));
				tr1::shared_ptr<AbstractNumber> me(new E());
				tr1::shared_ptr<AbstractNumber> ans2(new Exponent(me, exp -> add(exp2), newSign));
				tr1::shared_ptr<AbstractNumber> output2(new MultExpression(num, ans2, '+'));
				return output2;
			}
		}
        else if(number->getName() == "MultExpression")
        {
            tr1::shared_ptr<MultExpression> MultE = tr1::static_pointer_cast<MultExpression>(number);
            vector<tr1::shared_ptr<AbstractNumber> > MultENum = MultE->getNumerator();
            vector<tr1::shared_ptr<AbstractNumber> > MultEDem = MultE->getDenominator();
            if (MultEDem.size() == 0)
            {
                tr1::shared_ptr<AbstractNumber> one(new SmartInteger(1));
                MultEDem.push_back(one);
            }
            tr1::shared_ptr<AbstractNumber> reversedMultE(new MultExpression(MultEDem, MultENum, number->getSign()));
            return reversedMultE->multiply(shared_from_this());
        }

        tr1::shared_ptr<AbstractNumber> output2(new MultExpression(shared_from_this(), number, newSign));
        return output2;
}
開發者ID:kylelin47,項目名稱:COP-Project,代碼行數:54,代碼來源:E.cpp


注:本文中的tr1::shared_ptr::getSign方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。