void ribi::taba::GameWidget::ReleaseKey(const Key key)
{
  m_keys.erase(std::remove(m_keys.begin(),m_keys.end(),key),m_keys.end());
  if (m_keys.empty()) return;
  const auto iter = std::find(m_keys.begin(),m_keys.end(),Keys().GetOpposite(key));
  if (iter != m_keys.end())
  {
    std::swap(*m_keys.begin(),*iter);
    assert(m_keys[0] == Keys().GetOpposite(key));
  }
  m_direction = Helper().KeyToDirection(m_keys[0]);
}
void ribi::taba::GameWidget::PressKey(const Key key)
{
  m_keys.push_back(key);
  switch (m_keys.size())
  {
    case 1: break;
    case 2: std::swap(m_keys[0],m_keys[1]); break;
    case 3:
    {
      const int n_keys = static_cast<int>(m_keys.size());
      for (int i=0; i!=n_keys - 1; ++i)
      {
        if (Keys().IsOpposite(m_keys[i],m_keys[n_keys - 1]))
        {
          std::swap(m_keys[i],m_keys[n_keys - 1]);
          break;
        }
      }
    }
    break;
    default: break;
    case 0: assert(!"Should not get here");
  }
  assert(!m_keys.empty());
  m_direction = Helper().KeyToDirection(m_keys[0]);
}
Ejemplo n.º 3
0
McRequest::McRequest(const McRequest& other)
    : exptime_(other.exptime_),
      flags_(other.flags_),
      delta_(other.delta_),
      leaseToken_(other.leaseToken_),
      cas_(other.cas_) {
  // Key is always a single piece, so it's safe to do cloneOneInto.
  other.keyData_.cloneOneInto(keyData_);
  keys_ = Keys(getRange(keyData_));
  other.valueData_.cloneInto(valueData_);

  if (hasSameMemoryRegion(keyData_, other.keyData_) &&
      hasSameMemoryRegion(valueData_, other.valueData_)) {

    msg_ = other.msg_.clone();
  } else {
    msg_ = createMcMsgRef(
      other.msg_, getRange(keyData_),
      coalesceAndGetRange(valueData_));
  }

#ifndef LIBMC_FBTRACE_DISABLE
  if (other.fbtraceInfo_.get()) {
    fbtraceInfo_ = McFbtraceRef::moveRef(
      mc_fbtrace_info_deep_copy(other.fbtraceInfo_.get()));
  }
#endif
}
Ejemplo n.º 4
0
bool McRequest::setKeyFrom(const folly::IOBuf& source,
                               const uint8_t* keyBegin, size_t keySize) {
  if (keySize && cloneInto(keyData_, source, keyBegin, keySize)) {
    keys_ = Keys(getRange(keyData_));
    return true;
  }
  return false;
}
Ejemplo n.º 5
0
 static void mapping(IO &Io, clang::tooling::AtomicChange &Doc) {
   MappingNormalization<NormalizedAtomicChange, clang::tooling::AtomicChange>
       Keys(Io, Doc);
   Io.mapRequired("Key", Keys->Key);
   Io.mapRequired("FilePath", Keys->FilePath);
   Io.mapRequired("Error", Keys->Error);
   Io.mapRequired("InsertedHeaders", Keys->InsertedHeaders);
   Io.mapRequired("RemovedHeaders", Keys->RemovedHeaders);
   Io.mapRequired("Replacements", Keys->Replaces);
 }
Ejemplo n.º 6
0
void MappingTraits<ELFYAML::Symbol>::mapping(IO &IO, ELFYAML::Symbol &Symbol) {
  IO.mapOptional("Name", Symbol.Name, StringRef());
  IO.mapOptional("Type", Symbol.Type, ELFYAML::ELF_STT(0));
  IO.mapOptional("Section", Symbol.Section, StringRef());
  IO.mapOptional("Index", Symbol.Index);
  IO.mapOptional("Value", Symbol.Value, Hex64(0));
  IO.mapOptional("Size", Symbol.Size, Hex64(0));

  MappingNormalization<NormalizedOther, uint8_t> Keys(IO, Symbol.Other);
  IO.mapOptional("Visibility", Keys->Visibility, ELFYAML::ELF_STV(0));
  IO.mapOptional("Other", Keys->Other, ELFYAML::ELF_STO(0));
}
Ejemplo n.º 7
0
static int this_cell_is_truthy(thing_th *cell) {
    switch(th_kind(cell)) {
        case grid_k:
            return Keys(cell)!=NULL;
        case error_k: case null_k:
            return 0;
        case cons_k: case macro_k: 
        case gen_k: case procedure_k:
            return Car(cell)!=NULL || Cdr(cell)!=NULL;
        case atom_k:
            return !streq(sym(cell), "nil");
        case number_k: case string_k:
            return 1;
        case routine_k: case method_k:
            return call_rt(cell)!=NULL;
    }
}
Ejemplo n.º 8
0
void TrackInfoObject::setKey(mixxx::track::io::key::ChromaticKey key,
                             mixxx::track::io::key::Source source) {
    QMutexLocker lock(&m_qMutex);
    bool dirty = false;
    if (key == mixxx::track::io::key::INVALID) {
        m_keys = Keys();
        dirty = true;
    } else if (m_keys.getGlobalKey() != key) {
        m_keys = KeyFactory::makeBasicKeys(key, source);
    }

    if (dirty) {
        setDirty(true);
    }

    // Might be INVALID. We don't care.
    mixxx::track::io::key::ChromaticKey newKey = m_keys.getGlobalKey();
    lock.unlock();
    emit(keyUpdated(KeyUtils::keyToNumericValue(newKey)));
    emit(keysUpdated());
}
Ejemplo n.º 9
0
thing_th *Car(const thing_th *thing) {
    switch(th_kind(thing)) {
        case atom_k:
        case number_k:
        case method_k:
        case routine_k:
            return NULL;
        case string_k:
            return str_first_char((string_th *)thing);
        case error_k:
        case cons_k:
        case procedure_k:
        case macro_k:
        case gen_k:
            return cons_first_thing((cons_th *)thing);
        case grid_k:
            return Keys(thing);
        case null_k:
            return NULL;
    }
    return NULL;
}
Ejemplo n.º 10
0
 static void mapping(IO &IO, tooling::Range &Info) {
   MappingNormalization<NormalizedRange, tooling::Range> Keys(IO, Info);
   IO.mapRequired("Offset", Keys->Offset);
   IO.mapRequired("Length", Keys->Length);
 }
Ejemplo n.º 11
0
Archivo: GMenu.cpp Proyecto: FEI17N/Lgi
bool GMenuItem::ScanForAccel()
{
	char *Sc = ShortCut;
	if (!Sc)
	{
		char *n = GBase::Name();
		if (n)
		{
			char *tab = strrchr(n, '\t');
			if (tab)
			{
				Sc = tab + 1;
			}
		}
	}
	if (!Sc || !Info)
		return false;
	
	GToken Keys(Sc, "-+ \r\n");
	for (int i=0; i<Keys.Length(); i++)
	{
		char *k = Keys[i];
		if (stricmp(k, "Ctrl") == 0)
		{
			ShortcutMod |= B_COMMAND_KEY;
		}
		else if (stricmp(k, "Alt") == 0)
		{
			ShortcutMod |= B_CONTROL_KEY;
		}
		else if (stricmp(k, "Shift") == 0)
		{
			ShortcutMod |= B_SHIFT_KEY;
		}
		else if (stricmp(k, "Del") == 0 ||
				 stricmp(k, "Delete") == 0)
		{
			ShortcutKey = VK_DELETE;
		}
		else if (stricmp(k, "Ins") == 0 ||
				 stricmp(k, "Insert") == 0)
		{
			ShortcutKey = VK_INSERT;
		}
		else if (stricmp(k, "Home") == 0)
		{
			ShortcutKey = VK_HOME;
		}
		else if (stricmp(k, "End") == 0)
		{
			ShortcutKey = VK_END;
		}
		else if (stricmp(k, "PageUp") == 0)
		{
			ShortcutKey = VK_PAGEUP;
		}
		else if (stricmp(k, "PageDown") == 0)
		{
			ShortcutKey = VK_PAGEDOWN;
		}
		else if (stricmp(k, "Backspace") == 0)
		{
			ShortcutKey = VK_BACKSPACE;
		}
		else if (stricmp(k, "Space") == 0)
		{
			ShortcutKey = ' ';
		}
		else if (k[0] == 'F' && isdigit(k[1]))
		{
			ShortcutKey = VK_F1 + atoi(k+1) - 1;
		}
		else if (isalpha(k[0]))
		{
			ShortcutKey = toupper(k[0]);
		}
		else if (isdigit(k[0]))
		{
			ShortcutKey = k[0];
		}
	}
	
	if ((isalpha(ShortcutKey) || isdigit(ShortcutKey)) &&
		(ShortcutMod & B_COMMAND_KEY) != 0)
	{
		Info->SetShortcut(ShortcutKey, ShortcutMod);
	}
	else
	{
		UnsupportedShortcut = true;
	}
	return true;
}
void ribi::taba::GameWidget::Test() noexcept
{
  {
    static bool is_tested = false;
    if (is_tested) return;
    is_tested = true;
  }
  {
    Keys();
  }
  const TestTimer test_timer(__func__,__FILE__,1.0);
  const bool verbose{false};

  //Key presses: single key, does the player change direction?
  {
    GameWidget w;
    for (const auto key: Keys().GetAll())
    {
      if (!Keys().IsMovement(key)) continue;
      w.PressKey(key);
      assert(w.GetDirection() == Helper().KeyToDirection(key)
        && "A single key changes the direction of the player");
      w.ReleaseKey(key);
      assert(w.GetDirection() == Helper().KeyToDirection(key)
        && "Releasing the only single key, maintains the direction of the player");
    }
  }
  //Key presses: two keys: does the player keep both if perpendicular
  {
    GameWidget w;
    for (const auto key_a: Keys().GetAll())
    {
      if (!Keys().IsMovement(key_a)) continue;
      for (const auto key_b: Keys().GetAll())
      {
        if (!Keys().IsMovement(key_b)) continue;
        w.PressKey(key_a);
        w.PressKey(key_b);
        if (verbose)
        {
          TRACE(Keys().ToStr(key_a));
          TRACE(Keys().ToStr(key_b));
        }
        if (Keys().IsOpposite(key_a,key_b))
        {
          assert(w.GetDirection() == Helper().KeyToDirection(key_b)
            && "If an opposite key is pressed, change direction to it");
          w.ReleaseKey(key_b);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "If that opposite key is released, reverse the player's direction");
          w.ReleaseKey(key_a);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "Maintain that player's direction");
        }
        else
        {
          assert(w.GetDirection() == Helper().KeyToDirection(key_b)
            && "If a second perpendicular key is pressed, change direction to it");
          w.ReleaseKey(key_b);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "If the primary key is released, make the other key the new primary one");
          w.ReleaseKey(key_a);
          assert(w.GetDirection() == Helper().KeyToDirection(key_a)
            && "Maintain that player's direction");
        }
      }
    }
  }
  TRACE("Finished ribi::taba::GameWidget::Test successfully");
}
Ejemplo n.º 13
0
std::vector<ablib::string> Setting::INIKeys(const ablib::string &sec){
	return Keys(m_ini,sec);
}