Hoa central
Public Member Functions | Protected Attributes | List of all members
Hoa\Praspel\Model\Variable\Variable Class Reference
Inheritance diagram for Hoa\Praspel\Model\Variable\Variable:

Public Member Functions

 __construct ($name, $local, Praspel\Model\Clause $clause=null)
 
 setValue ($value)
 
getValue ()
 
 __set ($name, $value)
 
 predicate ($q=null)
 
 sample (Math\Sampler $sampler=null)
 
 reset ()
 
 key ($scalar)
 
 contains ($scalar)
 
 is ()
 
 domainof ($variable)
 
getDomains ()
 
getHeld ()
 
 getName ()
 
 isLocal ()
 
 getConstraints ()
 
 getAlias ()
 
 getClause ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Protected Attributes

 $_name = null
 
 $_local = false
 
 $_clause = null
 
 $_value = null
 
 $_domains = null
 
 $_refDomains = null
 
 $_alias = null
 
 $_constraints = []
 
 $_tmpConstraintsType = null
 
 $_tmpConstraintsIndex = null
 

Detailed Description

Class .

Represent a variable.

Definition at line 53 of file Variable.php.

Constructor & Destructor Documentation

Hoa\Praspel\Model\Variable\Variable::__construct (   $name,
  $local,
Praspel\Model\Clause  $clause = null 
)

Build a variable.

Parameters
string$nameName.
bool$localLocal.
\Hoa\Praspel\Model\Clause$clauseClause.
Returns
void
Exceptions

Definition at line 140 of file Variable.php.

144  {
145  if (('\old' === substr($name, 0, 4) ||
146  '\result' === $name) &&
147  !($clause instanceof Praspel\Model\Ensures)) {
148  throw new Praspel\Exception\Model(
149  '\old(…) and \result are only allowed in @ensures, ' .
150  'given %s in @%s.',
151  0,
152  [$name, $clause->getName()]
153  );
154  }
155 
156  $this->_name = $name;
157  $this->_local = $local;
158  $this->_clause = $clause;
159  $this->_refDomains = &$this->_domains;
160 
161  return;
162  }

Member Function Documentation

Hoa\Praspel\Model\Variable\Variable::__set (   $name,
  $value 
)

Allow to write $variable->in = … to define domains (if $name is not equal to "in", then it is a normal behavior).

Parameters
string$nameName.
mixed$valueValue.
Returns
void
Exceptions

Definition at line 197 of file Variable.php.

198  {
199  if ('in' !== $name) {
200  $this->$name = $value;
201 
202  return;
203  }
204 
205  $onDomains = $this->_domains === $this->_refDomains;
206 
207  if (true === $onDomains &&
208  !empty($this->_domains)) {
209  throw new Praspel\Exception\Model(
210  'Variable $%s has already declared domains.',
211  1,
212  $this->getName()
213  );
214  }
215 
216  if (!($value instanceof Realdom\Disjunction)) {
217  $value = realdom()->const($value);
218  }
219 
220  $this->_refDomains = $value;
221 
222  if (false === $onDomains) {
223  $this->_domains->propagateConstraints(
224  $this->_tmpConstraintsType,
225  $this->_tmpConstraintsIndex
226  );
227 
228  $this->_tmpConstraintsType = null;
229  $this->_tmpConstraintsIndex = null;
230  }
231 
232  unset($this->_refDomains);
233  $this->_refDomains = &$this->_domains;
234 
235  $this->_domains->setHolder($this);
236 
237  foreach ($this->_domains as $domain) {
238  $domain->setConstraints($this->_constraints);
239  }
240 
241  return;
242  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Variable::accept ( Visitor\Visit  $visitor,
$handle = null,
  $eldnah = null 
)

Accept a visitor.

Parameters
\Hoa\Visitor\Visit$visitorVisitor.
mixed&$handleHandle (reference).
mixed$eldnahHandle (no reference).
Returns
mixed

Definition at line 455 of file Variable.php.

459  {
460  return $visitor->visit($this, $handle, $eldnah);
461  }
Hoa\Praspel\Model\Variable\Variable::contains (   $scalar)

Define a “contains” constraint.

Parameters
mixed$scalarValue.
Returns

Definition at line 312 of file Variable.php.

313  {
314  if (!isset($this->_constraints['contains'])) {
315  $this->_constraints['contains'] = [];
316  }
317 
318  $this->_constraints['contains'][] = realdom()->const($scalar);
319 
320  return $this;
321  }
Hoa\Praspel\Model\Variable\Variable::domainof (   $variable)

Declare a “domainof” (alias).

Parameters
\Hoa\Praspel\Model\Variable$variableVariable.
Returns
Exceptions

Definition at line 350 of file Variable.php.

351  {
352  $variables = $this->getClause()->getLocalVariables();
353 
354  if (!isset($variables[$variable])) {
355  throw new Praspel\Exception\Model(
356  'Variable $%s does not exist, cannot alias domains to $%s.',
357  2,
358  [$variable, $this->getName()]
359  );
360  }
361 
362  if (!empty($this->_domains)) {
363  throw new Praspel\Exception\Model(
364  'Variable $%s already has domains, cannot alias new domains ' .
365  'from $%s.',
366  3,
367  [$this->getName(), $variable]
368  );
369  }
370 
371  $this->_alias = $variable;
372  $this->_domains = &$variables[$variable]->getDomains();
373 
374  return $this;
375  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Variable::getAlias ( )

Get alias.

Returns

Definition at line 432 of file Variable.php.

433  {
434  return $this->_alias;
435  }
Hoa\Praspel\Model\Variable\Variable::getClause ( )

Get parent clause.

Returns

Definition at line 442 of file Variable.php.

443  {
444  return $this->_clause;
445  }

Here is the caller graph for this function:

Hoa\Praspel\Model\Variable\Variable::getConstraints ( )

Get constraints.

Returns
array

Definition at line 422 of file Variable.php.

423  {
424  return $this->_constraints;
425  }
& Hoa\Praspel\Model\Variable\Variable::getDomains ( )

Get domains.

Returns

Definition at line 382 of file Variable.php.

383  {
384  return $this->_domains;
385  }

Here is the caller graph for this function:

& Hoa\Praspel\Model\Variable\Variable::getHeld ( )

Get held realdoms.

Returns

Implements Hoa\Realdom\IRealdom\Holder.

Definition at line 392 of file Variable.php.

393  {
394  return $this->getDomains();
395  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Variable::getName ( )

Get variable name.

Returns
string

Implements Hoa\Realdom\IRealdom\Holder.

Definition at line 402 of file Variable.php.

403  {
404  return $this->_name;
405  }

Here is the caller graph for this function:

& Hoa\Praspel\Model\Variable\Variable::getValue ( )

Get value of the variable.

Returns
mixed

Implements Hoa\Realdom\IRealdom\Holder.

Definition at line 183 of file Variable.php.

184  {
185  return $this->_value;
186  }

Here is the caller graph for this function:

Hoa\Praspel\Model\Variable\Variable::is ( )

Add an “is” constraint.

Parameters
string... Keywords.
Returns

Definition at line 329 of file Variable.php.

330  {
331  if (!isset($this->_constraints['is'])) {
332  $this->_constraints['is'] = [];
333  }
334 
335  $this->_constraints['is'] = array_merge(
336  $this->_constraints['is'],
337  func_get_args()
338  );
339 
340  return $this;
341  }
Hoa\Praspel\Model\Variable\Variable::isLocal ( )

Check if the variable is local (let) or not.

Returns
bool

Definition at line 412 of file Variable.php.

413  {
414  return $this->_local;
415  }
Hoa\Praspel\Model\Variable\Variable::key (   $scalar)

Define a “key” constraint. Use $variable->key(…)->in = …;

Parameters
mixed$scalarValue.
Returns

Definition at line 288 of file Variable.php.

289  {
290  if (!isset($this->_constraints['key'])) {
291  $this->_constraints['key'] = [];
292  }
293 
294  unset($this->_refDomains);
295  $handle = &$this->_constraints['key'][];
296  $handle[0] = realdom()->const($scalar);
297  $this->_refDomains = &$handle[1];
298 
299  end($this->_constraints['key']);
300  $this->_tmpConstraintsType = 'key';
301  $this->_tmpConstraintsIndex = key($this->_constraints['key']);
302 
303  return $this;
304  }
Hoa\Praspel\Model\Variable\Variable::predicate (   $q = null)

Definition at line 251 of file Variable.php.

252  {
253  if (null === $q) {
254  $q = $this->getValue();
255  }
256 
257  return $this->getDomains()->predicate($q);
258  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Variable::reset ( )

Call the reset() method on realistic domains.

Returns
void

Definition at line 277 of file Variable.php.

278  {
279  return $this->getDomains()->reset();
280  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Variable::sample ( Math\Sampler  $sampler = null)

Call the sample() method on realistic domains.

Parameters
\Hoa\Math\Sampler$samplerSampler.
Returns
mixed
Exceptions

Definition at line 267 of file Variable.php.

268  {
269  return $this->getDomains()->sample($sampler);
270  }

Here is the call graph for this function:

Hoa\Praspel\Model\Variable\Variable::setValue (   $value)

Set a value to the variable.

Parameters
mixed$valueValue.
Returns
mixed

Definition at line 170 of file Variable.php.

171  {
172  $old = $this->_value;
173  $this->_value = $value;
174 
175  return $old;
176  }

Member Data Documentation

Hoa\Praspel\Model\Variable\Variable::$_alias = null
protected

Definition at line 104 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_clause = null
protected

Definition at line 76 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_constraints = []
protected

Definition at line 111 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_domains = null
protected

Definition at line 90 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_local = false
protected

Definition at line 69 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_name = null
protected

Definition at line 62 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_refDomains = null
protected

Definition at line 97 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_tmpConstraintsIndex = null
protected

Definition at line 127 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_tmpConstraintsType = null
protected

Definition at line 119 of file Variable.php.

Hoa\Praspel\Model\Variable\Variable::$_value = null
protected

Definition at line 83 of file Variable.php.


The documentation for this class was generated from the following file: