00001 /******************************************************************************* 00002 00003 @file Writer.d 00004 00005 00006 Copyright (c) 2004 Kris Bell 00007 00008 This software is provided 'as-is', without any express or implied 00009 warranty. In no event will the authors be held liable for damages 00010 of any kind arising from the use of this software. 00011 00012 Permission is hereby granted to anyone to use this software for any 00013 purpose, including commercial applications, and to alter it and/or 00014 redistribute it freely, subject to the following restrictions: 00015 00016 1. The origin of this software must not be misrepresented; you must 00017 not claim that you wrote the original software. If you use this 00018 software in a product, an acknowledgment within documentation of 00019 said product would be appreciated but is not required. 00020 00021 2. Altered source versions must be plainly marked as such, and must 00022 not be misrepresented as being the original software. 00023 00024 3. This notice may not be removed or altered from any distribution 00025 of the source. 00026 00027 4. Derivative works are permitted, but they must carry this notice 00028 in full and credit the original source. 00029 00030 00031 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 00032 00033 00034 @version Initial version, March 2004 00035 @author Kris 00036 00037 *******************************************************************************/ 00038 00039 module mango.io.Writer; 00040 00041 public import mango.io.AbstractWriter; 00042 00043 /******************************************************************************* 00044 00045 Binary data Writer. Writers provide the means to append formatted 00046 data to an IBuffer, and expose a convenient method of handling a 00047 variety of data types. In addition to writing native types such 00048 as integer and char[], writers also process any class which has 00049 implemented the IWritable interface (one method). 00050 00051 See AbstractWriter for usage examples. 00052 00053 *******************************************************************************/ 00054 00055 class Writer : AbstractWriter 00056 { 00057 /*********************************************************************** 00058 00059 Construct a Writer upon the provided IBuffer. All formatted 00060 output will be directed to this buffer. 00061 00062 ***********************************************************************/ 00063 00064 this (IBuffer buffer) 00065 { 00066 super (buffer); 00067 00068 encode.int1 = 00069 encode.int8 = 00070 encode.int8u = 00071 encode.int16 = 00072 encode.int16u = 00073 encode.int32 = 00074 encode.int32u = 00075 encode.int64 = 00076 encode.int64u = 00077 encode.float32 = 00078 encode.float64 = 00079 encode.float80 = 00080 encode.char8 = 00081 encode.char16 = 00082 encode.char32 = &write; 00083 } 00084 00085 /*********************************************************************** 00086 00087 Construct a Writer on the buffer associated with the given 00088 conduit. 00089 00090 ***********************************************************************/ 00091 00092 this (IConduit conduit) 00093 { 00094 this (conduit.createBuffer); 00095 } 00096 00097 /*********************************************************************** 00098 00099 ***********************************************************************/ 00100 00101 final void write (void* src, uint count) 00102 { 00103 buffer.append (src[0..count]); 00104 } 00105 }