Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

MemoryInputStream.cpp

Go to the documentation of this file.
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 <stdio.h>
00026 #include "LampBasic.h"
00027 #include "Core/InputOutput/MemoryInputStream.h"
00028 
00029 namespace Lamp{
00030 
00031 //------------------------------------------------------------------------------
00032 // コンストラクタ
00033 MemoryInputStream::MemoryInputStream(const char* buffer, int size) :
00034     buffer_(buffer), size_(size), position_(0){
00035 }
00036 //------------------------------------------------------------------------------
00037 // デストラクタ
00038 MemoryInputStream::~MemoryInputStream(){
00039 }
00040 //------------------------------------------------------------------------------
00041 // メモリ入力ストリームの複製
00042 MemoryInputStream* MemoryInputStream::cloneMemoryInputStream(){
00043     MemoryInputStream* memoryInputStream =
00044         new MemoryInputStream(buffer_, size_);
00045     memoryInputStream->setPosition(getPosition());
00046     return memoryInputStream;
00047 }
00048 //------------------------------------------------------------------------------
00049 // 終端かどうか
00050 bool MemoryInputStream::isEnd(){
00051     return (position_ == size_);
00052 }
00053 //------------------------------------------------------------------------------
00054 // バイトデータの読み出し
00055 void MemoryInputStream::readBytes(void* data, int size){
00056     Assert((position_ + size) <= size_);
00057     std::memcpy(data, buffer_ + position_, size);
00058     position_ += size;
00059 }
00060 //------------------------------------------------------------------------------
00061 // サイズの取得
00062 int MemoryInputStream::getSize(){
00063     return size_;
00064 }
00065 //------------------------------------------------------------------------------
00066 // スキップ
00067 void MemoryInputStream::skip(int size){
00068     Assert((position_ + size) <= size_);
00069     position_ += size;
00070 }
00071 //------------------------------------------------------------------------------
00072 // アライメントを取る
00073 int MemoryInputStream::align(int alignSize){
00074     int size = position_ % alignSize;
00075     if(size == 0){ return size; }
00076     size = alignSize - size;
00077     Assert((position_ + size) <= size_);
00078     position_ += size;
00079     return size;
00080 }
00081 //------------------------------------------------------------------------------
00082 // 読み込み位置の取得
00083 int MemoryInputStream::getPosition(){
00084     return position_;
00085 }
00086 //------------------------------------------------------------------------------
00087 // 読み込み位置の設定
00088 void MemoryInputStream::setPosition(int position){
00089     Assert(position >= 0);
00090     Assert(position <= size_);
00091     position_ = position;
00092 }
00093 //------------------------------------------------------------------------------
00094 } // End of namespace Lamp
00095 //------------------------------------------------------------------------------

Generated on Wed Mar 16 10:29:32 2005 for Lamp by doxygen 1.3.2