Ejemplo n.º 1
0
void NativeFile::set(Offset at, Byte const *values, Size count)
{
    DENG2_GUARD(this);

    QFile &out = output();
    if (at > size())
    {
        /// @throw IByteArray::OffsetError  @a at specified a position beyond the
        /// end of the file.
        throw OffsetError("NativeFile::set", "Cannot write past end of file");
    }
    out.seek(at);
    out.write(reinterpret_cast<char const *>(values), count);
    if (out.error() != QFile::NoError)
    {
        /// @throw OutputError  Failure to write to the native file.
        throw OutputError("NativeFile::set", "Error writing to file:" +
                          out.errorString());
    }
    // Update status.
    Status st = status();
    st.size = max(st.size, at + count);
    st.modifiedAt = Time();
    setStatus(st);
}
Ejemplo n.º 2
0
void FixedByteArray::set(Offset at, Byte const *values, Size count)
{
    // Increasing the size is not allowed.
    if (at + count > size())
    {
        throw OffsetError("FixedByteArray::set", "Fixed byte arrays cannot grow");
    }
    ByteSubArray::set(at, values, count);
}
Ejemplo n.º 3
0
void NativeFile::get(Offset at, Byte *values, Size count) const
{
    DENG2_GUARD(this);

    QFile &in = input();
    if(at + count > size())
    {
        /// @throw IByteArray::OffsetError  The region specified for reading extends
        /// beyond the bounds of the file.
        throw OffsetError("NativeFile::get", description() + ": cannot read past end of file " +
                          String("(%1[+%2] > %3)").arg(at).arg(count).arg(size()));
    }
    in.seek(at);
    in.read(reinterpret_cast<char *>(values), count);
}
Ejemplo n.º 4
0
void NativeFile::get(Offset at, Byte *values, Size count) const
{
    DENG2_GUARD(this);

    if (at + count > size())
    {
        d->closeInput();
        /// @throw IByteArray::OffsetError  The region specified for reading extends
        /// beyond the bounds of the file.
        throw OffsetError("NativeFile::get", description() + ": cannot read past end of file " +
                          String("(%1[+%2] > %3)").arg(at).arg(count).arg(size()));
    }
    QFile &in = input();
    if (in.pos() != qint64(at)) in.seek(qint64(at));
    in.read(reinterpret_cast<char *>(values), count);

    // Close the native input file after reaching the end of the file.
    if (in.atEnd())
    {
        d->closeInput();
    }
}