ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilBitmask Class Reference

ilBitmask is a utility class to deal with bitmask-based settings. More...

+ Collaboration diagram for ilBitmask:

Public Member Functions

 __construct ($a_setting_names, $a_bitmask)
 Public constructor instantiating a class of type ilBitmask.
 get ($a_setting_name)
 Gets the given setting from the bitmask.
 set ($a_setting_name, $value)
 Sets the given setting from the bitmask.
 getBitmask ()
 Returns the bitmask.

Protected Attributes

 $setting_names
 $bitmask

Detailed Description

ilBitmask is a utility class to deal with bitmask-based settings.

The concept is to instantiate an instance of the class, passing an array of setting-names and the bitmask. Then you can access the bitmasks individual settings in your class with a simple accessor. This is a stable alternative to defining the cardinality of the individual settings in a dozen setters but in one convenient place.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 15 of file class.ilBitmask.php.

Constructor & Destructor Documentation

ilBitmask::__construct (   $a_setting_names,
  $a_bitmask 
)

Public constructor instantiating a class of type ilBitmask.

Parameters
$a_setting_namesstring[] Array of names ordered by ordinality
$a_bitmaskinteger Integer holding the current bitmask
Returns
ilBitmask

Definition at line 31 of file class.ilBitmask.php.

{
$this->setting_names = $a_setting_names;
$this->bitmask = $a_bitmask;
return;
}

Member Function Documentation

ilBitmask::get (   $a_setting_name)

Gets the given setting from the bitmask.

Parameters
$a_setting_namestring Name of the setting.
Returns
bool
Exceptions
ilExceptionThrown when setting is not available.

Definition at line 46 of file class.ilBitmask.php.

{
$i = 1;
foreach($this->setting_names as $name)
{
if ($name == $a_setting_name)
{
$retval = (($this->bitmask & $i) > 0);
return $retval;
}
$i = $i * 2;
}
require_once './Services/Exceptions/classes/class.ilException.php';
throw new ilException ('No such setting on bitmask.');
}
ilBitmask::getBitmask ( )

Returns the bitmask.

Returns
integer $bitmask The current bitmask.

Definition at line 110 of file class.ilBitmask.php.

References $bitmask.

{
}
ilBitmask::set (   $a_setting_name,
  $value 
)

Sets the given setting from the bitmask.

Parameters
$a_setting_name
$value
Returns
void
Exceptions
ilExceptionThrown when setting is not available.

Definition at line 71 of file class.ilBitmask.php.

{
if (!in_array($a_setting_name, $this->setting_names))
{
require_once './Services/Exceptions/classes/class.ilException.php';
throw new ilException ('No such setting on bitmask.');
}
$current_value = $this->get($a_setting_name);
if ($current_value == $value)
{
return;
}
$i = 1;
foreach($this->setting_names as $name)
{
if ($name == $a_setting_name)
{
if ($value == true)
{
$this->bitmask = $this->bitmask | $i;
}
else
{
$this->bitmask = $this->bitmask ^ $i;
}
}
$i = $i * 2;
}
return;
}

Field Documentation

ilBitmask::$bitmask
protected

Definition at line 21 of file class.ilBitmask.php.

Referenced by getBitmask().

ilBitmask::$setting_names
protected

Definition at line 18 of file class.ilBitmask.php.


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