Your browser must have JavaScript enabled in order to view this page.
 >  >
 
Welcome Guest#216 Login/register    Go to Bottom
Go to Top

Source for file mass.php

Documentation is available at mass.php

  1. <?php
  2. /**
  3.  * Coinherit for adding mass (volume and weight) abstraction to an object
  4.  *
  5.  * DutchPIPE version 0.4; PHP version 5
  6.  *
  7.  * LICENSE: This source file is subject to version 1.0 of the DutchPIPE license.
  8.  * If you did not receive a copy of the DutchPIPE license, you can obtain one at
  9.  * http://dutchpipe.org/license/1_0.txt or by sending a note to
  10.  * license@dutchpipe.org, in which case you will be mailed a copy immediately.
  11.  *
  12.  * @package    DutchPIPE
  13.  * @subpackage dpuniverse_std
  14.  * @author     Lennert Stock <ls@dutchpipe.org>
  15.  * @copyright  2006, 2007 Lennert Stock
  16.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  17.  * @version    Subversion: $Id: mass.php 277 2007-08-19 18:15:10Z ls $
  18.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  19.  */
  20.  
  21. /**
  22.  * The DutchPIPE property and coinherit system which all objects extend on
  23.  */
  24. inherit(DPUNIVERSE_STD_PATH 'DpProperties.php');
  25.  
  26. /**
  27.  * Gets mass constants
  28.  */
  29.  
  30. /**
  31.  * Coinherit for adding mass (volume and weight) abstraction to an object
  32.  *
  33.  * Creates the following DutchPIPE properties, depending on settings:<br />
  34.  *
  35.  * - int|float <b>weight</b> - Weight of object without inventory
  36.  * - int|float <b>totalWeight</b> - Weight including inventory, cannot be set
  37.  * - int|float <b>volume</b> - Volume of object
  38.  *
  39.  * @package    DutchPIPE
  40.  * @subpackage dpuniverse_std
  41.  * @author     Lennert Stock <ls@dutchpipe.org>
  42.  * @copyright  2006, 2007 Lennert Stock
  43.  * @license    http://dutchpipe.org/license/1_0.txt  DutchPIPE License
  44.  * @version    Release: 0.2.1
  45.  * @link       http://dutchpipe.org/manual/package/DutchPIPE
  46.  */
  47. class Mass extends DpProperties
  48. {
  49.    /**
  50.      * Mother object which is using this coinherit object
  51.      *
  52.      * @var        object 
  53.      * @access     private
  54.      */
  55.     private $mrMotherObject;
  56.  
  57.     /**
  58.      * Directly set the value of an existing DutchPIPE property
  59.      *
  60.      * @param      object    &$motherObject  Mother object which is using this coinherit object
  61.      * @access     private
  62.      */
  63.     final function __construct(&$motherObject)
  64.     {
  65.         $this->mrMotherObject $motherObject;
  66.  
  67.         if (WEIGHT_TYPE_NONE !== WEIGHT_TYPE{
  68.             $this->weight new_dp_property(0'_setWeight');
  69.             $this->totalWeight new_dp_property(0NULL'_getTotalWeight');
  70.         }
  71.  
  72.         if (VOLUME_TYPE_NONE !== VOLUME_TYPE{
  73.             $this->volume new_dp_property(0'_setVolume');
  74.         }
  75.     }
  76.  
  77.     /**
  78.      * Sets weight using member overloading if giving value if a valid weight
  79.      *
  80.      * @param      int|float$weight    Weight of this object
  81.      * @access     private
  82.      */
  83.     protected function _setWeight($val)
  84.     {
  85.         if ((is_integer($val|| is_float($val)) && $val >= 0{
  86.             $this->setDpProperty('weight'$val);
  87.         }
  88.     }
  89.  
  90.     /**
  91.      * Sets volume using member overloading if giving value if a valid weight
  92.      *
  93.      * @param      int|float$weight    Volume of this object
  94.      * @access     private
  95.      */
  96.     protected function _setVolume($val)
  97.     {
  98.         if ((is_integer($val|| is_float($val)) && $val >= 0{
  99.             $this->setDpProperty('volume'$val);
  100.         }
  101.     }
  102.  
  103.     /**
  104.      * Gets total weight - weight of object including weight of inventory
  105.      *
  106.      * @return     int|floatWeight including inventory
  107.      * @access     private
  108.      */
  109.     protected function _getTotalWeight()
  110.     {
  111.         /* Calculates our own weight plus everything we carry/contain */
  112.         $weight $this->getDpProperty('weight');
  113.  
  114.         $inv $this->mrMotherObject->getInventory();
  115.         foreach ($inv as &$ob{
  116.             $tmp $ob->weight;
  117.             if (is_int($tmp)) {
  118.                 $weight += $tmp;
  119.             }
  120.         }
  121.  
  122.         return $weight;
  123.     }
  124. }
  125. ?>

Documentation generated on Mon, 03 Sep 2007 22:22:03 +0200 by phpDocumentor 1.3.0RC6

Click me!
Guest#216
 
 
 
  Go to Top
 
 
Input Field OptionsClose Input Field Go to Top
 
Legal Notices | Copyright © 2006, 2007 Lennert Stock. All rights reserved. Last update: Mon Sep 03 2007, 21:50 CET.