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

Generated on Fri May 27 18:11:56 2005 for Mango by  doxygen 1.4.0