Listing 11
class Leaf : public ILeaf {
private:
double value ;
double uncertainty ;
std::string name ;
public:
// Constructor for a known constant -- with no uncertainty
Leaf(double v) : value (v), uncertainty (0.0) {}
// Constructor for an uncertain number
Leaf(
double v
, double u
, std::string const & name
) :value (v), uncertainty (u), name (name) {
assert(u > 0.0 && "Invalid uncertainty value");
}
virtual double value() const { return value ; }
virtual double uComponent(ILeaf const * i) const {
// There is a non-zero component of uncertainty
// only if 'i' points to this object.
return (i == this) ? uncertainty : 0.0;
}
virtual void dependsOn(Set& s) const {
// A constant does not contribute to the uncertainty of clients.
if(uncertainty != 0.0) s.insert(this);
}
virtual std::string const & name() const { return name ; }
};