#include "StdAfx.h" #include ".\keygenerator.h" KeyGenerator::KeyGenerator(void) { m_dwStartKey = 0; m_dwEndKey = 0; } KeyGenerator::~KeyGenerator(void) { } //dwStartKey must over than 0 VOID KeyGenerator::Init( DWORD dwStartKey, DWORD dwEndKey ) { // ÇØ´ç Ű °ª¿¡ 0ÀÌ¸é »ç¿ë¾ÈÇÔ, 1ÀÌ¸é »ç¿ëÁß. for( DWORD i = dwStartKey; i < dwEndKey; i++ ) m_mapKeyPool.insert( std::make_pair( i, FALSE ) ); m_dwStartKey = dwStartKey; m_dwEndKey = dwEndKey; } //À¯ÀÏÇÑ Å°¸¦ ÇÒ´ç ¹Þ´Â´Ù. BOOL KeyGenerator::AllocKey( DWORD& dwKey ) { if( m_mapKeyPool.empty() ) return FALSE; MAPKEY_ITER iter = m_mapKeyPool.begin(); dwKey = (*iter).first; m_mapKeyPool.erase( iter ); return TRUE; } //ÇØ´ç۸¦ ÇÒ´ç ÇÑ´Ù. Ç®¿¡¼­ ²¨³½´Ù. BOOL KeyGenerator::RestoreKey( DWORD dwKey ) { if( dwKey < m_dwStartKey || dwKey > m_dwEndKey ) return FALSE; // ÇöÀç ÀÌ Å°°ªÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö È®ÀÎÇØ ºÁ¾ß ÇÑ´Ù. MAPKEY_ITER iter = m_mapKeyPool.find( dwKey ); //۰¡ Ç®¿¡ ÀÖ´ÂÁö °Ë»ç. Ç®¿¡ ÀÖÀ¸¸é, if( iter != m_mapKeyPool.end() ) m_mapKeyPool.erase( iter ); else return FALSE; return TRUE; } //ÇØ´ç۸¦ ¹Ý³³ÇÏ´Ù. BOOL KeyGenerator::FreeKey( DWORD dwKey ) { if( dwKey < m_dwStartKey || dwKey > m_dwEndKey ) return FALSE; // ÇöÀç ÀÌ Å°°ªÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö È®ÀÎÇØ ºÁ¾ß ÇÑ´Ù. MAPKEY_ITER iter = m_mapKeyPool.find( dwKey ); //۰¡ Ç®¿¡ ÀÖ´ÂÁö °Ë»ç. if( iter == m_mapKeyPool.end() ) // Ç®¿¡ ¾øÀ¸¸é m_mapKeyPool.insert( std::make_pair( dwKey, 0) ); else // Ç®¿¡ ÀÖÀ¸¸é... ÀÌ¹Ì ¹Ý³³µÇ¾î ÀÖÀ¸¹Ç·Î.. return FALSE; return TRUE; } //Ç®¿¡ ÁÖ¾îÁø ۰¡ ÀÖ´ÂÁö ã´Â´Ù. BOOL KeyGenerator::FindKey( DWORD dwKey ) { if( dwKey < m_dwStartKey || dwKey > m_dwEndKey ) return FALSE; // ÇöÀç ÀÌ Å°°ªÀÌ ÀÖ´ÂÁö ¾ø´ÂÁö È®ÀÎÇØ ºÁ¾ß ÇÑ´Ù. MAPKEY_ITER iter = m_mapKeyPool.find( dwKey ); //۰¡ Ç®¿¡ ÀÖ´ÂÁö °Ë»ç. if( iter != m_mapKeyPool.end() ) // Ç®¿¡ ÀÖÀ¸¸é, return TRUE; else // Ç®¿¡ ¾øÀ¸¸é.. return FALSE; }