Accessing the Constraint Store

The class RIVar is defined to provide access to a real-interval variable in the constraint store. The class RIVar is derived from OZ_CtVar. The private and protected part of the class definition of RIVar is the implementation of the principle described in Section 2.5 of ``The Mozart Constraint Extensions Reference'' for real-interval constraints.

class RIVar : public OZ_CtVar {
private:
 
  RI * _ref;
  RI _copy_encap;
 
  RIProfile _rip;
 
protected:
 
  virtual void ctSetValue(OZ_Term t)
  {
    _copy.init(t);
    _ref = &_copy;
  }
 
  virtual OZ_Ct * ctRefConstraint(OZ_Ct * c)
  {
    return _ref = (RI *) c;
  }
 
  virtual OZ_Ct * ctSaveConstraint(OZ_Ct * c)
  {
    _copy = *(RI *) c;
    return &_copy;
  }
 
  virtual OZ_Ct * ctSaveEncapConstraint(OZ_Ct * c)
  {
    _encap = *(RI *) c;
    return &_encap;
  }
 
  virtual void ctRestoreConstraint(void)
  {
    *_ref = _copy;
  }
 
  virtual void ctSetConstraintProfile(void)
  {
    _rip = *_ref->getProfile();
  }
 
  virtual OZ_CtProfile * ctGetConstraintProfile(void)
  {
    return &_rip;
  }
 
  virtual OZ_Ct * ctGetConstraint(void)
  {
    return _ref;
  }
 
public:
 
  RIVar(void) : OZ_CtVar() { }
 
  RIVar(OZ_Term t) : OZ_CtVar() { read(t); }
 
  virtual OZ_Boolean isTouched(voidconst 
  {
    return _ref->isTouched(_rip);
  }
 
  RI &operator * (void) { return *_ref; }
  RI * operator -> (void) { return _ref; }
 
};

The public part of the class definition is self-explanatory. It provides for constructors, the function isTouched() to enable the CPI to detect if a parameter has been changed, and operators to provide direct access to the real-interval constraints.


Tobias Müller
Version 1.4.0 (20080702)