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 #ifndef MEMORY_OUTPUT_STREAM_H_ 00026 #define MEMORY_OUTPUT_STREAM_H_ 00027 00028 #include <Core/InputOutput/OutputStream.h> 00029 00030 namespace Lamp{ 00031 00032 //------------------------------------------------------------------------------ 00033 /** 00034 * メモリ出力ストリーム 00035 */ 00036 class MemoryOutputStream : public OutputStream{ 00037 public: 00038 /** 00039 * コンストラクタ 00040 * @param bufferInitialSize バッファ初期化サイズ 00041 */ 00042 explicit MemoryOutputStream(int bufferInitialSize); 00043 00044 /** 00045 * デストラクタ 00046 */ 00047 virtual ~MemoryOutputStream(); 00048 00049 /** 00050 * バッファの取得 00051 * 00052 * メモリバッファを取得します。 00053 * このバッファはこのクラスがデストラクトされる時に消去されます。 00054 * @return メモリバッファ 00055 */ 00056 virtual const char* getBuffer(){ return buffer_; } 00057 00058 protected: 00059 /** 00060 * バイトデータの書き出し 00061 * @param data 書き出すバイトデータ 00062 * @param size 書き出すサイズ 00063 */ 00064 virtual void writeBytes(const void* data, int size); 00065 00066 /** 00067 * サイズの取得 00068 * @return 書き込んだバイト数 00069 */ 00070 virtual int getSize(); 00071 00072 /** 00073 * スキップ 00074 * 00075 * 指定されたバイト数、0を書き出します。 00076 * @param size 0を書き出すバイト数 00077 */ 00078 virtual void skip(int size); 00079 00080 /** 00081 * アライメントを取る 00082 * 00083 * 指定されたバイト数のアライメントまで0を書き出します。 00084 * @param alignSize アライメントをとるバイト数 00085 * @return 0を書き出したバイト数 00086 */ 00087 virtual int align(int alignSize); 00088 00089 /** 00090 * 書き込み位置の取得 00091 * @return 書き込み位置 00092 */ 00093 virtual int getPosition(); 00094 00095 /** 00096 * 書き込み位置の設定 00097 * 00098 * 指定された位置に書き込み位置を変更します。 00099 * @param position 書き込み位置 00100 */ 00101 virtual void setPosition(int position); 00102 00103 /** 00104 * フラッシュ 00105 * 00106 * ストリームをフラッシュします。 00107 */ 00108 virtual void flush(); 00109 00110 private: 00111 // コピーコンストラクタの隠蔽 00112 MemoryOutputStream(const MemoryOutputStream& copy); 00113 00114 // 代入コピーの隠蔽 00115 void operator =(const MemoryOutputStream& copy); 00116 00117 // バッファチェック 00118 void bufferCheck(int size); 00119 00120 // バッファ 00121 char* buffer_; 00122 // バッファサイズ 00123 int bufferSize_; 00124 // 位置 00125 int position_; 00126 // サイズ 00127 int size_; 00128 00129 }; 00130 00131 //------------------------------------------------------------------------------ 00132 } // End of namespace Lamp 00133 #endif // End of MEMORY_OUTPUT_STREAM_H_ 00134 //------------------------------------------------------------------------------