casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
BaseSinkSource.h
Go to the documentation of this file.
00001 //# BaseSinkSource.h: Shared base class for ByteSink and ByteSource
00002 //# Copyright (C) 1996,1999,2001
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: BaseSinkSource.h 20551 2009-03-25 00:11:33Z Malte.Marquarding $
00027 
00028 #ifndef CASA_BASESINKSOURCE_H
00029 #define CASA_BASESINKSOURCE_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/IO/TypeIO.h>
00033 #include <casa/IO/ByteIO.h>
00034 #include <casa/Utilities/CountedPtr.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 // <summary>Shared base class for ByteSink and ByteSource.</summary>
00039 
00040 // <use visibility=export>
00041 
00042 // <prerequisite> 
00043 //    <li> <linkto class=TypeIO>TypeIO</linkto> class and derived classes
00044 // </prerequisite>
00045 
00046 // <reviewed reviewer="Friso Olnon" date="1996/11/06" tests="tByteSink" demos="">
00047 // </reviewed>
00048 
00049 // <synopsis> 
00050 // This class provides the common functionality for the classes
00051 // <linkto class=ByteSink>ByteSink</linkto> and
00052 // <linkto class=ByteSource>ByteSource</linkto>.
00053 // <p>
00054 // The object is constructed using a typed byte stream. This stream
00055 // is an instance of a class derived from class
00056 // <linkto class=TypeIO>TypeIO</linkto>. This makes it possible to
00057 // store the data in any format (e.g. CanonicalIO or RawIO).
00058 // Class <linkto class=CanonicalIO>CanonicalIO</linkto> makes it
00059 // possible to store the data in a canonical (machine-independent) format,
00060 // so it can be read on any machine and operating system. The canonical
00061 // format is big-endian IEEE, where a (unsigned) long is stored as 8 bytes.
00062 // This means that on common 32-bit big-endian machines like SUN and HP
00063 // only longs have to be converted and that CanonicalIO is as fast as RawIO.
00064 // Class <linkto class=RawIO>RawIO</linkto> stores the data in native
00065 // format, so the IO-process is faster on especially little-endian
00066 // machines (PC, DEC-alpha). Note that RawIO can also be used to read
00067 // bytes and interprete or convert them thereafter (e.g. using the
00068 // conversion functions in the <linkto class=Conversion>Conversion</linkto>
00069 // Conversion framework.
00070 // <p>
00071 // In its turn TypeIO uses an instance of a class derived from class
00072 // <linkto class=ByteIO>ByteIO</linkto>. This makes it possible to
00073 // use any output stream (e.g. file, memory).
00074 // </synopsis>
00075 
00076 // <motivation> 
00077 // The design of the ByteSink and ByteSource classes resembles the design of 
00078 // the iostream classes in the standard library. A shared base class is needed
00079 // to allow multiple inheritance needed for class ByteSinkSource.
00080 // </motivation>
00081 
00082 
00083 class BaseSinkSource
00084 {
00085 public: 
00086     // This functions returns a reference to itsTypeIO.
00087     // <group>
00088     TypeIO& typeIO();
00089     const TypeIO& typeIO() const;
00090     // </group>
00091 
00092     // This function sets the position on the given offset.
00093     // The seek option defines from which position the seek is done.
00094     // <group>
00095     Int64 seek (Int64 offset, ByteIO::SeekOption = ByteIO::Begin);
00096     Int64 seek (Int offset, ByteIO::SeekOption = ByteIO::Begin);
00097     // </group>
00098 
00099     // Is the SinkSource readable?
00100     Bool isReadable() const;
00101 
00102     // Is the SinkSource writable?
00103     Bool isWritable() const;
00104 
00105     // Is the SinkSource seekable?
00106     Bool isSeekable() const;
00107 
00108     // Is the BaseSinkSource unusable? 
00109     Bool isNull() const;
00110 
00111 protected:
00112     BaseSinkSource();
00113 
00114     // Construct using the given TypeIO. If takeOver is true the this class
00115     // will delete the supplied pointer. Otherwise the caller is responsible
00116     // for this.
00117     BaseSinkSource (TypeIO* typeIO, Bool takeOver=False);
00118 
00119     // The copy constructor uses reference semantics
00120     BaseSinkSource (const BaseSinkSource& BaseSinkSource);
00121 
00122     // The assignment operator uses reference semantics
00123     BaseSinkSource& operator= (const BaseSinkSource& BaseSinkSource);
00124 
00125     virtual ~BaseSinkSource();
00126 
00127 
00128     // This variable keeps a pointer to a TypeIO.
00129     CountedPtr<TypeIO> itsTypeIO;
00130 };
00131 
00132 
00133 
00134 } //# NAMESPACE CASA - END
00135 
00136 #endif