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 private import mango.io.model.IConduit; 00045 00046 00047 /******************************************************************************* 00048 00049 Interface to make any class compatible with any IWriter. 00050 00051 *******************************************************************************/ 00052 00053 interface IWritable 00054 { 00055 abstract void write (IWriter input); 00056 } 00057 00058 /******************************************************************************* 00059 00060 Make a signature for IWritable classes to use when they wish to 00061 avoid being processed by decorating writers, such as TextWriter. 00062 00063 *******************************************************************************/ 00064 00065 abstract class IPhantomWriter : IWritable 00066 { 00067 abstract void write (IWriter input); 00068 } 00069 00070 /******************************************************************************* 00071 00072 Make a signature for Newline classes 00073 00074 *******************************************************************************/ 00075 00076 abstract class INewlineWriter : IPhantomWriter {} 00077 00078 /******************************************************************************* 00079 00080 IWriter interface. IWriter provides the means to append formatted 00081 data to an IBuffer, and exposes a convenient method of handling a 00082 variety of data types. In addition to writing native types such 00083 as integer and char[], writers also process any class which has 00084 implemented the IWritable interface (one method). 00085 00086 *******************************************************************************/ 00087 00088 abstract class IWriter // could be an interface, but that causes poor codegen 00089 { 00090 // alias the put() methods for IOStream and Whisper styles 00091 alias put opShl; 00092 alias put opCall; 00093 00094 /*********************************************************************** 00095 00096 These are the basic writer methods 00097 00098 ***********************************************************************/ 00099 00100 abstract IWriter put (bool x); 00101 abstract IWriter put (ubyte x); 00102 abstract IWriter put (byte x); 00103 abstract IWriter put (ushort x); 00104 abstract IWriter put (short x); 00105 abstract IWriter put (uint x); 00106 abstract IWriter put (int x); 00107 abstract IWriter put (ulong x); 00108 abstract IWriter put (long x); 00109 abstract IWriter put (float x); 00110 abstract IWriter put (double x); 00111 abstract IWriter put (real x); 00112 abstract IWriter put (char x); 00113 abstract IWriter put (wchar x); 00114 abstract IWriter put (dchar x); 00115 00116 abstract IWriter put (byte[] x); 00117 abstract IWriter put (short[] x); 00118 abstract IWriter put (int[] x); 00119 abstract IWriter put (long[] x); 00120 abstract IWriter put (ubyte[] x); 00121 abstract IWriter put (ushort[] x); 00122 abstract IWriter put (uint[] x); 00123 abstract IWriter put (ulong[] x); 00124 abstract IWriter put (float[] x); 00125 abstract IWriter put (double[] x); 00126 abstract IWriter put (real[] x); 00127 abstract IWriter put (char[] x); 00128 abstract IWriter put (wchar[] x); 00129 abstract IWriter put (dchar[] x); 00130 00131 /*********************************************************************** 00132 00133 This is the mechanism used for binding arbitrary classes 00134 to the IO system. If a class implements IWritable, it can 00135 be used as a target for IWriter put() operations. That is, 00136 implementing IWritable is intended to transform any class 00137 into an IWriter adaptor for the content held therein. 00138 00139 ***********************************************************************/ 00140 00141 abstract IWriter put (IWritable x); 00142 00143 /*********************************************************************** 00144 00145 Bind an IEncoder to the writer. Encoders are intended to 00146 be used as a conversion mechanism between various character 00147 representations (encodings). Each writer may be configured 00148 with a distinct encoder. 00149 00150 ***********************************************************************/ 00151 00152 abstract void setEncoder (AbstractEncoder); 00153 00154 /*********************************************************************** 00155 00156 Output a newline. Do this indirectly so that it can be 00157 intercepted by subclasses. 00158 00159 ***********************************************************************/ 00160 00161 abstract IWriter cr (); 00162 00163 /*********************************************************************** 00164 00165 Flush the output of this writer. Throws an IOException 00166 if the operation fails. These are aliases for each other. 00167 00168 ***********************************************************************/ 00169 00170 abstract IWriter put (); 00171 abstract IWriter flush (); 00172 00173 /*********************************************************************** 00174 00175 Return the associated buffer 00176 00177 ***********************************************************************/ 00178 00179 abstract IBuffer getBuffer (); 00180 } 00181