Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

IReader.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file IReader.d
00004         
00005         Copyright (c) 2004 Kris Bell
00006         
00007         This software is provided 'as-is', without any express or implied
00008         warranty. In no event will the authors be held liable for damages
00009         of any kind arising from the use of this software.
00010         
00011         Permission is hereby granted to anyone to use this software for any 
00012         purpose, including commercial applications, and to alter it and/or 
00013         redistribute it freely, subject to the following restrictions:
00014         
00015         1. The origin of this software must not be misrepresented; you must 
00016            not claim that you wrote the original software. If you use this 
00017            software in a product, an acknowledgment within documentation of 
00018            said product would be appreciated but is not required.
00019 
00020         2. Altered source versions must be plainly marked as such, and must 
00021            not be misrepresented as being the original software.
00022 
00023         3. This notice may not be removed or altered from any distribution
00024            of the source.
00025 
00026         4. Derivative works are permitted, but they must carry this notice
00027            in full and credit the original source.
00028 
00029 
00030                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00031 
00032 
00033         @version        Initial version, March 2004     
00034          
00035         @author         Kris
00036         @author         Ivan Senji (the "alias get" idea)
00037 
00038 
00039 *******************************************************************************/
00040 
00041 module mango.io.model.IReader;
00042 
00043 public import mango.io.model.IBuffer;
00044 
00045 /*******************************************************************************
00046 
00047         Any class implementing IReadable becomes part of the Reader framework
00048         
00049 *******************************************************************************/
00050 
00051 interface IReadable
00052 {
00053         abstract void read (IReader input);
00054 }
00055 
00056 /*******************************************************************************
00057 
00058 *******************************************************************************/
00059 
00060 interface IArrayAllocator
00061 {
00062         abstract void reset ();
00063 
00064         abstract void bind (IReader input);
00065 
00066         abstract bool isMutable (void* x);
00067 
00068         abstract void allocate  (void[]* x, uint size, uint width, uint type, IBuffer.Converter convert);
00069 }
00070 
00071 /*******************************************************************************
00072 
00073         All reader instances should implement this interface.
00074 
00075 *******************************************************************************/
00076 
00077 abstract class IReader   // could be an interface, but that causes poor codegen
00078 {
00079         alias get opShr;
00080         alias get opCall;
00081 
00082         /***********************************************************************
00083         
00084                 These are the basic reader methods
00085 
00086         ***********************************************************************/
00087 
00088         abstract IReader get (inout bool x);
00089         abstract IReader get (inout byte x);
00090         abstract IReader get (inout ubyte x);
00091         abstract IReader get (inout short x);
00092         abstract IReader get (inout ushort x);
00093         abstract IReader get (inout int x);
00094         abstract IReader get (inout uint x);
00095         abstract IReader get (inout long x);
00096         abstract IReader get (inout ulong x);
00097         abstract IReader get (inout float x);
00098         abstract IReader get (inout double x);
00099         abstract IReader get (inout real x);
00100         abstract IReader get (inout char x);
00101         abstract IReader get (inout wchar x);
00102         abstract IReader get (inout dchar x);
00103 
00104         abstract IReader get (inout byte[] x,   uint elements = uint.max);
00105         abstract IReader get (inout short[] x,  uint elements = uint.max);
00106         abstract IReader get (inout int[] x,    uint elements = uint.max);
00107         abstract IReader get (inout long[] x,   uint elements = uint.max);
00108         abstract IReader get (inout ubyte[] x,  uint elements = uint.max);
00109         abstract IReader get (inout ushort[] x, uint elements = uint.max);
00110         abstract IReader get (inout uint[] x,   uint elements = uint.max);
00111         abstract IReader get (inout ulong[] x,  uint elements = uint.max);
00112         abstract IReader get (inout float[] x,  uint elements = uint.max);
00113         abstract IReader get (inout double[] x, uint elements = uint.max);
00114         abstract IReader get (inout real[] x,   uint elements = uint.max);
00115         abstract IReader get (inout char[] x,   uint elements = uint.max);
00116         abstract IReader get (inout wchar[] x,  uint elements = uint.max);
00117         abstract IReader get (inout dchar[] x,  uint elements = uint.max);
00118 
00119         /***********************************************************************
00120         
00121                 This is the mechanism used for binding arbitrary classes 
00122                 to the IO system. If a class implements IReadable, it can
00123                 be used as a target for IReader get() operations. That is, 
00124                 implementing IReadable is intended to transform any class 
00125                 into an IReader adaptor for the content held therein.
00126 
00127         ***********************************************************************/
00128 
00129         abstract IReader get (IReadable x);
00130 
00131         /***********************************************************************
00132                 
00133                 Pause the current thread until some content arrives in
00134                 the associated input buffer. This may stall forever.
00135 
00136         ***********************************************************************/
00137 
00138         abstract void wait ();
00139 
00140         /***********************************************************************
00141         
00142                 Return the buffer associated with this reader
00143 
00144         ***********************************************************************/
00145 
00146         abstract IBuffer getBuffer ();
00147 
00148         /***********************************************************************
00149         
00150                 Get the allocator to use for array management. Arrays are
00151                 always allocated by the IReader. That is, you cannot read
00152                 data into an array slice (for example). Instead, a number
00153                 of IArrayAllocator classes are available to manage memory
00154                 allocation when reading array content. 
00155 
00156                 You might use this to manage the assigned allocator. For
00157                 example, some allocators benefit from a reset() operation
00158                 after each data 'record' has been processed.
00159 
00160         ***********************************************************************/
00161 
00162         abstract IArrayAllocator getAllocator (); 
00163 
00164         /***********************************************************************
00165         
00166                 Set the allocator to use for array management. Arrays are
00167                 always allocated by the IReader. That is, you cannot read
00168                 data into an array slice (for example). Instead, a number
00169                 of IArrayAllocator classes are available to manage memory
00170                 allocation when reading array content. 
00171 
00172                 By default, an IReader will allocate each array from the 
00173                 heap. You can change that behavior by calling this method
00174                 with an IArrayAllocator of choice. For instance, there 
00175                 is a BufferAllocator which will slice an array directly 
00176                 from the buffer where possible. Also available is the 
00177                 record-oriented SliceAllocator, which slices memory from 
00178                 within a pre-allocated heap area, and should be reset by
00179                 the client code after each record has been read (to avoid 
00180                 unnecessary growth).
00181 
00182                 See ArrayAllocator for more information.
00183 
00184         ***********************************************************************/
00185 
00186         abstract void setAllocator (IArrayAllocator memory); 
00187 
00188         /***********************************************************************
00189         
00190                 Bind an IDecoder to the writer. Decoders are intended to
00191                 be used as a conversion mechanism between various character
00192                 representations (encodings).
00193 
00194         ***********************************************************************/
00195 
00196         abstract void setDecoder (AbstractDecoder);
00197 }

Generated on Sat Dec 24 17:28:33 2005 for Mango by  doxygen 1.4.0