/*---------------------------------------------------------------------------* Project: NintendoWare File: font_CharStrmReader.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_FONT_CHARSTRMREADER_H_ #define NW_FONT_CHARSTRMREADER_H_ #if defined(_MSC_VER) && _MSC_VER >= 1500 #pragma once #endif #include #include namespace nw { namespace font { //--------------------------------------------------------------------------- //! @brief 文字ストリームを読み取るための方法を提供します。 //--------------------------------------------------------------------------- class CharStrmReader { friend class Font; public: /* ------------------------------------------------------------------------ 関数 ------------------------------------------------------------------------ */ //! @name コンストラクタ / デストラクタ //@{ //! @brief コンストラクタです。 //! //! @param[in] rhs コピー元のオブジェクト。 //! CharStrmReader(const CharStrmReader& rhs) : mCharStrm(rhs.mCharStrm), mReadFunc(rhs.mReadFunc) { } //! デストラクタです。 ~CharStrmReader() { } //@} //! @name ストリーム読み取り //@{ //! @brief CharStrmReader が解釈する文字ストリームを設定します。 //! //! @param[in] stream 新しく設定するストリームの開始点。 //! void Set(const char* stream) { NN_POINTER_ASSERT(stream); NN_ASSERT( mReadFunc == &CharStrmReader::ReadNextCharUTF8 || mReadFunc == &CharStrmReader::ReadNextCharCP1252 || mReadFunc == &CharStrmReader::ReadNextCharSJIS ); mCharStrm = stream; } //! @brief CharStrmReader が解釈する文字ストリームを設定します。 //! //! @param[in] stream 新しく設定するストリームの開始点。 //! void Set(const wchar_t* stream) { NN_ALIGN_ASSERT(stream, 2); NN_POINTER_ASSERT(stream); NN_ASSERT(mReadFunc == &CharStrmReader::ReadNextCharUTF16); mCharStrm = stream; } //! @brief ストリームの現在位置へのポインタを取得します。 //! //! @return ストリーム中の次に読み取られる文字へのポインタを返します。 //! const void* GetCurrentPos() const { return mCharStrm; } //! @brief 文字ストリームの次の文字の文字コードを取得すると共に、 //! 現在位置を一文字分進めます。 //! //! @return 次の文字の文字コードを返します。 //! u16 Next() { return (this->*mReadFunc)(); } //@} private: /* ------------------------------------------------------------------------ 型 ------------------------------------------------------------------------ */ typedef u16 (CharStrmReader::*ReadNextCharFunc)(); /* ------------------------------------------------------------------------ 変数 ------------------------------------------------------------------------ */ const void* mCharStrm; // ストリーム現在位置へのポインタ const ReadNextCharFunc mReadFunc; // ストリーム解釈関数へのポインタ /* ------------------------------------------------------------------------ 関数 ------------------------------------------------------------------------ */ //---- コンストラクタ explicit CharStrmReader(ReadNextCharFunc func) : mCharStrm(NULL), mReadFunc(func) { } //---- ストリーム操作 template CharType GetChar(int offset=0) const { const CharType* charStrm = reinterpret_cast(mCharStrm); return *(charStrm + offset); } template void StepStrm(int step=1) { const CharType*& charStrm = reinterpret_cast(mCharStrm); charStrm += step; } //! @brief UTF8文字列ストリームの現在位置の文字の文字コードを読み取り、 //! 文字列ストリームの現在位置を1文字分進めます。 //! //! @return ストリームの現在位置の文字の文字コード。 //! u16 ReadNextCharUTF8(); //! @brief UTF16文字列ストリームの現在位置の文字の文字コードを読み取り、 //! 文字列ストリームの現在位置を1文字分進めます。 //! //! @return ストリームの現在位置の文字の文字コード。 //! u16 ReadNextCharUTF16(); //! @brief CP1252文字列ストリームの現在位置の文字の文字コードを読み取り、 //! 文字列ストリームの現在位置を1文字分進めます。 //! //! @return ストリームの現在位置の文字の文字コード。 //! u16 ReadNextCharCP1252(); //! @brief SJIS文字列ストリームの現在位置の文字の文字コードを読み取り、 //! 文字列ストリームの現在位置を1文字分進めます。 //! //! @return ストリームの現在位置の文字の文字コード。 //! u16 ReadNextCharSJIS(); }; } // namespace font } // namespace nw #endif // NW_FONT_CHARSTRMREADER_H_