Hoa central
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Hoa\Realdom\Realdom Class Reference
Inheritance diagram for Hoa\Realdom\Realdom:

Public Member Functions

 __construct ()
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 getArguments ()
 
 count ()
 
 getName ()
 
 setSampler (Math\Sampler $sampler)
 
 getSampler ()
 
 getValue ()
 
 reset ()
 
 predicate ($q)
 
 sample (Math\Sampler $sampler=null)
 
 intersectWith (Realdom $realdom)
 
 setConstraints (Array &$constraints)
 
 propagateConstraints ($type, $index)
 
 is ($qualifier)
 
 setHolder (IRealdom\Holder $holder)
 
 getHolder ()
 
 setPraspelVisitor (Visitor\Visit $visitor)
 
 getPraspelVisitor ()
 
 accept (Visitor\Visit $visitor, &$handle=null, $eldnah=null)
 
- Public Member Functions inherited from Hoa\Visitor\Element
 accept (Visit $visitor, &$handle=null, $eldnah=null)
 

Static Public Member Functions

static autoBoxing (Array &$arguments, Realdom $self=null)
 
static setDefaultSampler (Math\Sampler $sampler)
 
static getDefaultSampler ()
 
static setMaxTry ($maxtry)
 
static getMaxTry ()
 
static setDefaultPraspelVisitor (Visitor\Visit $visitor)
 
static getDefaultPraspelVisitor ()
 

Public Attributes

const NAME = '(null)'
 

Protected Member Functions

 construct ()
 
 setValue ($sampled)
 
 resetArguments ()
 
 _predicate ($q)
 
 _sample (Math\Sampler $sampler)
 
getConstraints ()
 
 _propagateConstraints ($type, $index, Array &$constraints)
 

Protected Attributes

 $_arguments = null
 
 $arguments = null
 
 $__sampler = null
 
 $_value = null
 
 $_constraints = null
 
 $_holder = null
 
 $_constructed = false
 
 $_praspelVisitor = null
 

Static Protected Attributes

static $_sampler = null
 
static $_maxtry = 64
 
static $_defaultPraspelVisitor = null
 

Detailed Description

Class .

Abstract-top-super realistic domain :-).

Definition at line 52 of file Realdom.php.

Constructor & Destructor Documentation

Hoa\Realdom\Realdom::__construct ( )
final

Build a realistic domain.

Returns
void
Exceptions

Definition at line 150 of file Realdom.php.

151  {
152  switch ($this->_arguments) {
153  case null:
154  $this->arguments = [];
155 
156  break;
157 
158  case …:
159  $this->arguments = func_get_args();
160  self::autoBoxing($this->arguments, $this);
161 
162  break;
163 
164  default:
165  $arguments = func_get_args();
166  $hints = [];
167  $this->arguments = [];
168  $i = 0;
169 
170  reset($this->_arguments);
171 
172  foreach ($arguments as $argument) {
173  $name = key($this->_arguments);
174  $hint = null;
175 
176  if (… === $argument) {
177  if (is_int($name)) {
178  throw new Exception\IllegalArgument(
179  'Argument %s passed to %s() does not have a ' .
180  'default value.',
181  0,
182  [$i + 1, $this->getName()]
183  );
184  }
185 
186  $argument = current($this->_arguments);
187  }
188 
189  if (is_int($name)) {
190  $name = current($this->_arguments);
191  ++$i;
192  }
193 
194  if (false !== $pos = strrpos($name, ' ')) {
195  $hint = trim(substr($name, 0, $pos));
196  $name = substr($name, $pos + 1);
197  }
198 
199  $this->arguments[$name] = $argument;
200  $hints[] = $hint;
201  next($this->_arguments);
202  }
203 
204  while (list($name, $default) = each($this->_arguments)) {
205  if (is_int($name)) {
206  $j = 0;
207  array_walk(
208  $this->_arguments,
209  function ($_, $key) use (&$j) {
210  $j += is_int($key);
211 
212  return;
213  }
214  );
215 
216  throw new Exception\MissingArgument(
217  1 < $j
218  ? '%s() expects at least %d parameters, %d given.'
219  : '%s() expects at least %d parameter, %d given.',
220  1,
221  [$this->getName(), $j, $i]
222  );
223  }
224 
225  $hint = null;
226 
227  if (false !== $pos = strrpos($name, ' ')) {
228  $hint = trim(substr($name, 0, $pos));
229  $name = substr($name, $pos + 1);
230  }
231 
232  $this->arguments[$name] = $default;
233  $hints[] = $hint;
234  }
235 
236  self::autoBoxing($this->arguments, $this);
237 
238  foreach ($this->arguments as &$argument) {
239  $hint = current($hints);
240 
241  if (null === $hint) {
242  next($hints);
243 
244  continue;
245  }
246 
247  if ($argument instanceof IRealdom\Holder) {
248  $_realdoms = $argument->getHeld();
249  } elseif ($argument instanceof IRealdom\Crate) {
250  $_realdoms = $argument->getTypes();
251  } elseif ($argument instanceof Disjunction) {
252  $_realdoms = $argument->getRealdoms();
253  } else {
254  $_realdoms = [$argument];
255  }
256 
257  $k = 0;
258 
259  $_hints = explode('|', $hint);
260 
261  foreach ($_hints as &$_hint) {
262  if ('\\' !== $_hint[0]) {
263  $_hint = __NAMESPACE__ . '\\' . $_hint;
264  }
265  }
266 
267  foreach ($_realdoms as $_realdom) {
268  $flag = false;
269 
270  foreach ($_hints as $__hint) {
271  if ($_realdom instanceof $__hint ||
272  $_realdom === $__hint) {
273  $flag = true;
274 
275  break;
276  }
277  }
278 
279  if (false === $flag) {
280  unset($_realdoms[$k]);
281  } else {
282  ++$k;
283  }
284  }
285 
286  switch (count($_realdoms)) {
287  case 0:
288  if ($argument instanceof IRealdom\Holder) {
289  throw new Exception\IllegalArgument(
290  'Argument %d passed to %s() must be of ' .
291  'type %s, variable %s does not satisfy ' .
292  'this constraint.',
293  2,
294  [
295  key($hints),
296  $this->getName(),
297  mb_strtolower($hint),
298  $argument->getName()
299  ]
300  );
301  }
302 
303  throw new Exception\IllegalArgument(
304  'Argument %d passed to %s() must be of type ' .
305  '%s, %s given.',
306  3,
307  [
308  key($hints),
309  $this->getName(),
310  mb_strtolower($hint),
311  mb_strtolower(mb_substr(
312  $_ = get_class($argument),
313  mb_strrpos($_, '\\') + 1
314  ))
315  ]
316  );
317 
318  break;
319 
320  case 1:
321  if ($argument instanceof IRealdom\Crate) {
322  break;
323  }
324 
325  $argument = $_realdoms[0];
326 
327  break;
328 
329  default:
330  throw new Exception\IllegalArgument(
331  'Variable %s, passed as argument %d of %s(), ' .
332  'has to many domains.',
333  4,
334  [
335  $argument->getName(),
336  key($hints),
337  $this->getName()
338  ]
339  );
340  }
341 
342  next($hints);
343  }
344  }
345 
346  return;
347  }

Here is the call graph for this function:

Member Function Documentation

Hoa\Realdom\Realdom::_predicate (   $q)
abstractprotected

Predicate whether the sampled value belongs to the realistic domains.

Parameters
mixed$qSampled value.
Returns
boolean

Here is the caller graph for this function:

Hoa\Realdom\Realdom::_propagateConstraints (   $type,
  $index,
Array &  $constraints 
)
protected

Propagate constraints.

Parameters
string$typeType.
int$indexIndex.
array$constraintsConstraints.
Returns
void
Exceptions

Definition at line 793 of file Realdom.php.

797  {
798  return;
799  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::_sample ( Math\Sampler  $sampler)
abstractprotected

Sample one new value.

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

Here is the caller graph for this function:

Hoa\Realdom\Realdom::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 902 of file Realdom.php.

906  {
907  return $visitor->visit($this, $handle, $eldnah);
908  }
static Hoa\Realdom\Realdom::autoBoxing ( Array &  $arguments,
Realdom  $self = null 
)
static

Auto-boxing.

Parameters
array&$argumentsArguments.
\Hoa\Realdom$selfSelf (if we auto-box arguments).
Returns
void

Definition at line 366 of file Realdom.php.

367  {
368  if (is_object($self) &&
369  (get_class($self) === 'Hoa\Realdom\Constarray' ||
370  get_class($self) === 'Hoa\Realdom\Constboolean' ||
371  get_class($self) === 'Hoa\Realdom\Constfloat' ||
372  get_class($self) === 'Hoa\Realdom\Constinteger' ||
373  get_class($self) === 'Hoa\Realdom\Constnull' ||
374  get_class($self) === 'Hoa\Realdom\Conststring')) {
375  return;
376  }
377 
378  foreach ($arguments as &$argument) {
379  switch (gettype($argument)) {
380  case 'array':
381  $handle = [];
382 
383  foreach ($argument as &$pair) {
384  $handle[] = &$pair[0];
385 
386  if (isset($pair[1])) {
387  $handle[] = &$pair[1];
388  }
389  }
390 
391  self::autoBoxing($handle);
392 
393  $argument = new Constarray($argument);
394 
395  break;
396 
397  case 'boolean':
398  $argument = new Constboolean($argument);
399 
400  break;
401 
402  case 'double':
403  $argument = new Constfloat($argument);
404 
405  break;
406 
407  case 'integer':
408  $argument = new Constinteger($argument);
409 
410  break;
411 
412  case 'NULL':
413  $argument = new Constnull($argument);
414 
415  break;
416 
417  case 'string':
418  $argument = new Conststring($argument);
419 
420  break;
421 
422  default:
423  if ($argument instanceof IRealdom\Holder) {
424  $argument = $argument->getHeld();
425 
426  if (null !== $self) {
427  $argument = $argument[0];
428  }
429 
430  break;
431  }
432  }
433  }
434 
435  return;
436  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::construct ( )
protected

Constructor of the realistic domain.

Returns
void

Definition at line 354 of file Realdom.php.

355  {
356  return;
357  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::count ( )

Get arity.

Returns
int

Definition at line 508 of file Realdom.php.

509  {
510  return count($this->arguments);
511  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::getArguments ( )

Get all arguments values.

Returns
array

Definition at line 498 of file Realdom.php.

499  {
500  return $this->arguments;
501  }

Here is the caller graph for this function:

& Hoa\Realdom\Realdom::getConstraints ( )
protected

Get constraints.

Returns
array

Definition at line 765 of file Realdom.php.

766  {
767  return $this->_constraints;
768  }

Here is the caller graph for this function:

static Hoa\Realdom\Realdom::getDefaultPraspelVisitor ( )
static

Get default Praspel visitor. If default visitor is null, Hoa will be used.

Parameters
\Hoa\Visitor\Visit$visitorVisitor.
Returns

Definition at line 861 of file Realdom.php.

862  {
863  if (null === static::$_defaultPraspelVisitor) {
864  static::$_defaultPraspelVisitor = new Praspel\Visitor\Praspel();
865  }
866 
867  return static::$_defaultPraspelVisitor;
868  }
static Hoa\Realdom\Realdom::getDefaultSampler ( )
static

Get the default sampler.

Returns

Definition at line 542 of file Realdom.php.

543  {
544  return static::$_sampler;
545  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::getHolder ( )

Get holder.

Returns

Definition at line 835 of file Realdom.php.

836  {
837  return $this->_holder;
838  }

Here is the caller graph for this function:

static Hoa\Realdom\Realdom::getMaxTry ( )
static

Get the max try number.

Returns
int

Definition at line 614 of file Realdom.php.

615  {
616  return self::$_maxtry;
617  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::getName ( )

Get the realistic domain name.

Returns
string

Definition at line 518 of file Realdom.php.

519  {
520  return static::NAME;
521  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::getPraspelVisitor ( )

Get Praspel visitor.

Returns

Definition at line 889 of file Realdom.php.

890  {
891  return $this->_praspelVisitor ?: static::getDefaultPraspelVisitor();
892  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::getSampler ( )

Get the sampler.

Returns

Definition at line 566 of file Realdom.php.

567  {
568  return $this->__sampler ?: static::$_sampler;
569  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::getValue ( )

Get the sampled value.

Returns
mixed

Definition at line 590 of file Realdom.php.

591  {
592  return $this->_value;
593  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::intersectWith ( Realdom  $realdom)

Check if the realistic domain intersects with another.

Parameters
\Hoa\Realdom$realdomRealistic domain.
Returns
bool

Definition at line 741 of file Realdom.php.

742  {
743  return false;
744  }
Hoa\Realdom\Realdom::is (   $qualifier)

Test the “is” constraint.

Parameters
string$qualifierQualifier.
Returns
bool

Definition at line 807 of file Realdom.php.

808  {
809  if (!isset($this->_constraints['is'])) {
810  return false;
811  }
812 
813  return in_array($qualifier, $this->_constraints['is']);
814  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::offsetExists (   $offset)

Check if an argument exists.

Parameters
string$offsetAttribute name.
Returns
bool

Definition at line 444 of file Realdom.php.

445  {
446  return
447  isset($this->arguments[$offset]) &&
448  !($this->arguments[$offset] instanceof Constnull);
449  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::offsetGet (   $offset)

Get an argument value.

Parameters
string$offsetAttribute name.
Returns
mixed

Definition at line 457 of file Realdom.php.

458  {
459  return
460  true === $this->offsetExists($offset)
461  ? $this->arguments[$offset]
462  : null;
463  }
offsetExists($offset)
Definition: Realdom.php:444

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Realdom::offsetSet (   $offset,
  $value 
)

Set an argument value.

Parameters
string$offsetAttribute name.
mixed$valueAttribute value.
Returns
mixed

Definition at line 472 of file Realdom.php.

473  {
474  $old = $this->offsetGet($offset);
475  $this->arguments[$offset] = $value;
476 
477  return $old;
478  }
offsetGet($offset)
Definition: Realdom.php:457

Here is the call graph for this function:

Hoa\Realdom\Realdom::offsetUnset (   $offset)

Unset an argument.

Parameters
string$offsetAttribute name.
Returns
void

Definition at line 486 of file Realdom.php.

487  {
488  unset($this->arguments[$offset]);
489 
490  return;
491  }
Hoa\Realdom\Realdom::predicate (   $q)

Predicate whether the sampled value belongs to the realistic domains.

Parameters
mixed$qSampled value.
Returns
boolean

Definition at line 661 of file Realdom.php.

662  {
663  if (false === $this->_constructed) {
664  $this->construct();
665  $this->_constructed = true;
666  }
667 
668  return $this->_predicate($q);
669  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Realdom::propagateConstraints (   $type,
  $index 
)

Propagate constraints (public).

Parameters
string$typeType.
int$indexIndex.
Returns
void

Definition at line 777 of file Realdom.php.

778  {
779  $this->_propagateConstraints($type, $index, $this->getConstraints());
780 
781  return;
782  }
_propagateConstraints($type, $index, Array &$constraints)
Definition: Realdom.php:793

Here is the call graph for this function:

Hoa\Realdom\Realdom::reset ( )

Reset the realistic domain.

Returns
void

Definition at line 624 of file Realdom.php.

625  {
626  if (false === $this->_constructed) {
627  $this->construct();
628  $this->_constructed = true;
629  }
630 
631  if ($this instanceof IRealdom\Nonconvex &&
632  isset($this->_discredited)) {
633  $this->_discredited = [];
634  }
635 
636  return;
637  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Realdom::resetArguments ( )
protected

Helper to reset all arguments.

Returns
void

Definition at line 644 of file Realdom.php.

645  {
646  foreach ($this->getArguments() as $name => $argument) {
647  if ($argument instanceof self) {
648  $argument->reset();
649  }
650  }
651 
652  return;
653  }

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Realdom::sample ( Math\Sampler  $sampler = null)

Sample a new value.

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

Definition at line 686 of file Realdom.php.

687  {
688  if (false === $this->_constructed) {
689  $this->construct();
690  $this->_constructed = true;
691  }
692 
693  if (null === $sampler &&
694  null === $sampler = $this->getSampler()) {
695  throw new Exception(
696  'No sampler set. Please, use the %s::setDefaultSampler() or ' .
697  '%1$s::setSampler() method.',
698  4,
699  __CLASS__
700  );
701  }
702 
703  $maxtry = $this->getMaxTry();
704 
705  do {
706  $sampled = $this->_sample($sampler);
707  $predicate = $this->predicate($sampled);
708 
709  if (false === $predicate) {
710  $this->reset();
711  }
712  } while (false === $predicate && 0 < --$maxtry);
713 
714  if (0 >= $maxtry) {
715  throw new Exception(
716  'Cannot sample a value, all tries failed (%d tries) from %s.',
717  5,
718  [$this->getMaxTry(), $this->getName()]
719  );
720  }
721 
722  $this->setValue($sampled);
723 
724  return $sampled;
725  }
static getMaxTry()
Definition: Realdom.php:614
_sample(Math\Sampler $sampler)
setValue($sampled)
Definition: Realdom.php:577

Here is the call graph for this function:

Here is the caller graph for this function:

Hoa\Realdom\Realdom::setConstraints ( Array &  $constraints)

Set constraints. Please, see Hoa.

Parameters
array&$constraintsContraints.
Returns

Definition at line 753 of file Realdom.php.

754  {
755  $this->_constraints = &$constraints;
756 
757  return $this;
758  }
static Hoa\Realdom\Realdom::setDefaultPraspelVisitor ( Visitor\Visit  $visitor)
static

Set default Praspel visitor.

Parameters
\Hoa\Visitor\Visit$visitorVisitor.
Returns

Definition at line 846 of file Realdom.php.

847  {
848  $old = static::$_defaultPraspelVisitor;
849  static::$_defaultPraspelVisitor = $visitor;
850 
851  return $old;
852  }
static Hoa\Realdom\Realdom::setDefaultSampler ( Math\Sampler  $sampler)
static

Set the default sampler.

Parameters
\Hoa\Math\Sampler$samplerSampler.
Returns

Definition at line 529 of file Realdom.php.

530  {
531  $old = static::$_sampler;
532  static::$_sampler = $sampler;
533 
534  return $old;
535  }

Here is the caller graph for this function:

Hoa\Realdom\Realdom::setHolder ( IRealdom\Holder  $holder)

Set holder.

Parameters
\Hoa\Realdom\IRealdom\Holder$holderHolder.
Returns

Definition at line 822 of file Realdom.php.

823  {
824  $old = $holder;
825  $this->_holder = $holder;
826 
827  return $old;
828  }
static Hoa\Realdom\Realdom::setMaxTry (   $maxtry)
static

Set the max try number.

Parameters
int$maxtryMax try authorized.
Returns
int

Definition at line 601 of file Realdom.php.

602  {
603  $old = self::$_maxtry;
604  self::$_maxtry = $maxtry;
605 
606  return $old;
607  }
Hoa\Realdom\Realdom::setPraspelVisitor ( Visitor\Visit  $visitor)

Set Praspel visitor.

Parameters
\Hoa\Visitor\Visit$visitorVisitor.
Returns

Definition at line 876 of file Realdom.php.

877  {
878  $old = $this->_praspelVisitor;
879  $this->_praspelVisitor = $visitor;
880 
881  return $old;
882  }
Hoa\Realdom\Realdom::setSampler ( Math\Sampler  $sampler)

Set the sampler.

Parameters
\Hoa\Math\Sampler$samplerSampler.
Returns

Definition at line 553 of file Realdom.php.

554  {
555  $old = $this->__sampler;
556  $this->__sampler = $sampler;
557 
558  return $old;
559  }
Hoa\Realdom\Realdom::setValue (   $sampled)
protected

Set the sampled value.

Parameters
mixed$sampledSampled value.
Returns
mixed

Definition at line 577 of file Realdom.php.

578  {
579  $old = $this->_value;
580  $this->_value = $sampled;
581 
582  return $old;
583  }

Here is the caller graph for this function:

Member Data Documentation

Hoa\Realdom\Realdom::$__sampler = null
protected

Definition at line 90 of file Realdom.php.

Hoa\Realdom\Realdom::$_arguments = null
protected

Definition at line 69 of file Realdom.php.

Hoa\Realdom\Realdom::$_constraints = null
protected

Definition at line 111 of file Realdom.php.

Hoa\Realdom\Realdom::$_constructed = false
protected

Definition at line 125 of file Realdom.php.

Hoa\Realdom\Realdom::$_defaultPraspelVisitor = null
staticprotected

Definition at line 132 of file Realdom.php.

Hoa\Realdom\Realdom::$_holder = null
protected

Definition at line 118 of file Realdom.php.

Hoa\Realdom\Realdom::$_maxtry = 64
staticprotected

Definition at line 104 of file Realdom.php.

Hoa\Realdom\Realdom::$_praspelVisitor = null
protected

Definition at line 139 of file Realdom.php.

Hoa\Realdom\Realdom::$_sampler = null
staticprotected

Definition at line 83 of file Realdom.php.

Hoa\Realdom\Realdom::$_value = null
protected

Definition at line 97 of file Realdom.php.

Hoa\Realdom\Realdom::$arguments = null
protected

Definition at line 76 of file Realdom.php.

const Hoa\Realdom\Realdom::NAME = '(null)'

Realistic domain name.

string

Definition at line 62 of file Realdom.php.


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