1 /*---------------------------------------------------------------------------* 2 Project: Horizon 3 File: font_CharStrmReader.h 4 5 Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Revision: 25674 $ 14 *---------------------------------------------------------------------------*/ 15 16 #ifndef NN_FONT_FONT_CHAR_STRM_READER_H_ 17 #define NN_FONT_FONT_CHAR_STRM_READER_H_ 18 19 #include <nn/types.h> 20 #include <nn/assert.h> 21 22 namespace nn { 23 namespace font { 24 25 26 //--------------------------------------------------------------------------- 27 // 28 //--------------------------------------------------------------------------- 29 class CharStrmReader 30 { 31 friend class Font; 32 33 public: 34 /* ------------------------------------------------------------------------ 35 Functions 36 ------------------------------------------------------------------------ */ 37 38 // 39 // 40 41 // 42 // 43 // 44 // CharStrmReader(const CharStrmReader & rhs)45 CharStrmReader(const CharStrmReader& rhs) 46 : mCharStrm(rhs.mCharStrm), 47 mReadFunc(rhs.mReadFunc) 48 { 49 } 50 51 // ~CharStrmReader()52 ~CharStrmReader() 53 { 54 } 55 56 // 57 58 59 // 60 // 61 62 // 63 // 64 // 65 // Set(const char * stream)66 void Set(const char* stream) 67 { 68 NN_POINTER_ASSERT(stream); 69 NN_ASSERT( mReadFunc == &CharStrmReader::ReadNextCharUTF8 70 || mReadFunc == &CharStrmReader::ReadNextCharCP1252 71 || mReadFunc == &CharStrmReader::ReadNextCharSJIS ); 72 mCharStrm = stream; 73 } 74 75 // 76 // 77 // 78 // Set(const wchar_t * stream)79 void Set(const wchar_t* stream) 80 { 81 NN_ALIGN_ASSERT(stream, 2); 82 NN_POINTER_ASSERT(stream); 83 NN_ASSERT(mReadFunc == &CharStrmReader::ReadNextCharUTF16); 84 mCharStrm = stream; 85 } 86 87 // 88 // 89 // 90 // GetCurrentPos()91 const void* GetCurrentPos() const { return mCharStrm; } 92 93 // 94 // 95 // 96 // 97 // Next()98 u16 Next() { return (this->*mReadFunc)(); } 99 100 // 101 102 private: 103 /* ------------------------------------------------------------------------ 104 Types 105 ------------------------------------------------------------------------ */ 106 typedef u16 (CharStrmReader::*ReadNextCharFunc)(); 107 108 109 /* ------------------------------------------------------------------------ 110 Variables 111 ------------------------------------------------------------------------ */ 112 const void* mCharStrm; // Pointer to the current stream position 113 const ReadNextCharFunc mReadFunc; // Pointer to the stream interpretation function 114 115 116 /* ------------------------------------------------------------------------ 117 Functions 118 ------------------------------------------------------------------------ */ 119 //---- Constructor CharStrmReader(ReadNextCharFunc func)120 explicit CharStrmReader(ReadNextCharFunc func) 121 : mCharStrm(NULL), 122 mReadFunc(func) 123 { 124 } 125 126 //---- Stream operations 127 template <typename CharType> 128 CharType GetChar(int offset=0) const 129 { 130 const CharType* charStrm = reinterpret_cast<const CharType*>(mCharStrm); 131 return *(charStrm + offset); 132 } 133 134 template <typename CharType> 135 void StepStrm(int step=1) 136 { 137 const CharType*& charStrm = reinterpret_cast<const CharType*&>(mCharStrm); 138 charStrm += step; 139 } 140 141 // 142 // 143 // 144 // 145 // 146 u16 ReadNextCharUTF8(); 147 148 // 149 // 150 // 151 // 152 // 153 u16 ReadNextCharUTF16(); 154 155 // 156 // 157 // 158 // 159 // 160 u16 ReadNextCharCP1252(); 161 162 // 163 // 164 // 165 // 166 // 167 u16 ReadNextCharSJIS(); 168 }; 169 170 171 172 } // namespace font 173 } // namespace nn 174 175 #endif // NN_FONT_FONT_CHAR_STRM_READER_H_ 176