Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TextIO.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 // 
00003 // This file is part of Vesta.
00004 // 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 // 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Created on Mon Mar 30 09:59:04 PST 1998 by heydon
00020 
00021 #include <Basics.H>
00022 #include <FS.H>
00023 #include <VestaLog.H>
00024 #include <Recovery.H>
00025 #include "TextIO.H"
00026 
00027 using std::ostream;
00028 using std::istream;
00029 using std::streamoff;
00030 using std::ios;
00031 
00032 void TextIO::Log(VestaLog &log, const Text &t)
00033   throw (VestaLog::Error)
00034 {
00035   unsigned long len = t.Length();
00036   Basics::uint16 len_short = (Basics::uint16) len;
00037   // Check for 16-bit integer overflow
00038   assert(((unsigned long) len_short) == len);
00039   log.write((char *)(&len_short), sizeof(len_short));
00040   log.write(t.chars(), len);
00041 }
00042 
00043 void TextIO::Recover(RecoveryReader &rd, /*OUT*/ Text &t)
00044   throw (VestaLog::Error, VestaLog::Eof)
00045 {
00046     Basics::uint16 len;
00047     rd.readAll((char *)(&len), sizeof(len));
00048     char *buff = NEW_PTRFREE_ARRAY(char, len+1);
00049     rd.readAll(buff, len);
00050     buff[len] = '\0';
00051     t.Init((const char *) buff);
00052 }
00053 
00054 void TextIO::Write(ostream &ofs, const Text &t)
00055   throw (FS::Failure)
00056 {
00057   unsigned long len = t.Length();
00058   Basics::uint16 len_short = (Basics::uint16) len;
00059   // Check for 16-bit integer overflow
00060   assert(((unsigned long) len_short) == len);
00061   FS::Write(ofs, (char *)(&len_short), sizeof(len_short));
00062   FS::Write(ofs, t.chars(), len);
00063 }
00064 
00065 void TextIO::Read(istream &ifs, /*OUT*/ Text &t)
00066   throw (FS::Failure, FS::EndOfFile)
00067 {
00068     Basics::uint16 len;
00069     FS::Read(ifs, (char *)(&len), sizeof(len));
00070     char *buff = NEW_PTRFREE_ARRAY(char, len+1);
00071     FS::Read(ifs, buff, len);
00072     buff[len] = '\0';
00073     t.Init((const char *) buff);
00074 }
00075 
00076 int TextIO::Skip(istream &ifs) throw (FS::Failure, FS::EndOfFile)
00077 {
00078     Basics::uint16 len;
00079     FS::Read(ifs, (char *)(&len), sizeof(len)); // read length
00080     FS::Seek(ifs, (streamoff)len, ios::cur);    // skip "len" bytes
00081     return sizeof(len) + len;
00082 }

Generated on Mon May 8 00:48:33 2006 for Vesta by  doxygen 1.4.2