bool FSMDirector_TransferInputs(struct FSMDirector* director, struct IOPort* port) { if (!port->isInput(port) /*|| !port->isOpaque(port)*/) { fprintf(stderr, "Attempted to transferInputs on a port is not an opaque input port."); exit(-1); } bool wasTransferred = false; PblMap* tokensIn = pblMapNewHashMap(); for (int i = 0; i < port->getWidth(port); i++) { if (i < port->getWidthInside(port)) { if (port->hasToken(port, i)) { Token* t = port->get(port, i); port->sendInside(port, i, t); pblMapAdd(tokensIn, &port, sizeof(struct IOPort*), t, sizeof(Token)); wasTransferred = true; } } else { if (port->hasToken(port, i)) { port->get(port, i); } } } if (wasTransferred) { director->transferModalInputs(tokensIn); } pblMapFree(tokensIn); return wasTransferred; }
/** * Associates the specified string value with the specified string key in this map. * * If the map previously contained a mapping for the key, the old value is replaced by the specified value. * (A map m is said to contain a mapping for a key k if and only if pblMapContainsKey(k) would return true.) * * For hash maps this method has a time complexity of O(1). * For tree maps this method has a time complexity of O(Log N). * * @return int rc > 0: The map did not already contain a mapping for the key. * @return int rc == 0: The map did already contain a mapping for the key. * @return int rc < 0: An error, see pbl_errno: * * <BR>PBL_ERROR_OUT_OF_MEMORY - Out of memory. * <BR>PBL_ERROR_OUT_OF_BOUNDS - Maximum capacity of the hash set exceeded. */ int pblMapAddStrStr( /* */ PblMap * map, /** The map to add to */ char * key, /** Key to add a mapping for */ char * value /** Value of the new mapping */ ) { return pblMapAdd( map, key, key ? 1 + strlen( key ) : 0, value, value ? 1 + strlen( value ) : 0 ); }
bool FSMDirector_DirectorTransferModalOutputs1(struct FSMDirector* director, struct IOPort* port) { bool result = false; if (!port->isOutput(port) /*|| !port->isOpaque(port)*/) { fprintf(stderr, "Attempted to transferOutputs on a port that is not an opaque input port."); exit(-1); } PblMap* tokensOut = pblMapNewHashMap(); for (int i = 0; i < port->getWidthInside(port); i++) { if (port->hasTokenInside(port, i)) { Token* t = port->getInside(port, i); port->sendLocalInside(port, i, t); pblMapAdd(tokensOut, &port, sizeof(struct IOPort*), t, sizeof(Token)); result = true; } } if (result) { director->transferModalOutputs(tokensOut); } pblMapFree(tokensOut); return result; }
/** * Copies all of the mappings from the specified source map to this map. * These mappings will replace any mappings that this map had for any * of the keys currently in the specified map. * * For hash maps this method has a time complexity of O(M). * For tree maps this method has a time complexity of O(M * Log N). * With M being the number of elements in the source map and * N being the number of elements in the target map. * * @return int rc == 0: Ok. * @return int rc < 0: An error, see pbl_errno: * * <BR>PBL_ERROR_CONCURRENT_MODIFICATION - The source map was modified concurrently. * <BR>PBL_ERROR_OUT_OF_MEMORY - Out of memory. */ int pblMapPutAll( /* */ PblMap * map, /** The map to copy the entries to */ PblMap * sourceMap /** The map to copy the entries from */ ) { int hasNext; void * element; PblMapEntry * entry; PblIterator iterator; pblIteratorInit( sourceMap->entrySet, &iterator ); while( ( hasNext = pblIteratorHasNext( &iterator ) ) > 0 ) { element = pblIteratorNext( &iterator ); if( element == (void*)-1 ) { // Concurrent modification // return -1; } entry = (PblMapEntry *)element; if( !entry ) { continue; } if( pblMapAdd( map, entry->buffer, entry->keyLength, entry->buffer + entry->keyLength, entry->valueLength ) < 0 ) { return -1; } } return 0; }