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

IWriter.d

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003         @file IWriter.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 
00027                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00028 
00029 
00030         @version        Initial version, March 2004      
00031         @author         Kris
00032 
00033 
00034 *******************************************************************************/
00035 
00036 module mango.io.model.IWriter;
00037 
00038 public import mango.io.model.IBuffer;
00039 
00040 /*******************************************************************************
00041 
00042         Interface to make any class compatible with any IWriter.
00043 
00044 *******************************************************************************/
00045 
00046 interface IWritable
00047 {
00048         void write (IWriter w);
00049 }
00050 
00051 /*******************************************************************************
00052 
00053         Make a signature for IWritable classes to use when they wish to 
00054         avoid processing by writers such as TokenWriter.
00055 
00056 *******************************************************************************/
00057 
00058 interface IPhantomWriter : IWritable
00059 {
00060 }
00061 
00062 /*******************************************************************************
00063 
00064         Make a signature for Newline classes
00065 
00066 *******************************************************************************/
00067 
00068 interface INewlineWriter : IPhantomWriter
00069 {
00070 }
00071 
00072 /*******************************************************************************
00073 
00074         Use instances of IStringEncoder to convert between character 'sizes'
00075         and to apply the various character encodings. These may throw an
00076         exception if they don't support the requested type. For example, an
00077         exception would/should be thrown where a ASCII-based IStringEncoder 
00078         is requested to write a dchar[] instead of a char[].
00079 
00080         An appropriate IStringEncoder should be attached to each IWriter, and
00081         thus be available for subsequent use. A raw binary implementation is
00082         attached by default (no encoding).
00083 
00084         Note that the 'count' argument is the number of bytes provided in
00085         the 'src' buffer. The decoders are expected to convert exactly that 
00086         amount, or throw an exception.
00087 
00088 *******************************************************************************/
00089 
00090 interface IStringEncoder
00091 {
00092         void char8  (void *src, uint count);
00093         void char16 (void *src, uint count);
00094         void char32 (void *src, uint count);
00095 }
00096 
00097 /*******************************************************************************
00098 
00099         IWriter interface. IWriter provides the means to append formatted 
00100         data to an IBuffer, and exposes a convenient method of handling a
00101         variety of data types. In addition to writing native types such
00102         as integer and char[], writers also process any class which has
00103         implemented the IWritable interface (one method).
00104 
00105 *******************************************************************************/
00106 
00107 interface IWriter
00108 {
00109         /***********************************************************************
00110         
00111                 These are the basic writer methods
00112 
00113         ***********************************************************************/
00114 
00115         IWriter put (bool x);
00116         IWriter put (ubyte x);
00117         IWriter put (byte x);
00118         IWriter put (ushort x);
00119         IWriter put (short x);
00120         IWriter put (uint x);
00121         IWriter put (int x);
00122         IWriter put (ulong x);
00123         IWriter put (long x);
00124         IWriter put (float x);
00125         IWriter put (double x);
00126         IWriter put (real x);
00127 
00128         IWriter put (char x);
00129         IWriter put (wchar x);
00130         IWriter put (dchar x);
00131 
00132         IWriter put (char[] x);
00133 
00134         // these will have to wait until walter implements string prefixes
00135         IWriter putw (wchar[] x);
00136         IWriter putd (dchar[] x);
00137 
00138         // these are currently disabled until a future release
00139         //IWriter put (bool[] x);
00140         //IWriter put (byte[] x);
00141         //IWriter put (short[] x);
00142         //IWriter put (int[] x);
00143         //IWriter put (long[] x);
00144         //IWriter put (ubyte[] x);
00145         //IWriter put (ushort[] x);
00146         //IWriter put (uint[] x);
00147         //IWriter put (ulong[] x);
00148         //IWriter put (float[] x);
00149         //IWriter put (double[] x);
00150         //IWriter put (real[] x);
00151 
00152         IWriter put (IWritable x);
00153 
00154         /***********************************************************************
00155         
00156                 Set the configured IStringEncoder. These are intended to
00157                 be used as a conversion mechanism between various character
00158                 representations. They are also expected to be used for the
00159                 process of applying character encodings.
00160 
00161         ***********************************************************************/
00162 
00163         void setStringEncoder (IStringEncoder s);
00164 
00165         /***********************************************************************
00166         
00167                 And these are used for the << syntax. Some are currently 
00168                 unavailable due to the compiler being confused over its
00169                 implicit type conversions ...
00170 
00171         ***********************************************************************/
00172 
00173         version (UseShiftOperators)
00174         {
00175                 IWriter opShl (bool x);
00176                 IWriter opShl (ubyte x);
00177                 IWriter opShl (byte x);
00178                 IWriter opShl (ushort x);
00179                 IWriter opShl (short x);
00180                 IWriter opShl (uint x);
00181                 IWriter opShl (int x);
00182                 IWriter opShl (ulong x);
00183                 IWriter opShl (long x);
00184                 IWriter opShl (float x);
00185                 IWriter opShl (double x);
00186                 IWriter opShl (real x);
00187 
00188                 IWriter opShl (char x);
00189                 IWriter opShl (wchar x);
00190                 IWriter opShl (dchar x);
00191 
00192                 IWriter opShl (char[] x);
00193 
00194                 // these will have to wait until walter implements string prefixes
00195                 //IWriter opShl (wchar[] x);
00196                 //IWriter opShl (dchar[] x);
00197 
00198                 IWriter opShl (IWritable x);
00199         }
00200 
00201         /***********************************************************************
00202 
00203                 Output a newline. Do this indirectly so that it can be 
00204                 intercepted by subclasses.
00205         
00206         ***********************************************************************/
00207 
00208         IWriter cr ();
00209 
00210         /***********************************************************************
00211         
00212                 Flush the output of this writer. Throws an IOException 
00213                 if the operation fails.
00214 
00215         ***********************************************************************/
00216 
00217         IWriter flush ();
00218 
00219         /***********************************************************************
00220         
00221                 Return the associated buffer
00222 
00223         ***********************************************************************/
00224 
00225         IBuffer getBuffer ();
00226 }
00227 

Generated on Sun Nov 7 19:06:52 2004 for Mango by doxygen 1.3.6