/*----------------------------------------------------------------------------- * CStream *----------------------------------------------------------------------------- * ½ºÆ®¸² Ŭ·¡½º *----------------------------------------------------------------------------- * Copyright (c) , 2006, WEBZEN Inc. * All rights reserved. * * Author : Noh Yong Hwan, 2006, WEBZEN Inc. Research & Development Dept. * fixbrain@gmail.com , somma@webzen.co.kr **---------------------------------------------------------------------------*/ #ifndef _INCLUDE_C_STREAM_H_ #define _INCLUDE_C_STREAM_H_ #include // // ÃÖ»óÀ§ ½ºÆ®¸² ÀÎÅÍÆäÀ̽º // class CStream { private: protected: unsigned long m_size; unsigned long m_pos; // ChangeCursor() method ¸¸ÀÌ setPos() ¸¦ È£ÃâÇÏ¸ç ¸ðµç À¯È¿¼º °Ë»ç´Â // ChangeCursor() method ³»¿¡¼­ ¼öÇàÇÑ´Ù. // unsigned long setPos(const unsigned long newPosition) { m_pos = newPosition; return m_pos; }; virtual int SetSize(unsigned long newSize) = 0; public: CStream() : m_pos(0), m_size(0) { }; virtual ~CStream(){}; int GetSize() { return m_size; }; int GetCurrentCusor() { return m_pos; }; int ChangeCursor(const unsigned long offset, unsigned long from); // ½ºÆ®¸²ÀÌ »ç¿ëÇÑ ÀÚ¿øÀ» ¼Ò¸êÇÑ´Ù. // (ÆÄÀÏÀ̵ç, ¸Þ¸ð¸®µç...) // virtual void ClearStream(void) = 0; // ½ºÆ®¸²À¸·Î ºÎÅÍ µ¥ÀÌÅ͸¦ Àо ¹öÆÛ¿¡ ¾´´Ù. // virtual int ReadFromStream(void *Buffer, int Count) = 0; // ¹öÆÛ·ÎºÎÅÍ µ¥ÀÌÅ͸¦ ÀÐ¾î ½ºÆ®¸²ÀÇ ÇöÀç Æ÷Áö¼Ç¿¡ ¾´´Ù. // virtual int WriteToStream(const void *Buffer, int Count) = 0; }; // // ¸Þ¸ð¸® ½ºÆ®¸² Ŭ·¡½º // // WARNING ! // ÀÌ Å¬·¡½º¿¡¼­ ´Ù¸¥ Ŭ·¡½º¸¦ ÆÄ»ýÇÏÁö ¸»°Í. // º¹»ç/´ëÀÔ/¼Ò¸êÀÚ µîµî.. ÀüÇô ÆÄ»ý °´Ã¼¸¦ °í·ÁÇÏÁö ¾Ê¾ÒÀ½. ÄíÄíÄí :-) // class CMemoryStream : public CStream { private: char *m_pMemory; virtual int SetSize(unsigned long newSize); protected: public: CMemoryStream() : m_pMemory(NULL) {}; ~CMemoryStream() { if (NULL != m_pMemory) { // free and change cursor // if (0 != SetSize(0)) { _ASSERTE(!"SetSize() error"); } } }; // ½ºÆ®¸²ÀÌ »ç¿ëÇÑ ÀÚ¿øÀ» ¼Ò¸êÇÑ´Ù. // (ÆÄÀÏÀ̵ç, ¸Þ¸ð¸®µç...) // -- inline method ÀÓ - cpp ÂÊÀ¸·Î ³Ñ±âÁö ¸»°Í // virtual void ClearStream(void) { // free and change cursor // if (0 != SetSize(0)) { _ASSERTE(!"SetSize() error"); } } // ByteToRead ¸¸Å­ ÀÐÀ» ¼ö ÀÖ´ÂÁö °Ë»ç // // -- inline method ÀÓ - cpp ÂÊÀ¸·Î ³Ñ±âÁö ¸»°Í // bool CanReadFromStream(int ByteToRead) { if (m_pos + ByteToRead > m_size) return false; else return true; } // ½ºÆ®¸²À¸·Î ºÎÅÍ µ¥ÀÌÅ͸¦ Àо ¹öÆÛ¿¡ ¾´´Ù. // virtual int ReadFromStream(void *Buffer, int Count); // ¹öÆÛ·ÎºÎÅÍ µ¥ÀÌÅ͸¦ ÀÐ¾î ½ºÆ®¸²ÀÇ ÇöÀç Æ÷Áö¼Ç¿¡ ¾´´Ù. // virtual int WriteToStream(const void *Buffer, int Count); // ¸Þ¸ð¸® ¸â¹ö¿¡ Á÷Á¢ ¿¢¼¼½º Çϱâ À§ÇÑ ¸Þ¼Òµå // const void *GetMemory() { return m_pMemory; }; }; #endif