1 /*---------------------------------------------------------------------------* 2 Project: NintendoWare 3 File: font_CharStrmReader.h 4 5 Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain proprietary 8 information of Nintendo and/or its licensed developers and are protected by 9 national and international copyright laws. They may not be disclosed to third 10 parties or copied or duplicated in any form, in whole or in part, without the 11 prior written consent of Nintendo. 12 13 The content herein is highly confidential and should be handled accordingly. 14 15 $Revision: 31311 $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef NW_FONT_CHARSTRMREADER_H_ 19 #define NW_FONT_CHARSTRMREADER_H_ 20 21 #if defined(_MSC_VER) && _MSC_VER >= 1500 22 #pragma once 23 #endif 24 25 #include <nn/types.h> 26 #include <nn/assert.h> 27 28 namespace nw { 29 namespace font { 30 31 32 //--------------------------------------------------------------------------- 33 //! @brief 文字ストリームを読み取るための方法を提供します。 34 //--------------------------------------------------------------------------- 35 class CharStrmReader 36 { 37 friend class Font; 38 39 public: 40 /* ------------------------------------------------------------------------ 41 関数 42 ------------------------------------------------------------------------ */ 43 44 //! @name コンストラクタ / デストラクタ 45 //@{ 46 47 //! @brief コンストラクタです。 48 //! 49 //! @param[in] rhs コピー元のオブジェクト。 50 //! CharStrmReader(const CharStrmReader & rhs)51 CharStrmReader(const CharStrmReader& rhs) 52 : mCharStrm(rhs.mCharStrm), 53 mReadFunc(rhs.mReadFunc) 54 { 55 } 56 57 //! デストラクタです。 ~CharStrmReader()58 ~CharStrmReader() 59 { 60 } 61 62 //@} 63 64 65 //! @name ストリーム読み取り 66 //@{ 67 68 //! @brief CharStrmReader が解釈する文字ストリームを設定します。 69 //! 70 //! @param[in] stream 新しく設定するストリームの開始点。 71 //! Set(const char * stream)72 void Set(const char* stream) 73 { 74 NN_POINTER_ASSERT(stream); 75 NN_ASSERT( mReadFunc == &CharStrmReader::ReadNextCharUTF8 76 || mReadFunc == &CharStrmReader::ReadNextCharCP1252 77 || mReadFunc == &CharStrmReader::ReadNextCharSJIS ); 78 mCharStrm = stream; 79 } 80 81 //! @brief CharStrmReader が解釈する文字ストリームを設定します。 82 //! 83 //! @param[in] stream 新しく設定するストリームの開始点。 84 //! Set(const wchar_t * stream)85 void Set(const wchar_t* stream) 86 { 87 NN_ALIGN_ASSERT(stream, 2); 88 NN_POINTER_ASSERT(stream); 89 NN_ASSERT(mReadFunc == &CharStrmReader::ReadNextCharUTF16); 90 mCharStrm = stream; 91 } 92 93 //! @brief ストリームの現在位置へのポインタを取得します。 94 //! 95 //! @return ストリーム中の次に読み取られる文字へのポインタを返します。 96 //! GetCurrentPos()97 const void* GetCurrentPos() const { return mCharStrm; } 98 99 //! @brief 文字ストリームの次の文字の文字コードを取得すると共に、 100 //! 現在位置を一文字分進めます。 101 //! 102 //! @return 次の文字の文字コードを返します。 103 //! Next()104 u16 Next() { return (this->*mReadFunc)(); } 105 106 //@} 107 108 private: 109 /* ------------------------------------------------------------------------ 110 型 111 ------------------------------------------------------------------------ */ 112 typedef u16 (CharStrmReader::*ReadNextCharFunc)(); 113 114 115 /* ------------------------------------------------------------------------ 116 変数 117 ------------------------------------------------------------------------ */ 118 const void* mCharStrm; // ストリーム現在位置へのポインタ 119 const ReadNextCharFunc mReadFunc; // ストリーム解釈関数へのポインタ 120 121 122 /* ------------------------------------------------------------------------ 123 関数 124 ------------------------------------------------------------------------ */ 125 //---- コンストラクタ CharStrmReader(ReadNextCharFunc func)126 explicit CharStrmReader(ReadNextCharFunc func) 127 : mCharStrm(NULL), 128 mReadFunc(func) 129 { 130 } 131 132 //---- ストリーム操作 133 template <typename CharType> 134 CharType GetChar(int offset=0) const 135 { 136 const CharType* charStrm = reinterpret_cast<const CharType*>(mCharStrm); 137 return *(charStrm + offset); 138 } 139 140 template <typename CharType> 141 void StepStrm(int step=1) 142 { 143 const CharType*& charStrm = reinterpret_cast<const CharType*&>(mCharStrm); 144 charStrm += step; 145 } 146 147 //! @brief UTF8文字列ストリームの現在位置の文字の文字コードを読み取り、 148 //! 文字列ストリームの現在位置を1文字分進めます。 149 //! 150 //! @return ストリームの現在位置の文字の文字コード。 151 //! 152 u16 ReadNextCharUTF8(); 153 154 //! @brief UTF16文字列ストリームの現在位置の文字の文字コードを読み取り、 155 //! 文字列ストリームの現在位置を1文字分進めます。 156 //! 157 //! @return ストリームの現在位置の文字の文字コード。 158 //! 159 u16 ReadNextCharUTF16(); 160 161 //! @brief CP1252文字列ストリームの現在位置の文字の文字コードを読み取り、 162 //! 文字列ストリームの現在位置を1文字分進めます。 163 //! 164 //! @return ストリームの現在位置の文字の文字コード。 165 //! 166 u16 ReadNextCharCP1252(); 167 168 //! @brief SJIS文字列ストリームの現在位置の文字の文字コードを読み取り、 169 //! 文字列ストリームの現在位置を1文字分進めます。 170 //! 171 //! @return ストリームの現在位置の文字の文字コード。 172 //! 173 u16 ReadNextCharSJIS(); 174 }; 175 176 177 178 } // namespace font 179 } // namespace nw 180 181 #endif // NW_FONT_CHARSTRMREADER_H_ 182