. */ namespace GnuBoat\Nmea; require_once(__DIR__ ."/../../autoloader.php"); /** * @brief Use this class to parse a single NMEA sentence (parseSentence()) or a complete file (parseFile()) * */ class Parser { function __construct($debug = 0) { $this->_debug = $debug; $this->_formats = array(); if(canClassBeLoaded("GnuBoat\Nmea\Nmea0183\Parser")) $this->_formats["0183"] = "GnuBoat\Nmea\Nmea0183\Parser"; } public function formatsSupported() { return array_keys($this->_formats); } /** * @brief Returns an array of NmeaSentence objects, specialized for the type of sentence */ function parseFile($file, $format) { return call_user_func(array(new $this->_formats[$format], "parseFile"), $file, $this->_debug); } /** * @brief Returns an NmeaSentence object, specialized for the type of sentence */ function parseSentence($sentence, $format) { if(!array_key_exists($format, $this->_formats)){ $message = "No handler for requested format ". $format ." found\n"; error_log($message); if($this->_debug > 0) print $message; return null; } if(empty($sentence)){ $message = "Empty sentence\n"; error_log($message); if($this->_debug > 0) print $message; return null; } return call_user_func(array(new $this->_formats[$format], "parseSentence"), $sentence, $this->_debug); } private $_formats; private $_debug; } ?>