void tryCopy() { // NextNum nn(10,3); std::vector<int> iTab(10); std::generate(iTab.begin(), iTab.end(), NextNum(10,5)); parcourir<std::vector<int>::iterator>(iTab.begin(), iTab.end()); std::copy(iTab.begin(), iTab.end(), std::ostream_iterator<int>(std::cout, ", ")); }
bool IOHIKeyboardMapper::parseKeyMapping(const UInt8 * map, UInt32 mappingLen, NXParsedKeyMapping * parsedMapping) const { NewMappingData nmd; int i, j, k, l, n; unsigned int m; int keyMask, numMods; int maxSeqNum = -1; unsigned char * bp; /* Initialize the new map. */ bzero( parsedMapping, sizeof (NXParsedKeyMapping) ); parsedMapping->maxMod = -1; parsedMapping->numDefs = -1; parsedMapping->numSeqs = -1; if (!map || !mappingLen) return false; nmd.endPtr = map + mappingLen; nmd.bp = map; nmd.shorts = 1; // First value, the size, is always a short /* Start filling it in with the new data */ parsedMapping->mapping = (unsigned char *)map; parsedMapping->mappingLen = mappingLen; parsedMapping->shorts = nmd.shorts = NextNum(&nmd); /* Walk through the modifier definitions */ numMods = NextNum(&nmd); for(i=0; i<numMods; i++) { /* Get bit number */ if ((j = NextNum(&nmd)) >= NX_NUMMODIFIERS) return false; /* Check maxMod */ if (j > parsedMapping->maxMod) parsedMapping->maxMod = j; /* record position of this def */ parsedMapping->modDefs[j] = (unsigned char *)nmd.bp; /* Loop through each key assigned to this bit */ for(k=0,n = NextNum(&nmd);k<n;k++) { /* Check that key code is valid */ if ((l = NextNum(&nmd)) >= NX_NUMKEYCODES) return false; /* Make sure the key's not already assigned */ if (parsedMapping->keyBits[l] & NX_MODMASK) return false; /* Set bit for modifier and which one */ //The "if" here is to patch the keymapping file. That file has nothing // for num lock, so no change is required here for num lock. // Also, laptop Macs have num lock handled by Buttons driver if ((j != NX_MODIFIERKEY_ALPHALOCK) || (_delegate->doesKeyLock(NX_KEYTYPE_CAPS_LOCK)) ) { parsedMapping->keyBits[l] |=NX_MODMASK | (j & NX_WHICHMODMASK); } } } //This is here because keymapping file has an entry for caps lock, but in // order to trigger special code (line 646-), the entry needs to be zero if (!_delegate->doesKeyLock(NX_KEYTYPE_CAPS_LOCK)) parsedMapping->modDefs[NX_MODIFIERKEY_ALPHALOCK] = 0; //This section is here to force keymapping to include the PowerBook's secondary // fn key as a new modifier key. This code can be removed once the keymapping // file has the fn key (ADB=0x3f) in the modifiers section. // NX_MODIFIERKEY_SECONDARYFN = 8 in ev_keymap.h if (_delegate->interfaceID() == NX_EVS_DEVICE_INTERFACE_ADB) { parsedMapping->keyBits[0x3f] |=NX_MODMASK | (NX_MODIFIERKEY_SECONDARYFN & NX_WHICHMODMASK); } /* Walk through each key definition */ parsedMapping->numDefs = NextNum(&nmd); n = parsedMapping->numDefs; for( i=0; i < NX_NUMKEYCODES; i++) { if (i < n) { parsedMapping->keyDefs[i] = (unsigned char *)nmd.bp; if ((keyMask = NextNum(&nmd)) != (nmd.shorts ? 0xFFFF: 0x00FF)) { /* Set char gen bit for this guy: not a no-op */ parsedMapping->keyBits[i] |= NX_CHARGENMASK; /* Check key defs to find max sequence number */ for(j=0, k=1; j<=parsedMapping->maxMod; j++, keyMask>>=1) { if (keyMask & 0x01) k*= 2; } for(j=0; j<k; j++) { m = NextNum(&nmd); l = NextNum(&nmd); if (m == (unsigned)(nmd.shorts ? 0xFFFF: 0x00FF)) if (((int)l) > maxSeqNum) maxSeqNum = l; /* Update expected # of seqs */ } } else /* unused code within active range */