コード例 #1
0
ファイル: boggle.cpp プロジェクト: rselbo/boggle
/// Adds a single letter of a word to the internal dictionary
void Boggle::AddLetter(const std::string& word, unsigned int pos, DictEntry* dictionary)
{
#if defined(OPTIMIZED)
  DictEntry *entry = dictionary->Get(word[pos]);
  if (entry == nullptr)
  {
    entry = m_Pool.Allocate();
    entry->m_Character = word[pos];
    dictionary->Insert(entry);
  }
#else
  DictEntry *&entry = dictionary->m_NextLetter[word[pos] - 'a'];
  //Make sure we have an entry for this character
  if (entry == nullptr)
  {
    //Allocate and initialize the entry
    entry = m_Pool.Allocate();
    entry->m_Character = word[pos];
  }
#endif

  if (pos == word.length() - 1)
  {
    //if the word ends at this DictEntry mark the word as terminated at this entry
    entry->m_Terminated = true;
    return;
  }

  //recurse to add the next letter of the word
  AddLetter(word, ++pos, entry);
}
コード例 #2
0
ファイル: UICustomEdit.cpp プロジェクト: OLR-xray/OLR-3.0
bool CUICustomEdit::KeyPressed(int dik)
{
	xr_map<u32, char>::iterator it;
	char out_me = 0;
	bool bChanged = false;
	switch(dik)
	{
	case DIK_LEFT:
	case DIKEYBOARD_LEFT:
		m_lines.DecCursorPos();		
		break;
	case DIK_RIGHT:
	case DIKEYBOARD_RIGHT:
		m_lines.IncCursorPos();		
		break;
	case DIK_LSHIFT:
	case DIK_RSHIFT:
		m_bShift = true;
		break;
	case DIK_ESCAPE:
		if (xr_strlen(GetText()) != 0)
		{
			SetText("");
			bChanged = true;
		}
		else
		{
			GetParent()->SetKeyboardCapture(this, false);
			m_bInputFocus = false;
			m_iKeyPressAndHold = 0;
		};
		break;
	case DIK_RETURN:
	case DIK_NUMPADENTER:
		GetParent()->SetKeyboardCapture(this, false);
		m_bInputFocus = false;
		m_iKeyPressAndHold = 0;
		GetMessageTarget()->SendMessage(this,EDIT_TEXT_COMMIT,NULL);
		break;
	case DIK_BACKSPACE:
		m_lines.DelLeftChar();
		bChanged = true;
		break;
	case DIK_DELETE:
	case DIKEYBOARD_DELETE:
		m_lines.DelChar();
		bChanged = true;
		break;
	case DIK_SPACE:
		out_me = ' ';					break;
	case DIK_LBRACKET:
		out_me = m_bShift ? '{' : '[';	break;
	case DIK_RBRACKET:
		out_me = m_bShift ? '}' : ']';	break;
	case DIK_SEMICOLON:
		out_me = m_bShift ? ':' : ';';	break;
	case DIK_APOSTROPHE:
		out_me = m_bShift ? '"' : '\'';	break;
	case DIK_BACKSLASH:
		out_me = m_bShift ? '|' : '\\';	break;
	case DIK_SLASH:
		out_me = m_bShift ? '?' : '/';	break;
	case DIK_COMMA:
		out_me = m_bShift ? '<' : ',';	break;
	case DIK_PERIOD:
		out_me = m_bShift ? '>' : '.';	break;
	case DIK_MINUS:
		out_me = m_bShift ? '_' : '-';	break;
	case DIK_EQUALS:
		out_me = m_bShift ? '+' : '=';	break;
	default:
		it = gs_DIK2CHR.find(dik);

		//нажата клавиша с буквой 
		if (gs_DIK2CHR.end() != it){
			AddLetter((*it).second);
			bChanged = true;
		}

		break;
	}

	if (m_bNumbersOnly)
	{
		if (strstr(m_lines.GetText(), "."))
			return true;
		if (('.' == out_me) && m_bFloatNumbers){
			AddChar(out_me);
			bChanged = true;
		}
	}
	else
		if(out_me){
			AddChar(out_me);
			bChanged = true;
		}

		if(bChanged)
			GetMessageTarget()->SendMessage(this,EDIT_TEXT_CHANGED,NULL);

		return true;
}
コード例 #3
0
ファイル: boggle.cpp プロジェクト: rselbo/boggle
/// Adds a single word to the internal dictionary
void Boggle::AddWord(const std::string& line)
{
  AddLetter(line, 0, m_Base);
  ++m_DictWords;
}