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

ExternalReadStream.cc

Go to the documentation of this file.
00001 /*
00002  * ExternalReadStream.cc
00003  *
00004  * Smalltalk like class library for C++
00005  * External read stream.
00006  *
00007  * Copyright (c) 2003 Milan Cermak
00008  */
00009 /*
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  */
00024 #include <stlib/ExternalReadStream.h>
00025 #include <stlib/Character.h>
00026 #include <stlib/IOBuffer.h>
00027 #include <stlib/LineEndConvention.h>
00028 #include <stlib/SequenceableCollection.h>
00029 #include <stlib/String.h>
00030 
00031 ExternalReadStream::ExternalReadStream(IOAccessor *accessor)
00032   : ExternalStream(accessor)
00033 {
00034     /* Does nothing */
00035 }
00036 
00037 /* Class-accessing protocol */
00038 String *ExternalReadStream::className(void) const
00039 {
00040     return new String("ExternalReadStream");
00041 }
00042 
00043 /* Accessing protocol */
00044 void ExternalReadStream::flush(void)
00045 {
00046     /* Does nothing */
00047 }
00048 
00049 Object *ExternalReadStream::next(void)
00050 {
00051     Object *ch;
00052 
00053     if (_position >= read_limit) {
00054         ch = pastEnd();
00055         if (ch == nil) return nil;
00056     } else {
00057         ch = collection->at(_position++);
00058     }
00059     return ch;
00060 }
00061 
00062 void ExternalReadStream::nextPut(Object *object)
00063 {
00064     shouldNotImplement(new String(__PRETTY_FUNCTION__));
00065 }
00066 
00067 /* Positioning protocol */
00068 void ExternalReadStream::skip(long n)
00069 {
00070     long pos;
00071 
00072     pos = _position + n;
00073     if (pos >= 0 && pos <= read_limit)
00074         _position = pos;
00075     else {
00076         if (io_buffer->isSeekable())
00077             setPosition(readPosition() + n);
00078         else {
00079             if (n > 0) next(n);
00080             else {
00081                 /* Cannot move back on unseekable stream.
00082                    May raise an exception here.
00083                  */
00084             }
00085         }
00086     }
00087 }
00088 
00089 /* Testing protocol */
00090 bool ExternalReadStream::isReadable(void)
00091 {
00092     return true;
00093 }
00094 
00095 bool ExternalReadStream::isWritable(void)
00096 {
00097     return false;
00098 }

Generated on Mon Nov 27 09:47:55 2006 for Smalltalk like C++ Class Library by  doxygen 1.4.2