diogenes.flagset.inc.php

00001 <?php
00002 /*
00003  * Copyright (C) 2003-2004 Polytechnique.org
00004  * http://opensource.polytechnique.org/
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 
00024 class flagset {
00026   var $value;
00027 
00029   var $sep = ",";
00030 
00031 
00036   function flagset( $flags="" ) {
00037     $this->value = $flags;
00038   }
00039 
00040 
00045   function addflag($flag) {
00046     if (!$flag) return;
00047     if (!$this->hasflag($flag)) {
00048       if ($this->value)
00049         $this->value .= $this->sep;
00050       $this->value .= $flag;
00051     }
00052   }
00053 
00054   
00059   function as_array()
00060   {
00061     if ($this->value) {
00062       $arr = explode($this->sep, $this->value);
00063     } else {
00064       $arr = array();
00065     } 
00066     return $arr;
00067   }
00068   
00069   
00074   function hasflag($flag) {
00075     $tok = strtok($this->value,$this->sep);
00076     while ($tok) {
00077       if ($tok==$flag) return 1;
00078       $tok = strtok($this->sep);
00079     }
00080     return 0;
00081   }
00082 
00083 
00088   function rmflag($flag) {
00089     if (!$flag) return;
00090     $newvalue = "";
00091     $tok = strtok($this->value,$this->sep);
00092     while ($tok) {
00093       if ($tok!=$flag) {
00094         if ($newvalue)
00095          $newvalue .= $this->sep;
00096         $newvalue .= $tok;
00097       }
00098       $tok = strtok($this->sep);
00099     }
00100     $this->value=$newvalue;
00101   }
00102 
00103 } 
00104 
00105 ?>

Generated on Fri Jan 11 01:20:08 2008 for Diogenes by  doxygen 1.5.1