00001 //------------------------------------------------------------------------------ 00002 // Lamp : Open source game middleware 00003 // Copyright (C) 2004 Junpei Ohtani ( Email : junpee@users.sourceforge.jp ) 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 //------------------------------------------------------------------------------ 00019 00020 /** @file 00021 * バイナリリーダ実装 00022 * @author Junpee 00023 */ 00024 00025 #include "LampBasic.h" 00026 #include "Core/InputOutput/BinaryReader.h" 00027 00028 namespace Lamp{ 00029 00030 //------------------------------------------------------------------------------ 00031 // コンストラクタ 00032 BinaryReader::BinaryReader() : Reader(){ 00033 } 00034 //------------------------------------------------------------------------------ 00035 // デストラクタ 00036 BinaryReader::~BinaryReader(){ 00037 } 00038 //------------------------------------------------------------------------------ 00039 // boolの読み込み 00040 bool BinaryReader::readBool(){ 00041 bool value; 00042 readBytes(&value, sizeof(bool)); 00043 return value; 00044 } 00045 //------------------------------------------------------------------------------ 00046 // charの読み込み 00047 char BinaryReader::readChar(){ 00048 char value; 00049 readBytes(&value, sizeof(char)); 00050 return value; 00051 } 00052 //------------------------------------------------------------------------------ 00053 // u_charの読み込み 00054 u_char BinaryReader::readUChar(){ 00055 u_char value; 00056 readBytes(&value, sizeof(u_char)); 00057 return value; 00058 } 00059 //------------------------------------------------------------------------------ 00060 // shortの読み込み 00061 short BinaryReader::readShort(){ 00062 short value; 00063 readBytes(&value, sizeof(short)); 00064 return value; 00065 } 00066 //------------------------------------------------------------------------------ 00067 // u_shortの読み込み 00068 u_short BinaryReader::readUShort(){ 00069 u_short value; 00070 readBytes(&value, sizeof(u_short)); 00071 return value; 00072 } 00073 //------------------------------------------------------------------------------ 00074 // intの読み込み 00075 int BinaryReader::readInt(){ 00076 int value; 00077 readBytes(&value, sizeof(int)); 00078 return value; 00079 } 00080 //------------------------------------------------------------------------------ 00081 // u_intの読み込み 00082 u_int BinaryReader::readUInt(){ 00083 u_int value; 00084 readBytes(&value, sizeof(u_int)); 00085 return value; 00086 } 00087 //------------------------------------------------------------------------------ 00088 // floatの読み込み 00089 float BinaryReader::readFloat(){ 00090 float value; 00091 readBytes(&value, sizeof(float)); 00092 return value; 00093 } 00094 //------------------------------------------------------------------------------ 00095 // doubleの読み込み 00096 double BinaryReader::readDouble(){ 00097 double value; 00098 readBytes(&value, sizeof(double)); 00099 return value; 00100 } 00101 //------------------------------------------------------------------------------ 00102 // Stringの読み込み 00103 const String BinaryReader::readString(){ 00104 int value; 00105 readBytes(&value, sizeof(int)); 00106 char* buffer = new char[value + 1]; 00107 readBytes(buffer, value); 00108 buffer[value] = '\0'; 00109 String returnString(buffer); 00110 delete[] buffer; 00111 return returnString; 00112 } 00113 //------------------------------------------------------------------------------ 00114 // 配列の読み込み 00115 void BinaryReader::readArray( 00116 void* array, int elementSize, int elementCount){ 00117 readBytes(array, elementSize * elementCount); 00118 } 00119 //------------------------------------------------------------------------------ 00120 } // End of namespace Lamp 00121 //------------------------------------------------------------------------------