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

FileOutputStream.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/FileOutputStream.h"
00028 
00029 namespace Lamp{
00030 
00031 //------------------------------------------------------------------------------
00032 // コンストラクタ
00033 FileOutputStream::FileOutputStream(String fileName) : position_(0), size_(0){
00034     file_ = fopen(fileName.getBytes(), "wbc");
00035     Assert(file_ != NULL);
00036 }
00037 //------------------------------------------------------------------------------
00038 // デストラクタ
00039 FileOutputStream::~FileOutputStream(){
00040     int closeResult = fclose(file_);
00041     Assert(closeResult == 0);
00042 }
00043 //------------------------------------------------------------------------------
00044 // バイトデータの書き出し
00045 void FileOutputStream::writeBytes(const void* data, int size){
00046     int result = (int)fwrite(data, 1, size, file_);
00047     Assert(result == size);
00048     position_ += size;
00049     if(position_ > size_){ size_ = position_; }
00050 }
00051 //------------------------------------------------------------------------------
00052 // サイズの取得
00053 int FileOutputStream::getSize(){
00054     return size_;
00055 }
00056 //------------------------------------------------------------------------------
00057 // スキップ
00058 void FileOutputStream::skip(int size){
00059     for(int i = 0;i < size;i++){
00060         int result = fputc(0, file_);
00061         Assert(result != EOF);
00062     }
00063     position_ += size;
00064     if(position_ > size_){ size_ = position_; }
00065 }
00066 //------------------------------------------------------------------------------
00067 // アライメントを取る
00068 int FileOutputStream::align(int alignSize){
00069     int size = position_ % alignSize;
00070     if(size == 0){ return size; }
00071     size = alignSize - size;
00072     for(int i = 0;i < size;i++){
00073         int result = fputc(0, file_);
00074         Assert(result != EOF);
00075     }
00076     position_ += size;
00077     if(position_ > size_){ size_ = position_; }
00078     return size;
00079 }
00080 //------------------------------------------------------------------------------
00081 // 書き込み位置の取得
00082 int FileOutputStream::getPosition(){
00083     return position_;
00084 }
00085 //------------------------------------------------------------------------------
00086 // 書き込み位置の設定
00087 void FileOutputStream::setPosition(int position){
00088     int result = fseek(file_, position, SEEK_SET);
00089     Assert(result == 0);
00090     position_ = position;
00091 }
00092 //------------------------------------------------------------------------------
00093 // フラッシュ
00094 void FileOutputStream::flush(){
00095     int result = fflush(file_);
00096     Assert(result == 0);
00097 }
00098 //------------------------------------------------------------------------------
00099 } // End of namespace Lamp
00100 //------------------------------------------------------------------------------

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