* @return $length Minimum length for one entry/block
*/
function caluclateMinimumBlockLength ();
+
+ /**
+ * Checks whether the block separator has been found
+ *
+ * @param $str String to look in
+ * @return $isFound Whether the block separator has been found
+ */
+ function isBlockSeparatorFound ($str);
}
// [EOF]
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class BaseFrameworkSystem extends stdClass implements FrameworkInterface {
+ /**
+ * Separator for header data
+ */
+ const SEPARATOR_HEADER_DATA = 0x01;
+
+ /**
+ * Separator header->entries
+ */
+ const SEPARATOR_HEADER_ENTRIES = 0x02;
+
+ /**
+ * Separator hash->name
+ */
+ const SEPARATOR_HASH_NAME = 0x03;
+
+ /**
+ * Separator entry->entry
+ */
+ const SEPARATOR_ENTRIES = 0x04;
+
/**
* Length of count
*/
*/
const LENGTH_POSITION = 20;
+ /**
+ * Length of name
+ */
+ const LENGTH_NAME = 10;
+
/**
* The real class name
*/
*
* @return $totalEntries Size of file header
*/
- protected final function getHeaderSize () {
+ public final function getHeaderSize () {
// Get it
return $this->headerSize;
}
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
+
+ /**
+ * Checks whether the block separator has been found
+ *
+ * @param $str String to look in
+ * @return $isFound Whether the block separator has been found
+ */
+ public function isBlockSeparatorFound ($str) {
+ // Determine it
+ $isFound = (strpos($str, self::getBlockSeparator()) !== FALSE);
+
+ // Return result
+ return $isFound;
+ }
+
+ /**
+ * Getter for block separator character(s)
+ *
+ * @return $blockSeparator A separator for blocks
+ */
+ protected static final function getBlockSeparator () {
+ return chr(self::SEPARATOR_ENTRIES);
+ }
}
// [EOF]
*/
const INDEX_MAGIC = 'INDEXv0.1';
- /**
- * Separator for header data
- */
- const SEPARATOR_HEADER_DATA = 0x01;
-
- /**
- * Separator header->entries
- */
- const SEPARATOR_HEADER_ENTRIES = 0x02;
-
/**
* Protected constructor
*
//* NOISY-DEBUG: */ self::createDebugInstance(__CLASS__)->debugOutput(sprintf('[%s:%d:] EXIT!', __METHOD__, __LINE__));
}
- /**
- * Calculates minimum length for one entry/block
- *
- * @return $length Minimum length for one entry/block
- */
- public function caluclateMinimumBlockLength () {
- // Calulcate it
- // @TODO Not finished yet
- $length = 0;
-
- // Return it
- return $length;
- }
-
/**
* Initializes this index
*
// Count all entries in file
$this->analyzeFile();
}
+
+ /**
+ * Calculates minimum length for one entry/block
+ *
+ * @return $length Minimum length for one entry/block
+ */
+ public function caluclateMinimumBlockLength () {
+ // Calulcate it
+ // @TODO Not finished yet
+ $length = 0;
+
+ // Return it
+ return $length;
+ }
}
// [EOF]
$this->initBackBuffer();
// Separate data
- $dataArray = explode($this->getBlockInstance()->getBlockSeparator(), $data);
+ $dataArray = explode(self::getBlockSeparator(), $data);
// Left part is the actual block, right one the back-buffer data
$this->setCurrentBlock($dataArray[0]);
// If some bytes could be read, all is fine
$isValid = ((is_string($data)) && (strlen($data) > 0));
- // Seek back to old position
- $this->seek($seekPosition);
+ // Get header size
+ $headerSize = $this->getBlockInstance()->getHeaderSize();
+
+ // Is the seek position at or beyond the header?
+ if ($seekPosition >= $headerSize) {
+ // Seek back to old position
+ $this->seek($seekPosition);
+ } else {
+ // Seek directly behind the header
+ $this->seek($headerSize);
+ }
// Return result
return $isValid;
*/
const STACK_MAGIC = 'STACKv0.1';
- /**
- * Separator for header data
- */
- const SEPARATOR_HEADER_DATA = 0x01;
-
- /**
- * Separator header->entries
- */
- const SEPARATOR_HEADER_ENTRIES = 0x02;
-
- /**
- * Separator hash->name
- */
- const SEPARATOR_HASH_NAME = 0x03;
-
- /**
- * Length of name
- */
- const LENGTH_NAME = 10;
-
/**
* Protected constructor
*
$this->setIndexInstance($indexInstance);
}
- /**
- * Calculates minimum length for one entry/block
- *
- * @return $length Minimum length for one entry/block
- */
- public function caluclateMinimumBlockLength () {
- // Calulcate it
- $length = self::getHashLength() + strlen(self::SEPARATOR_HASH_NAME) + self::LENGTH_NAME + 1;
-
- // Return it
- return $length;
- }
-
/**
* Adds a value to given stack
*
// Now, simply return the found count value, this must be up-to-date then!
return $this->getCounter();
}
+
+ /**
+ * Calculates minimum length for one entry/block
+ *
+ * @return $length Minimum length for one entry/block
+ */
+ public function caluclateMinimumBlockLength () {
+ // Calulcate it
+ $length = self::getHashLength() + strlen(chr(self::SEPARATOR_HASH_NAME)) + self::LENGTH_NAME + 1 + strlen(self::getBlockSeparator());
+
+ // Return it
+ return $length;
+ }
}
// [EOF]