#pragma once //#include //Sequence 에서 Event 발생 후, 발생된 Event는 다시 사용 안 한도록 수정된것.. template class KEventKeyRes { public: KEventKeyRes() { m_keyCount = 0; m_keys = NULL; } virtual ~KEventKeyRes() { if ( m_keys ) delete[] m_keys; } /// 최소~최대 이벤트 거리 const KInterval &GetInterval() { return m_interval; } void SetKeyCount( int count, int nLength = 0 ) { m_keyCount = count; m_keys = new T[count]; m_nLength = nLength; } /// 전체 길이 int GetLength() { return m_nLength; } int GetKeyCount() { return m_keyCount; } /// 초기화 void SetInit() { for ( int i=0 ; i=0 && iIndex < m_keyCount); return m_keys[iIndex]; } void Rearrange() { sortKeys( m_keyCount ); m_interval.Set( m_keys[0].time, m_keys[m_keyCount-1].time ); } void SetWholeKey( T *key, int count ) { SetKeyCount( count ); SetKey( 0, key, count ); } int GetIndexNumber(int time) { T pred; pred.time = time; T *found = std::lower_bound( m_keys, (m_keys + m_keyCount), pred ); return static_cast(found - m_keys); } void GetData( DWORD time, T*& key1, T*& key2 ) { T pred; pred.time = time; T * found; if(!UseUpperBound) { found = std::lower_bound( m_keys, (m_keys + m_keyCount), pred ); if ( found == m_keys ) // found first key means time less than first time { //시간이 크거나, 같아야 하며, 사용하지 않은것 이면, if( found->time <= time && found->bUse == false ) key1 = found; else key1 = NULL; key2 = NULL; return; } else if ( found == (m_keys+m_keyCount) ) // found end mark return last key { if( m_keys[m_keyCount-1].time <= time && m_keys[m_keyCount-1].bUse == false ) key1 = &m_keys[m_keyCount-1]; else key1 = NULL; key2 = NULL; return; } else if ( found->time == time ) { if( found->time <= time && found->bUse == false ) key1 = found; else key1 = NULL; key2 = NULL; return; } if( (found-1)->time <= time && (found-1)->bUse == false ) key1 = (found-1); else key1 = NULL; if( found->time <= time && found->bUse == false ) key2 = found; else key2 = NULL; return; } else { found = std::upper_bound( m_keys, (m_keys + m_keyCount), pred ); if ( found == (m_keys+m_keyCount - 1) ) // found first key is last key. { if( found->time <= time && found->bUse == false ) key1 = found; else key1 = NULL; if( m_keys[0].time <= time && m_keys[0].bUse == false ) key2 = m_keys; else key2 = NULL; return; } else if ( found == (m_keys+m_keyCount) ) // found end mark return last key { if( m_keys[m_keyCount-1].time <= time && m_keys[m_keyCount-1].bUse == false ) key1 = &m_keys[m_keyCount-1]; else key1 = NULL; key2 = NULL; return; } else if ( found->time == time ) { if( found->time <= time && found->bUse == false ) key1 = found; else key1 = NULL; key2 = NULL; return; } if( found->time <= time && found->bUse == false ) key1 = found; else key1 = NULL; if( (found + 1)->time <= time && (found + 1)->bUse == false ) key2 = found + 1; else key2 = NULL; return; } } void SetName( const std::string & name ) { m_strName = name; } const std::string & GetName() { return m_strName; } protected: void sortKeys( int count ) { std::sort( m_keys, m_keys+count ); } KInterval m_interval; int m_nLength; int m_keyCount; T* m_keys; std::string m_strName; };