//------------------------------------------------------------------------------
// Lamp : Open source game middleware
// Copyright (C) 2004  Junpei Ohtani ( Email : junpee@users.sourceforge.jp )
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//------------------------------------------------------------------------------

/** @file
 * バイナリリーダ実装
 * @author Junpee
 */

#include "LampBasic.h"
#include "Core/InputOutput/BinaryReader.h"

namespace Lamp{

//------------------------------------------------------------------------------
// コンストラクタ
BinaryReader::BinaryReader() : Reader(){
}
//------------------------------------------------------------------------------
// デストラクタ
BinaryReader::~BinaryReader(){
}
//------------------------------------------------------------------------------
// boolの読み込み
bool BinaryReader::readBool(){
	bool value;
	readBytes(&value, sizeof(bool));
	return value;
}
//------------------------------------------------------------------------------
// charの読み込み
char BinaryReader::readChar(){
	char value;
	readBytes(&value, sizeof(char));
	return value;
}
//------------------------------------------------------------------------------
// u_charの読み込み
u_char BinaryReader::readUChar(){
	u_char value;
	readBytes(&value, sizeof(u_char));
	return value;
}
//------------------------------------------------------------------------------
// shortの読み込み
short BinaryReader::readShort(){
	short value;
	readBytes(&value, sizeof(short));
	return value;
}
//------------------------------------------------------------------------------
// u_shortの読み込み
u_short BinaryReader::readUShort(){
	u_short value;
	readBytes(&value, sizeof(u_short));
	return value;
}
//------------------------------------------------------------------------------
// intの読み込み
int BinaryReader::readInt(){
	int value;
	readBytes(&value, sizeof(int));
	return value;
}
//------------------------------------------------------------------------------
// u_intの読み込み
u_int BinaryReader::readUInt(){
	u_int value;
	readBytes(&value, sizeof(u_int));
	return value;
}
//------------------------------------------------------------------------------
// floatの読み込み
float BinaryReader::readFloat(){
	float value;
	readBytes(&value, sizeof(float));
	return value;
}
//------------------------------------------------------------------------------
// doubleの読み込み
double BinaryReader::readDouble(){
	double value;
	readBytes(&value, sizeof(double));
	return value;
}
//------------------------------------------------------------------------------
// Stringの読み込み
const String BinaryReader::readString(){
	int value;
	readBytes(&value, sizeof(int));
	char* buffer = new char[value + 1];
	readBytes(buffer, value);
	buffer[value] = '\0';
	String returnString(buffer);
	delete[] buffer;
	return returnString;
}
//------------------------------------------------------------------------------
// 配列の読み込み
void BinaryReader::readArray(
	void* array, int elementSize, int elementCount){
	readBytes(array, elementSize * elementCount);
}
//------------------------------------------------------------------------------
} // End of namespace Lamp
//------------------------------------------------------------------------------
