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

FPStream.C

Go to the documentation of this file.
00001 // Copyright (C) 2006, Vesta Free Software Project
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 #include "FPStream.H"
00020 
00021 FP::FPStreambuf::FPStreambuf()
00022   : total_bytes(0), tag("", 0)
00023 {
00024   setp(this->buf.bytes,
00025        this->buf.bytes +sizeof(Word));
00026 }
00027 
00028 FP::FPStreambuf::FPStreambuf(const FP::Tag &init_tag)
00029   : total_bytes(0)
00030 {
00031   this->tag = init_tag;
00032   setp(this->buf.bytes,
00033        this->buf.bytes +sizeof(Word));
00034 }
00035 
00036 void FP::FPStreambuf::flush()
00037 {
00038   unsigned int count = pptr() - this->buf.bytes;
00039   assert(count <= sizeof(Word));
00040   if(count > 0)
00041     this->tag.Extend(this->buf.bytes, count);
00042   this->total_bytes += count;
00043   setp(this->buf.bytes,
00044        this->buf.bytes +sizeof(Word));
00045 }
00046 
00047 FP::FPStreambuf::pos_type
00048 FP::FPStreambuf::seekoff(off_type offset,
00049                               seekdir way,
00050                               openmode mode)
00051 {
00052   // We don't seek
00053   this->flush();
00054   return this->total_bytes;
00055 }
00056 
00057 FP::FPStreambuf::pos_type
00058 FP::FPStreambuf::seekpos(pos_type pos, 
00059                               openmode mode)
00060 {
00061   // We don't seek
00062   this->flush();
00063   return this->total_bytes;
00064 }
00065 
00066 int FP::FPStreambuf::underflow()
00067 {
00068   // We don't do reading.
00069   return EOF;
00070 }
00071 
00072 std::streamsize FP::FPStreambuf::xsgetn(char* s, std::streamsize n)
00073 {
00074   // We don't do reading.
00075   return 0;
00076 }
00077 
00078 int FP::FPStreambuf::overflow(int c)
00079 {
00080   this->flush();
00081 
00082   // Append the byte to be written.
00083   if(c != EOF)
00084     {
00085       assert(pptr() == this->buf.bytes);
00086 
00087       *(pptr()) = (char) c;
00088       pbump(1);
00089     }
00090 
00091   // Indicate that everything is fine by returning the character
00092   // passed (converting an EOF into a non-EOF).
00093   return (c & 0x00ff);
00094 }
00095 
00096 std::streamsize FP::FPStreambuf::xsputn(const char* s, std::streamsize n)
00097 {
00098   this->flush();
00099 
00100   this->tag.Extend(s, n);
00101 
00102   total_bytes += n;
00103   
00104   return n;
00105 }

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