namespace libgpx;
+use \ArrayAccess;
+use \Countable;
use \DomainException;
+use \IteratorAggregate;
/**
* The GPX route type.
*
* @author Andy Street <andy@street.me.uk>
*/
-class Route extends DataType implements Geographic
+class Route extends DataType
+ implements Geographic, ArrayAccess, Countable, IteratorAggregate
{
/**
return $length;
}
+ /**
+ * Check if an offset holds a value.
+ *
+ * @see ArrayAccess::offsetExists
+ *
+ * @param mixed $offset The offset to search
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return $this->getPoints()->offsetExists($offset);
+ }
+
+ /**
+ * Fetch a point from this route.
+ *
+ * @see ArrayAccess::offsetGet
+ *
+ * @param mixed $offset The offset to retrieve
+ * @return Point
+ */
+ public function offsetGet($offset)
+ {
+ return $this->getPoints()->offsetGet($offset);
+ }
+
+ /**
+ * Set the point at an offset.
+ *
+ * @see ArrayAccess::offsetSet
+ *
+ * @param mixed $offset Where to store the point.
+ * @param Point $value The point to store.
+ * @return void
+ */
+ public function offsetSet($offset, $value)
+ {
+ return $this->getPoints()->offsetSet($offset, $value);
+ }
+
+ /**
+ * Remove a point.
+ *
+ * @see ArrayAccess::offsetUnset
+ *
+ * @param mixed $offset Which point to remove
+ * @return void
+ */
+ public function offsetUnset($offset)
+ {
+ return $this->getPoints()->offsetUnset($offset);
+ }
+
+ /**
+ * Count the number of points in this route.
+ *
+ * @return int
+ */
+ public function count()
+ {
+ return ($this->points === null ? 0 : $this->points->count());
+ }
+
+ /**
+ * Fetch an iterator for the points contained in this route.
+ *
+ * @return \Iterator
+ */
+ public function getIterator() {
+ return $this->getPoints();
+ }
+
}
namespace libgpx;
+use \ArrayAccess;
+use \Countable;
use \DomainException;
+use \IteratorAggregate;
/**
* A GPX trk type.
*
* @author Andy Street <andy@street.me.uk>
*/
-class Track extends DataType implements Geographic
+class Track extends DataType
+ implements Geographic, ArrayAccess, Countable, IteratorAggregate
{
/**
$this->number = $number;
}
+ /**
+ * Count the number of track points.
+ *
+ * @return The number of track points contained in all the segments of this
+ * track.
+ */
+ public function countTrackPoints()
+ {
+ $count = 0;
+ if ($this->segments !== null) {
+ foreach ($this->segments as $segment) {
+ $count += count($segment);
+ }
+ }
+ return $count;
+ }
+
/**
* Fetch an ordered list of track segments.
*
return $length;
}
+ /**
+ * Check if an offset holds a value.
+ *
+ * @see ArrayAccess::offsetExists
+ *
+ * @param mixed $offset The offset to search
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return $this->getSegments()->offsetExists($offset);
+ }
+
+ /**
+ * Fetch a segment from this track.
+ *
+ * @see ArrayAccess::offsetGet
+ *
+ * @param mixed $offset The offset to retrieve
+ * @return TrackSegment
+ */
+ public function offsetGet($offset)
+ {
+ return $this->getSegments()->offsetGet($offset);
+ }
+
+ /**
+ * Set the segment at an offset.
+ *
+ * @see ArrayAccess::offsetSet
+ *
+ * @param mixed $offset Where to store the segment.
+ * @param TrackSegment $value The segment to store.
+ * @return void
+ */
+ public function offsetSet($offset, $value)
+ {
+ return $this->getSegments()->offsetSet($offset, $value);
+ }
+
+ /**
+ * Remove a segment.
+ *
+ * @see ArrayAccess::offsetUnset
+ *
+ * @param mixed $offset Which segment to remove
+ * @return void
+ */
+ public function offsetUnset($offset)
+ {
+ return $this->getSegments()->offsetUnset($offset);
+ }
+
+ /**
+ * Count the number of segments in this track.
+ *
+ * @return int
+ */
+ public function count()
+ {
+ return ($this->segments === null ? 0 : $this->segments->count());
+ }
+
+ /**
+ * Fetch an iterator for the segments contained in this track.
+ *
+ * @return \Iterator
+ */
+ public function getIterator() {
+ return $this->getSegments();
+ }
+
}
namespace libgpx;
+use \ArrayAccess;
+use \Countable;
+use \IteratorAggregate;
+
/**
* A GPX trkseg type.
*
* @author Andy Street <andy@street.me.uk>
*/
-class TrackSegment implements Geographic
+class TrackSegment
+ implements Geographic, ArrayAccess, Countable, IteratorAggregate
{
/**
return $length;
}
+ /**
+ * Check if an offset holds a value.
+ *
+ * @see ArrayAccess::offsetExists
+ *
+ * @param mixed $offset The offset to search
+ * @return boolean
+ */
+ public function offsetExists($offset)
+ {
+ return $this->getPoints()->offsetExists($offset);
+ }
+
+ /**
+ * Fetch a point from this segment.
+ *
+ * @see ArrayAccess::offsetGet
+ *
+ * @param mixed $offset The offset to retrieve
+ * @return Point
+ */
+ public function offsetGet($offset)
+ {
+ return $this->getPoints()->offsetGet($offset);
+ }
+
+ /**
+ * Set the point at an offset.
+ *
+ * @see ArrayAccess::offsetSet
+ *
+ * @param mixed $offset Where to store the point.
+ * @param Point $value The point to store.
+ * @return void
+ */
+ public function offsetSet($offset, $value)
+ {
+ return $this->getPoints()->offsetSet($offset, $value);
+ }
+
+ /**
+ * Remove a point.
+ *
+ * @see ArrayAccess::offsetUnset
+ *
+ * @param mixed $offset Which point to remove
+ * @return void
+ */
+ public function offsetUnset($offset)
+ {
+ return $this->getPoints()->offsetUnset($offset);
+ }
+
+ /**
+ * Count the number of points in this track segment.
+ *
+ * @return int
+ */
+ public function count()
+ {
+ return ($this->points === null ? 0 : $this->points->count());
+ }
+
+ /**
+ * Fetch an iterator for the points contained in this segment.
+ *
+ * @return \Iterator
+ */
+ public function getIterator() {
+ return $this->getPoints();
+ }
+
}