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. An 8-bit ASCII implementation
00082         is attached by default.
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 put (wchar[] x);
00136         //IWriter put (dchar[] x);
00137 
00138         IWriter put (IWritable x);
00139 
00140         /***********************************************************************
00141         
00142                 Set the configured IStringEncoder. These are intended to
00143                 be used as a conversion mechanism between various character
00144                 representations. They are also expected to be used for the
00145                 process of applying character encodings.
00146 
00147         ***********************************************************************/
00148 
00149         void setStringEncoder (IStringEncoder s);
00150 
00151         /***********************************************************************
00152         
00153                 And these are used for the << syntax. Some are currently 
00154                 unavailable due to the compiler being confused over its
00155                 implicit type conversions ...
00156 
00157         ***********************************************************************/
00158 
00159         version (UseShiftOperators)
00160         {
00161                 IWriter opShl (bool x);
00162                 IWriter opShl (ubyte x);
00163                 IWriter opShl (byte x);
00164                 IWriter opShl (ushort x);
00165                 IWriter opShl (short x);
00166                 IWriter opShl (uint x);
00167                 IWriter opShl (int x);
00168                 IWriter opShl (ulong x);
00169                 IWriter opShl (long x);
00170                 IWriter opShl (float x);
00171                 IWriter opShl (double x);
00172                 IWriter opShl (real x);
00173 
00174                 IWriter opShl (char x);
00175                 IWriter opShl (wchar x);
00176                 IWriter opShl (dchar x);
00177 
00178                 IWriter opShl (char[] x);
00179 
00180                 // these will have to wait until walter implements string prefixes
00181                 //IWriter opShl (wchar[] x);
00182                 //IWriter opShl (dchar[] x);
00183 
00184                 IWriter opShl (IWritable x);
00185         }
00186 
00187         /***********************************************************************
00188 
00189                 Output a newline. Do this indirectly so that it can be 
00190                 intercepted by subclasses.
00191         
00192         ***********************************************************************/
00193 
00194         IWriter cr ();
00195 
00196         /***********************************************************************
00197         
00198                 Flush the output of this writer. Throws an IOException 
00199                 if the operation fails.
00200 
00201         ***********************************************************************/
00202 
00203         IWriter flush ();
00204 
00205         /***********************************************************************
00206         
00207                 Return the associated buffer
00208 
00209         ***********************************************************************/
00210 
00211         IBuffer getBuffer ();
00212 }
00213 

Generated on Sun Oct 24 22:31:15 2004 for Mango by doxygen 1.3.6