*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 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
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-class BaseBinaryFile extends BaseFile {
+class BaseBinaryFile extends BaseAbstractFile {
/**
* Separator for header data
*/
const SEPARATOR_HEADER_ENTRIES = 0x02;
/**
- * Separator hash->name
+ * Separator group->hash
*/
- const SEPARATOR_HASH_NAME = 0x03;
+ const SEPARATOR_GROUP_HASH = 0x03;
+
+ /**
+ * Separator hash->value
+ */
+ const SEPARATOR_HASH_VALUE = 0x04;
/**
* Separator entry->entry
*/
- const SEPARATOR_ENTRIES = 0x04;
+ const SEPARATOR_ENTRIES = 0x05;
/**
* Separator type->position
*/
- const SEPARATOR_TYPE_POSITION = 0x05;
+ const SEPARATOR_TYPE_POSITION = 0x06;
/**
* Length of count
const LENGTH_POSITION = 20;
/**
- * Length of name
+ * Length of group
*/
- const LENGTH_NAME = 10;
+ const LENGTH_GROUP = 10;
/**
* Maximum length of entry type
// ... to write it back into the file
$this->flushFileHeader();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
/**
// Seek to currently ("old") saved position
$this->seek($this->getSeekPosition());
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
/**
* @return void
*/
public function writeData ($seekPosition, $data, $flushHeader = TRUE) {
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%s - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] seekPosition=%s,data()=%d - CALLED!', __METHOD__, __LINE__, $seekPosition, strlen($data)));
// Write data at given position
$this->getPointerInstance()->writeAtPosition($seekPosition, $data);
+ // Increment counter
+ $this->incrementCounter();
+
// Update seek position
$this->updateSeekPosition();
// Rewind seek position (to beginning of file) and update/flush file header
$this->rewindUpdateSeekPosition();
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!!', __METHOD__, __LINE__));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
/**
* @param $bytes Amount of bytes to read
* @return $data Data read from file
*/
- public function read ($bytes) {
+ public function read ($bytes = NULL) {
+ // $bytes shall be integer
+ assert(is_int($bytes));
+
// Call pointer instance
return $this->getPointerInstance()->read($bytes);
}
/**
* Rewinds to the beginning of the file
*
- * @return $status Status of this operation
+ * @return $status Status of this operation
*/
public function rewind () {
// Call pointer instance
} // END - if
// Debug message
- /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current()=%s', __METHOD__, __LINE__, strlen($current)));
+ /* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] current()=%d', __METHOD__, __LINE__, strlen($current)));
} // END - while
// If the last read block is empty, check gaps
} // END - if
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] key()=%s', __FUNCTION__, __LINE__, $this->key()));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] key()=%d', __FUNCTION__, __LINE__, $this->key()));
// Make sure the block instance is set
assert($this->getBlockInstance() instanceof CalculatableBlock);
$block = $this->read($length);
// Debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] block()=%s,length=%s', __FUNCTION__, __LINE__, strlen($block), $length));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] block()=%d,length=%s', __FUNCTION__, __LINE__, strlen($block), $length));
// Is it all empty?
if (strlen(trim($block)) == 0) {
$data .= $block;
// A debug message
- //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] data()=%s', __FUNCTION__, __LINE__, strlen($data)));
+ //* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d] data()=%d', __FUNCTION__, __LINE__, strlen($data)));
} // END - while
// EOF reached?
// Call block instance
$this->getBlockInstance()->flushFileHeader();
}
+
+ /**
+ * Searches for next suitable gap the given length of data can fit in
+ * including padding bytes.
+ *
+ * @param $length Length of raw data
+ * @return $seekPosition Found next gap's seek position
+ */
+ public function searchNextGap ($length) {
+ // If the file is only gaps, no need to seek
+ if ($this->isFileOnlyGaps()) {
+ // The first empty block is the first one right after the header
+ return ($this->getHeaderSize() + 1);
+ } // END - if
+
+ // @TODO Unfinished
+ $this->partialStub('length=' . $length);
+ }
}
// [EOF]