Vault  4.1
viostream.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright c1997-2014 Trygve Isaacson. All rights reserved.
00003 This file is part of the Code Vault version 4.1
00004 http://www.bombaydigital.com/
00005 License: MIT. See LICENSE.md in the Vault top level directory.
00006 */
00007 
00010 #include "vexception.h"
00011 #include "viostream.h"
00012 #include "vstream.h"
00013 
00014 VIOStream::VIOStream(VStream& rawStream)
00015     : mRawStream(rawStream)
00016     {
00017 }
00018 
00019 void VIOStream::readGuaranteed(Vu8* targetBuffer, Vs64 numBytesToRead) {
00020     mRawStream.readGuaranteed(targetBuffer, numBytesToRead);
00021 }
00022 
00023 Vu8 VIOStream::readGuaranteedByte() {
00024     return mRawStream.readGuaranteedByte();
00025 }
00026 
00027 Vs64 VIOStream::read(Vu8* targetBuffer, Vs64 numBytesToRead) {
00028     return mRawStream.read(targetBuffer, numBytesToRead);
00029 }
00030 
00031 Vs64 VIOStream::write(const Vu8* buffer, Vs64 numBytesToWrite) {
00032     return mRawStream.write(buffer, numBytesToWrite);
00033 }
00034 
00035 void VIOStream::flush() {
00036     mRawStream.flush();
00037 }
00038 
00039 bool VIOStream::skip(Vs64 numBytesToSkip) {
00040     return mRawStream.skip(numBytesToSkip);
00041 }
00042 
00043 bool VIOStream::seek(Vs64 offset, int whence) {
00044     return mRawStream.seek(offset, whence);
00045 }
00046 
00047 bool VIOStream::seek0() {
00048     return mRawStream.seek0();
00049 }
00050 
00051 Vs64 VIOStream::getIOOffset() const {
00052     return mRawStream.getIOOffset();
00053 }
00054 
00055 Vs64 VIOStream::available() const {
00056     return mRawStream.available();
00057 }
00058 
00059 VStream& VIOStream::getRawStream() {
00060     return mRawStream;
00061 }
00062 
00063 // static
00064 Vs16 VIOStream::streamCompare(VIOStream& streamA, VIOStream& streamB, Vs64 numBytesToCompare) {
00065     Vs64 offsetA = streamA.getIOOffset();
00066     Vs64 offsetB = streamB.getIOOffset();
00067 
00068     Vs16 compareResult = 0;        // Assume equal until we know better
00069     while (numBytesToCompare-- > 0) {
00070         Vu8 byteA = 0, byteB = 0;
00071         bool aEnded = false, bEnded = false;
00072 
00073         try {
00074             streamA.read(&byteA, CONST_S64(1));
00075         } catch (const VEOFException& /*ex*/) {
00076             aEnded = true;
00077         }
00078 
00079         try {
00080             streamB.read(&byteB, CONST_S64(1));
00081         } catch (const VEOFException& /*ex*/) {
00082             bEnded = true;
00083         }
00084 
00085         if (aEnded && bEnded) {
00086             break;
00087         } else if (aEnded) {
00088             compareResult = -1;
00089             break;
00090         } else if (bEnded) {
00091             compareResult = 1;
00092             break;
00093         }
00094 
00095         if (byteA < byteB) {
00096             compareResult = -1;
00097             break;
00098         } else if (byteA > byteB) {
00099             compareResult = 1;
00100             break;
00101         }
00102     }
00103 
00104     streamA.seek(offsetA, SEEK_SET);
00105     streamB.seek(offsetB, SEEK_SET);
00106 
00107     return compareResult;
00108 }

Copyright ©1997-2014 Trygve Isaacson. All rights reserved. This documentation was generated with Doxygen.