ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBitmask.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 class ilBitmask
16 {
18  protected $setting_names;
19 
21  protected $bitmask;
22 
31  public function __construct($a_setting_names, $a_bitmask)
32  {
33  $this->setting_names = $a_setting_names;
34  $this->bitmask = $a_bitmask;
35  return;
36  }
37 
46  public function get($a_setting_name)
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  }
61 
71  public function set($a_setting_name, $value)
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  }
104 
110  public function getBitmask()
111  {
112  return $this->bitmask;
113  }
114 }