本文整理汇总了C++中tr1::shared_ptr::getValue方法的典型用法代码示例。如果您正苦于以下问题:C++ shared_ptr::getValue方法的具体用法?C++ shared_ptr::getValue怎么用?C++ shared_ptr::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tr1::shared_ptr
的用法示例。
在下文中一共展示了shared_ptr::getValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// Multiplies number by this and returns the product
//
// Parameters:
// shared_ptr<AbstractNumber> number number being multiplied
//
// Returns:
// shared_ptr<AbstractNumber> resulting product of multiplication
tr1::shared_ptr<AbstractNumber> Exponent::multiply(tr1::shared_ptr<AbstractNumber> number){
// Checks for simplification if both exponents
number = number->simplify();
if(number->getName() == "Exponent"){
tr1::shared_ptr<Exponent> givenNumber = tr1::static_pointer_cast<Exponent>(number);
if(abs(givenNumber->getValue("base")->toDouble() - base->toDouble()) < 0.000001){
tr1::shared_ptr<AbstractNumber> r(new Exponent(base, power->add(givenNumber->getValue("power")), this->calcSign(number)));
return r;
}
else if (number->getName() == "Radical") {
if (abs(number->getValue("value")->toDouble() - base->toDouble()) < 0.000001 )
{
std::vector< tr1::shared_ptr<AbstractNumber> > SumVector;
tr1::shared_ptr<AbstractNumber> one(new SmartInteger(1));
tr1::shared_ptr<AbstractNumber> invertedRoot(new MultExpression(one, number->getValue("root")->noSign(), number->getValue("root")->getSign()));
SumVector.push_back(power);
SumVector.push_back(invertedRoot);
tr1::shared_ptr<AbstractNumber> power(new SumExpression(SumVector));
tr1::shared_ptr<AbstractNumber> output(new Exponent(number->getValue("value")->noSign(), power, sign));
return output;
}
}
else{
tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
tr1::shared_ptr<AbstractNumber> r(new MultExpression(me, number, this->calcSign(number)));
return r;
}
}
// Checks for simplification if number = base
// Adds 1 to exponent
else if(abs(number->toDouble() - base->toDouble()) < 0.000001 ){
tr1::shared_ptr<AbstractNumber> c(new SmartInteger(1));
tr1::shared_ptr<AbstractNumber> r(new Exponent(base, power->add(c), this->calcSign(number)));
return r;
}
else if(number->getName() == "SumExpression" || number->getName() == "MultExpression")
{
return number->multiply(shared_from_this());
}
vector< tr1::shared_ptr<AbstractNumber> > MultVector;
tr1::shared_ptr<AbstractNumber> me(new Exponent(base, power, sign));
MultVector.push_back(me);
MultVector.push_back(number);
tr1::shared_ptr<AbstractNumber> r(new MultExpression(MultVector, '+'));
return r;
}
示例2: 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;
}