ILIAS  release_4-4 Revision
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. More...
 
 get ($a_setting_name)
 Gets the given setting from the bitmask. More...
 
 set ($a_setting_name, $value)
 Sets the given setting from the bitmask. More...
 
 getBitmask ()
 Returns the bitmask. More...
 

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

◆ __construct()

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.

32  {
33  $this->setting_names = $a_setting_names;
34  $this->bitmask = $a_bitmask;
35  return;
36  }

Member Function Documentation

◆ get()

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.

47  {
48  $i = 1;
49  foreach($this->setting_names as $name)
50  {
51  if ($name == $a_setting_name)
52  {
53  $retval = (($this->bitmask & $i) > 0);
54  return $retval;
55  }
56  $i = $i * 2;
57  }
58  require_once './Services/Exceptions/classes/class.ilException.php';
59  throw new ilException ('No such setting on bitmask.');
60  }
Base class for ILIAS Exception handling.

◆ getBitmask()

ilBitmask::getBitmask ( )

Returns the bitmask.

Returns
integer $bitmask The current bitmask.

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

References $bitmask.

111  {
112  return $this->bitmask;
113  }

◆ set()

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.

72  {
73  if (!in_array($a_setting_name, $this->setting_names))
74  {
75  require_once './Services/Exceptions/classes/class.ilException.php';
76  throw new ilException ('No such setting on bitmask.');
77  }
78 
79  $current_value = $this->get($a_setting_name);
80  if ($current_value == $value)
81  {
82 
83  return;
84  }
85 
86  $i = 1;
87  foreach($this->setting_names as $name)
88  {
89  if ($name == $a_setting_name)
90  {
91  if ($value == true)
92  {
93  $this->bitmask = $this->bitmask | $i;
94  }
95  else
96  {
97  $this->bitmask = $this->bitmask ^ $i;
98  }
99  }
100  $i = $i * 2;
101  }
102  return;
103  }
Base class for ILIAS Exception handling.

Field Documentation

◆ $bitmask

ilBitmask::$bitmask
protected

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

Referenced by getBitmask().

◆ $setting_names

ilBitmask::$setting_names
protected

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


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