00001 /******************************************************************************* 00002 00003 @file EndianReader.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.EndianReader; 00037 00038 public import mango.io.Reader; 00039 00040 private import mango.base.ByteSwap; 00041 00042 /******************************************************************************* 00043 00044 A pair of classes to handle byte-swapping for integral types. The 00045 basic EndianReader is transparent, whilst EndianReaderSwap is not. 00046 00047 Use the static create() method to construct the appropriate reader. 00048 00049 *******************************************************************************/ 00050 00051 class EndianReader : Reader 00052 { 00053 /*********************************************************************** 00054 00055 Construct EndianReader upon the given IBuffer. 00056 00057 ***********************************************************************/ 00058 00059 this (IBuffer buffer) 00060 { 00061 super (buffer); 00062 00063 numeric.int16 = 00064 numeric.int16u = 00065 string.char16 = &bits16; 00066 00067 numeric.int32 = 00068 numeric.int32u = 00069 numeric.float32 = 00070 string.char32 = &bits32; 00071 00072 numeric.int64 = 00073 numeric.int64u = 00074 numeric.float64 = &bits64; 00075 00076 numeric.float80 = &bits80; 00077 } 00078 00079 /*********************************************************************** 00080 00081 ***********************************************************************/ 00082 00083 override char[] toString() 00084 { 00085 return "endian reader"; 00086 } 00087 00088 /*********************************************************************** 00089 00090 ***********************************************************************/ 00091 00092 final void bits16 (void* dst, uint count) 00093 { 00094 read (dst, count); 00095 ByteSwap.swap16 (dst, count); 00096 } 00097 00098 /*********************************************************************** 00099 00100 ***********************************************************************/ 00101 00102 final void bits32 (void* dst, uint count) 00103 { 00104 read (dst, count); 00105 ByteSwap.swap32 (dst, count); 00106 } 00107 00108 /*********************************************************************** 00109 00110 ***********************************************************************/ 00111 00112 final void bits64 (void* dst, uint count) 00113 { 00114 read (dst, count); 00115 ByteSwap.swap64 (dst, count); 00116 } 00117 00118 /*********************************************************************** 00119 00120 ***********************************************************************/ 00121 00122 final void bits80 (void* dst, uint count) 00123 { 00124 read (dst, count); 00125 ByteSwap.swap80 (dst, count); 00126 } 00127 }