boxed_scalars.php 964 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. *
  4. * Boxed scalar values, usable with classes implementing Comparable_Interface
  5. * based on an OSInet Finite_State_Machine (fsm).
  6. *
  7. * This version relies on OSInet FSM >= 1.6
  8. *
  9. * @copyright (c) 2007 OSI
  10. * @license Licensed under the CeCILL 2.0
  11. * @version CVS: $Id: boxed_scalars.php,v 1.3 2007-06-10 19:39:54 marand Exp $
  12. * @link http://wiki.audean.com/fsm/fsm
  13. * @since Not applicable yet
  14. * @package default
  15. */
  16. /**
  17. * This class enables use of scalar values with classes implementing Comparable_Interface
  18. * @package default
  19. */
  20. class boxed_int implements Comparable_Interface
  21. {
  22. protected $value;
  23. function __construct($n)
  24. {
  25. $this->value = $n;
  26. }
  27. function cmp(Comparable_Interface $other)
  28. {
  29. if ($this->value < $other->value)
  30. return -1;
  31. elseif ($this->value > $other->value)
  32. return 1;
  33. else
  34. return 0;
  35. }
  36. function as_int()
  37. {
  38. return $this->value;
  39. }
  40. }