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         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         @author         Kris, Ivan Senji (the "alias opShl put" idea)
00035 
00036 
00037 *******************************************************************************/
00038 
00039 module mango.io.model.IWriter;
00040 
00041 public import mango.io.model.IBuffer;
00042 
00043 /*******************************************************************************
00044 
00045 *******************************************************************************/
00046 
00047 typedef void delegate(void* dst, uint count) BufferEncoder;
00048 
00049 /*******************************************************************************
00050 
00051         Interface to make any class compatible with any IWriter.
00052 
00053 *******************************************************************************/
00054 
00055 interface IWritable
00056 {
00057         void write (IWriter w);
00058 }
00059 
00060 /*******************************************************************************
00061 
00062         Any class implementing IEncoder can be bound to a writer using
00063         the bind() method.
00064         
00065 *******************************************************************************/
00066 
00067 interface IEncoder
00068 {
00069         ConverterType type ();
00070 
00071         BufferEncoder bind (IWriter writer);
00072 }
00073 
00074 /*******************************************************************************
00075 
00076         Make a signature for IWritable classes to use when they wish to 
00077         avoid processing by writers such as TokenWriter.
00078 
00079 *******************************************************************************/
00080 
00081 interface IPhantomWriter : IWritable
00082 {
00083 }
00084 
00085 /*******************************************************************************
00086 
00087         Make a signature for Newline classes
00088 
00089 *******************************************************************************/
00090 
00091 interface INewlineWriter : IPhantomWriter
00092 {
00093 }
00094 
00095 /*******************************************************************************
00096 
00097         IWriter interface. IWriter provides the means to append formatted 
00098         data to an IBuffer, and exposes a convenient method of handling a
00099         variety of data types. In addition to writing native types such
00100         as integer and char[], writers also process any class which has
00101         implemented the IWritable interface (one method).
00102 
00103 *******************************************************************************/
00104 
00105 interface IWriter
00106 {
00107         alias opShl put;
00108 
00109         /***********************************************************************
00110         
00111                 These are the basic writer methods
00112 
00113         ***********************************************************************/
00114 
00115         IWriter opShl (bool x);
00116         IWriter opShl (ubyte x);
00117         IWriter opShl (byte x);
00118         IWriter opShl (ushort x);
00119         IWriter opShl (short x);
00120         IWriter opShl (uint x);
00121         IWriter opShl (int x);
00122         IWriter opShl (ulong x);
00123         IWriter opShl (long x);
00124         IWriter opShl (float x);
00125         IWriter opShl (double x);
00126         IWriter opShl (real x);
00127         IWriter opShl (char x);
00128         IWriter opShl (wchar x);
00129         IWriter opShl (dchar x);
00130 
00131         IWriter opShl (byte[] x);
00132         IWriter opShl (short[] x);
00133         IWriter opShl (int[] x);
00134         IWriter opShl (long[] x);
00135         IWriter opShl (ubyte[] x);
00136         IWriter opShl (ushort[] x);
00137         IWriter opShl (uint[] x);
00138         IWriter opShl (ulong[] x);
00139         IWriter opShl (float[] x);
00140         IWriter opShl (double[] x);
00141         IWriter opShl (real[] x);
00142         IWriter opShl (char[] x);
00143 
00144         // these two will have to wait until Walter fixes 
00145         // the string-literal conversion fiasco ...
00146         IWriter opShlw (wchar[] x);
00147         IWriter opShld (dchar[] x);
00148 
00149         IWriter opShl (IWritable x);
00150 
00151         /***********************************************************************
00152         
00153                 Bind an IEncoder to the writer. Encoders are intended to
00154                 be used as a conversion mechanism between various character
00155                 representations (encodings), or the translation of any data
00156                 type from one representation to another. Each data type may
00157                 be configured with a distinct encoder, covering all native
00158                 types (15 in total).
00159 
00160                 An appropriate encoder set should be attached to each 
00161                 IWriter, and thus be available for subsequent use. A raw 
00162                 binary implementation is attached by default (no encoding).
00163 
00164                 See module mango.icu.UMango for an example of encoder 
00165                 implementation -- those classes bind the ICU converters 
00166                 to this IO package.
00167 
00168         ***********************************************************************/
00169 
00170         void setEncoder (IEncoder e); 
00171 
00172         /***********************************************************************
00173 
00174                 Output a newline. Do this indirectly so that it can be 
00175                 intercepted by subclasses.
00176         
00177         ***********************************************************************/
00178 
00179         IWriter cr ();
00180 
00181         /***********************************************************************
00182         
00183                 Flush the output of this writer. Throws an IOException 
00184                 if the operation fails.
00185 
00186         ***********************************************************************/
00187 
00188         IWriter flush ();
00189 
00190         /***********************************************************************
00191         
00192                 Return the associated buffer
00193 
00194         ***********************************************************************/
00195 
00196         IBuffer getBuffer ();
00197 }
00198 

Generated on Tue Jan 25 21:18:22 2005 for Mango by doxygen 1.3.6