SplObjectStorage Class Reference

Object storage. More...

Inheritance diagram for SplObjectStorage:

Inheritance graph
{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}{Countable\n||+ count()\l}
[legend]
Collaboration diagram for SplObjectStorage:

Collaboration graph
{Iterator\n||+ current()\l+ key()\l+ next()\l+ rewind()\l+ valid()\l}{Traversable\n||}{Countable\n||+ count()\l}
[legend]
List of all members.

Public Member Functions

 attach ($obj)
 contains ($obj)
 count ()
 current ()
 detach ($obj)
 key ()
 next ()
 rewind ()
 valid ()

Private Attributes

 $index = 0
 $storage = array()

Detailed Description

Object storage.

Author:
Marcus Boerger
Version:
1.0
Since:
PHP 6.0
This container allows to store objects uniquly without the need to compare them one by one. This is only possible internally. The code represenation here therefore has a complexity of O(n) while the actual implementation has complexity O(1).

Definition at line 23 of file splobjectstorage.inc.


Member Function Documentation

SplObjectStorage::attach ( obj  ) 

Parameters:
$obj new object to attach to storage if not yet contained

Definition at line 91 of file splobjectstorage.inc.

References contains().

00092     {
00093         if (is_object($obj) && !$this->contains($obj))
00094         {
00095             $this->storage[] = $obj;
00096         }
00097     }

Here is the call graph for this function:

SplObjectStorage::contains

SplObjectStorage::contains ( obj  ) 

Parameters:
obj object to look for

Returns:
whether $obj is contained in storage

Definition at line 74 of file splobjectstorage.inc.

Referenced by attach().

00075     {
00076         if (is_object($obj))
00077         {
00078             foreach($this->storage as $object)
00079             {
00080                 if ($object === $obj)
00081                 {
00082                     return true;
00083                 }
00084             }
00085         }
00086         return false;
00087     }

SplObjectStorage::count (  ) 

Returns:
number of objects in storage

Implements Countable.

Definition at line 66 of file splobjectstorage.inc.

00067     {
00068         return count($this->storage);
00069     }

SplObjectStorage::current (  ) 

Returns:
current object

Implements Iterator.

Definition at line 51 of file splobjectstorage.inc.

00052     {
00053         return current($this->storage);
00054     }

SplObjectStorage::detach ( obj  ) 

Parameters:
$obj object to remove from storage

Definition at line 101 of file splobjectstorage.inc.

References rewind().

00102     {
00103         if (is_object($obj))
00104         {
00105             foreach($this->storage as $idx => $object)
00106             {
00107                 if ($object === $obj)
00108                 {
00109                     unset($this->storage[$idx]);
00110                     $this->rewind();
00111                     return;
00112                 }
00113             }
00114         }
00115     }

Here is the call graph for this function:

SplObjectStorage::rewind

SplObjectStorage::key (  ) 

Returns:
current key

Implements Iterator.

Definition at line 44 of file splobjectstorage.inc.

Referenced by valid().

00045     {
00046         return $this->index;
00047     }

SplObjectStorage::next (  ) 

Forward to next element.

Implements Iterator.

Definition at line 58 of file splobjectstorage.inc.

00059     {
00060         next($this->storage);
00061         $this->index++;
00062     }

SplObjectStorage::rewind (  ) 

Rewind to top iterator as set in constructor.

Implements Iterator.

Definition at line 30 of file splobjectstorage.inc.

Referenced by detach().

00031     {
00032         rewind($this->storage);
00033     }

SplObjectStorage::valid (  ) 

Returns:
whether iterator is valid

Implements Iterator.

Definition at line 37 of file splobjectstorage.inc.

References key().

00038     {
00039         return key($this->storage) !== false;
00040     }

Here is the call graph for this function:

SplObjectStorage::key


Member Data Documentation

SplObjectStorage::$index = 0 [private]

Definition at line 26 of file splobjectstorage.inc.

SplObjectStorage::$storage = array() [private]

Definition at line 25 of file splobjectstorage.inc.


The documentation for this class was generated from the following file:
Generated on Thu Apr 26 01:07:52 2007 for SPL-StandardPHPLibrary by  doxygen 1.5.2