*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
// Last character must be the separator
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] data(-1)=%s', __METHOD__, __LINE__, dechex(ord(substr($data, -1, 1)))));
- assert(substr($data, -1, 1) == chr(BaseFile::SEPARATOR_HEADER_ENTRIES));
+ assert(substr($data, -1, 1) == chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES));
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Okay, then remove it
$data = substr($data, 0, -1);
// And update seek position
- $this->updateSeekPosition();
+ $this->getIteratorInstance()->updateSeekPosition();
/*
* Now split it:
* 1 => total entries
* 2 => current seek position
*/
- $header = explode(chr(BaseFile::SEPARATOR_HEADER_DATA), $data);
+ $header = explode(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA), $data);
// Set header here
- $this->setHeader($header);
+ $this->getIteratorInstance()->setHeader($header);
// Check if the array has only 3 elements
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] header(%d)=%s', __METHOD__, __LINE__, count($header), print_r($header, TRUE)));
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Check length of count and seek position
- assert(strlen($header[1]) == BaseFile::LENGTH_COUNT);
+ assert(strlen($header[1]) == BaseBinaryFile::LENGTH_COUNT);
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
- assert(strlen($header[2]) == BaseFile::LENGTH_POSITION);
+ assert(strlen($header[2]) == BaseBinaryFile::LENGTH_POSITION);
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] Passed assert().', __METHOD__, __LINE__));
// Decode count and seek position
self::STACK_MAGIC,
// Separator magic<->count
- chr(BaseFile::SEPARATOR_HEADER_DATA),
+ chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
// Total entries (will be zero) and pad it to 20 chars
- str_pad($this->dec2hex($this->getCounter()), BaseFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
+ str_pad($this->dec2hex($this->getIteratorInstance()->getCounter()), BaseBinaryFile::LENGTH_COUNT, '0', STR_PAD_LEFT),
// Separator count<->seek position
- chr(BaseFile::SEPARATOR_HEADER_DATA),
+ chr(BaseBinaryFile::SEPARATOR_HEADER_DATA),
// Position (will be zero)
- str_pad($this->dec2hex($this->getSeekPosition(), 2), BaseFile::LENGTH_POSITION, '0', STR_PAD_LEFT),
+ str_pad($this->dec2hex($this->getIteratorInstance()->getSeekPosition(), 2), BaseBinaryFile::LENGTH_POSITION, '0', STR_PAD_LEFT),
// Separator position<->entries
- chr(BaseFile::SEPARATOR_HEADER_ENTRIES)
+ chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES)
);
// Write it to disk (header is always at seek position 0)
- $this->writeData(0, $header, FALSE);
+ $this->getIteratorInstance()->writeData(0, $header, FALSE);
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
// Calculate header size
$this->getIteratorInstance()->setHeaderSize(
strlen(self::STACK_MAGIC) +
- strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
- BaseFile::LENGTH_COUNT +
- strlen(chr(BaseFile::SEPARATOR_HEADER_DATA)) +
- BaseFile::LENGTH_POSITION +
- strlen(chr(BaseFile::SEPARATOR_HEADER_ENTRIES))
+ strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
+ BaseBinaryFile::LENGTH_COUNT +
+ strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_DATA)) +
+ BaseBinaryFile::LENGTH_POSITION +
+ strlen(chr(BaseBinaryFile::SEPARATOR_HEADER_ENTRIES))
);
// Init counters and gaps array
*/
public function getStackCount ($stackerName) {
// Now, simply return the found count value, this must be up-to-date then!
- return $this->getCounter();
+ return $this->getIteratorInstance()->getCounter();
}
/**
*/
public function calculateMinimumBlockLength () {
// Calulcate it
- $length = self::getHashLength() + strlen(chr(BaseFile::SEPARATOR_HASH_NAME)) + BaseFile::LENGTH_NAME + 1 + strlen(chr(BaseFile::SEPARATOR_ENTRIES));
+ $length = self::getHashLength() + strlen(chr(BaseBinaryFile::SEPARATOR_HASH_NAME)) + BaseBinaryFile::LENGTH_NAME + 1 + strlen(chr(BaseBinaryFile::SEPARATOR_ENTRIES));
// Return it
return $length;
}
+
+ /**
+ * Initializes counter for valid entries, arrays for damaged entries and
+ * an array for gap seek positions. If you call this method on your own,
+ * please re-analyze the file structure. So you are better to call
+ * analyzeFile() instead of this method.
+ *
+ * @return void
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public function initCountersGapsArray () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for header size
+ *
+ * @return $totalEntries Size of file header
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public final function getHeaderSize () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for header size
+ *
+ * @param $headerSize Size of file header
+ * @return void
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public final function setHeaderSize ($headerSize) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for header array
+ *
+ * @return $totalEntries Size of file header
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public final function getHeader () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Setter for header
+ *
+ * @param $header Array for a file header
+ * @return void
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public final function setHeader (array $header) {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Updates seekPosition attribute from file to avoid to much access on file.
+ *
+ * @return void
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public function updateSeekPosition () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * Getter for total entries
+ *
+ * @return $totalEntries Total entries in this file
+ * @throws UnsupportedOperationException This method is not (and maybe never will be) supported
+ */
+ public final function getCounter () {
+ throw new UnsupportedOperationException(array($this, __FUNCTION__, $this->getIteratorInstance()->getPointerInstance()), self::EXCEPTION_UNSPPORTED_OPERATION);
+ }
+
+ /**
+ * "Getter" for file size
+ *
+ * @return $fileSize Size of currently loaded file
+ */
+ public function getFileSize () {
+ // Call iterator's method
+ return $this->getIteratorInstance()->getFileSize();
+ }
}
// [EOF]